From c99d115fb9f831420c94d6cce23bf2418a5dd04a Mon Sep 17 00:00:00 2001 From: RipplB Date: Thu, 23 Jan 2025 16:40:05 +0100 Subject: [PATCH] Bump copyright year --- build.gradle.kts | 2 +- buildSrc/build.gradle.kts | 2 +- buildSrc/gradle.properties | 2 +- buildSrc/settings.gradle.kts | 2 +- buildSrc/src/main/kotlin/Deps.kt | 2 +- .../src/main/kotlin/antlr-grammar.gradle.kts | 2 +- buildSrc/src/main/kotlin/cli-tool.gradle.kts | 2 +- .../src/main/kotlin/jacoco-common.gradle.kts | 2 +- .../src/main/kotlin/java-common.gradle.kts | 2 +- .../main/kotlin/kaml-serialization.gradle.kts | 4 +- .../src/main/kotlin/kotlin-common.gradle.kts | 2 +- .../src/main/kotlin/maven-artifact.gradle.kts | 2 +- .../src/main/kotlin/tool-common.gradle.kts | 2 +- .../shared-with-buildSrc/mirrors.gradle.kts | 2 +- scripts/complex.kts | 2 +- scripts/simple.kts | 2 +- settings.gradle.kts | 2 +- subprojects/cfa/cfa-analysis/build.gradle.kts | 2 +- .../bme/mit/theta/cfa/analysis/CfaAction.java | 14 +- .../mit/theta/cfa/analysis/CfaAnalysis.java | 13 +- .../mit/theta/cfa/analysis/CfaInitFunc.java | 16 +- .../mit/theta/cfa/analysis/CfaInitPrecs.java | 9 +- .../hu/bme/mit/theta/cfa/analysis/CfaOrd.java | 7 +- .../bme/mit/theta/cfa/analysis/CfaPrec.java | 2 +- .../bme/mit/theta/cfa/analysis/CfaState.java | 14 +- .../cfa/analysis/CfaTraceConcretizer.java | 19 +- .../mit/theta/cfa/analysis/CfaTransFunc.java | 20 +- .../cfa/analysis/DistToErrComparator.java | 27 +- .../theta/cfa/analysis/config/CfaConfig.java | 3 +- .../cfa/analysis/config/CfaConfigBuilder.java | 2 +- .../cfa/analysis/impact/ImpactChecker.java | 27 +- .../cfa/analysis/impact/ImpactReachedSet.java | 28 +- .../cfa/analysis/impact/ImpactRefiner.java | 9 +- .../analysis/impact/PredImpactChecker.java | 61 +- .../analysis/impact/PredImpactRefiner.java | 8 +- .../theta/cfa/analysis/lts/CfaCachedLts.java | 12 +- .../mit/theta/cfa/analysis/lts/CfaLbeLts.java | 17 +- .../mit/theta/cfa/analysis/lts/CfaLts.java | 6 +- .../mit/theta/cfa/analysis/lts/CfaSbeLts.java | 16 +- .../theta/cfa/analysis/lts/package-info.java | 5 +- .../mit/theta/cfa/analysis/package-info.java | 5 +- .../cfa/analysis/prec/GlobalCfaPrec.java | 7 +- .../analysis/prec/GlobalCfaPrecRefiner.java | 14 +- .../theta/cfa/analysis/prec/LocalCfaPrec.java | 27 +- .../analysis/prec/LocalCfaPrecRefiner.java | 19 +- .../prec/RefutationToGlobalCfaPrec.java | 8 +- .../theta/cfa/analysis/prec/package-info.java | 5 +- .../cfa/analysis/utils/CfaVisualizer.java | 2 +- .../cfa/analysis/CfaCombineExtractUtils.kt | 13 +- .../theta/cfa/analysis/CfaControlInitFunc.kt | 11 +- .../cfa/analysis/CfaErrorlocPredicate.kt | 12 +- .../theta/cfa/analysis/CfaToMonolithicExpr.kt | 2 +- .../theta/cfa/analysis/CfaMddCheckerTest.java | 2 +- .../bme/mit/theta/cfa/analysis/CfaTest.java | 235 ++-- .../DistanceToErrorLocComparatorTest.java | 14 +- .../mit/theta/cfa/analysis/EncodingTest.java | 13 +- .../mit/theta/cfa/analysis/LocPrecTest.java | 8 +- .../impact/CfaPredImpactCheckerTest.java | 2 +- .../CfaCombineExtractUtilsUnitTest.kt | 54 +- .../analysis/CfaControlInitFuncUnitTest.kt | 43 +- .../prec/RefutationToGlobalCfaPrecUnitTest.kt | 67 +- subprojects/cfa/cfa-cli/build.gradle.kts | 2 +- .../java/hu/bme/mit/theta/cfa/cli/CfaCli.java | 2 +- .../hu/bme/mit/theta/cfa/cli/CfaMetrics.java | 41 +- subprojects/cfa/cfa/build.gradle.kts | 2 +- .../main/java/hu/bme/mit/theta/cfa/CFA.java | 4 +- .../hu/bme/mit/theta/cfa/CFAVarChanger.kt | 2 +- .../bme/mit/theta/cfa/dsl/CfaDslManager.java | 20 +- .../mit/theta/cfa/dsl/CfaEdgeDefinition.java | 14 +- .../bme/mit/theta/cfa/dsl/CfaExpression.java | 337 +++--- .../mit/theta/cfa/dsl/CfaLocationSymbol.java | 3 +- .../mit/theta/cfa/dsl/CfaProcessSymbol.java | 10 +- .../mit/theta/cfa/dsl/CfaSpecification.java | 15 +- .../bme/mit/theta/cfa/dsl/CfaStatement.java | 10 +- .../hu/bme/mit/theta/cfa/dsl/CfaType.java | 20 +- .../mit/theta/cfa/dsl/CfaVariableSymbol.java | 3 +- .../hu/bme/mit/theta/cfa/dsl/CfaWriter.java | 6 +- .../bme/mit/theta/cfa/dsl/package-info.java | 5 +- .../mit/theta/cfa/parser/CfaInterpreter.java | 17 +- .../bme/mit/theta/cfa/parser/CfaParser.java | 6 +- .../java/hu/bme/mit/theta/cfa/CfaTest.java | 2 +- .../mit/theta/cfa/dsl/CfaDslManagerTest.java | 36 +- .../mit/theta/cfa/parser/CfaParserTest.java | 16 +- .../mit/theta/cfa/CFAVarChangerUnitTest.kt | 30 +- subprojects/common/analysis/build.gradle.kts | 2 +- .../hu/bme/mit/theta/analysis/Action.java | 10 +- .../hu/bme/mit/theta/analysis/Analysis.java | 3 +- .../java/hu/bme/mit/theta/analysis/Cex.java | 2 +- .../hu/bme/mit/theta/analysis/EmptyCex.java | 7 +- .../hu/bme/mit/theta/analysis/InitFunc.java | 7 +- .../bme/mit/theta/analysis/InvTransFunc.java | 3 +- .../java/hu/bme/mit/theta/analysis/LTS.java | 13 +- .../hu/bme/mit/theta/analysis/Lattice.java | 3 +- .../hu/bme/mit/theta/analysis/PartialOrd.java | 7 +- .../java/hu/bme/mit/theta/analysis/Prec.java | 8 +- .../java/hu/bme/mit/theta/analysis/State.java | 7 +- .../java/hu/bme/mit/theta/analysis/Trace.java | 20 +- .../hu/bme/mit/theta/analysis/TransFunc.java | 7 +- .../mit/theta/analysis/algorithm/Checker.java | 2 +- .../theta/analysis/algorithm/EmptyProof.java | 2 +- .../mit/theta/analysis/algorithm/Proof.java | 2 +- .../mit/theta/analysis/algorithm/Result.java | 2 +- .../analysis/algorithm/SafetyChecker.java | 2 +- .../analysis/algorithm/SafetyResult.java | 2 +- .../theta/analysis/algorithm/Statistics.java | 14 +- .../mit/theta/analysis/algorithm/arg/ARG.java | 2 +- .../analysis/algorithm/arg/ArgBuilder.java | 46 +- .../analysis/algorithm/arg/ArgChecker.java | 28 +- .../theta/analysis/algorithm/arg/ArgEdge.java | 3 +- .../theta/analysis/algorithm/arg/ArgNode.java | 65 +- .../algorithm/arg/ArgNodeComparators.java | 53 +- .../algorithm/arg/ArgStructuralEquality.java | 58 +- .../analysis/algorithm/arg/ArgTrace.java | 18 +- .../analysis/algorithm/arg/ArgUtils.java | 9 +- .../algorithm/arg/SearchStrategy.java | 8 +- .../algorithm/arg/debug/ARGWebDebugger.java | 106 +- .../mit/theta/analysis/algorithm/asg/ASG.kt | 2 +- .../theta/analysis/algorithm/asg/ASGTrace.kt | 2 +- .../analysis/algorithm/asg/ASGTraceRefiner.kt | 2 +- .../bounded/AbstractMonolithicExpr.kt | 2 +- .../algorithm/bounded/BoundedChecker.kt | 2 +- .../bounded/BoundedCheckerBuilder.kt | 2 +- .../algorithm/bounded/BoundedStatistics.kt | 12 +- .../algorithm/bounded/MonolithicExpr.kt | 2 +- .../bounded/MonolithicExprCegarChecker.java | 2 +- .../bounded/ReversedMonolithicExpr.kt | 2 +- .../analysis/algorithm/cegar/Abstractor.java | 2 +- .../algorithm/cegar/AbstractorResult.java | 9 +- .../algorithm/cegar/ArgAbstractor.java | 2 +- .../algorithm/cegar/ArgCegarChecker.java | 2 +- .../analysis/algorithm/cegar/ArgRefiner.java | 2 +- .../algorithm/cegar/BasicArgAbstractor.java | 2 +- .../algorithm/cegar/CegarChecker.java | 4 +- .../algorithm/cegar/CegarStatistics.java | 15 +- .../analysis/algorithm/cegar/Refiner.java | 2 +- .../algorithm/cegar/RefinerResult.java | 2 +- .../cegar/abstractor/StopCriterion.java | 9 +- .../cegar/abstractor/StopCriterions.java | 44 +- .../analysis/algorithm/chc/HornChecker.kt | 2 +- .../loopchecker/AcceptancePredicate.kt | 2 +- .../loopchecker/abstraction/ASGAbstractor.kt | 4 +- .../abstraction/GdfsSearchStrategies.kt | 4 +- ...rategy.kt => LoopCheckerSearchStrategy.kt} | 6 +- .../abstraction/NdfsSearchStrategy.kt | 4 +- .../exception/InvalidPathException.kt | 2 +- .../exception/TraceCheckingFailedException.kt | 2 +- .../refinement/ASGTraceCheckerStrategy.kt | 2 +- ...BoundedUnrollingASGTraceCheckerStrategy.kt | 2 +- ...DirectRefinementASGTraceCheckerStrategy.kt | 2 +- .../refinement/SingleASGTraceRefiner.kt | 2 +- .../util/VarCollectorStmtVisitor.kt | 2 +- .../analysis/algorithm/mcm/MemoryEvent.kt | 2 +- .../mcm/analysis/FiniteStateChecker.kt | 2 +- .../algorithm/mcm/analysis/PartialSolver.kt | 2 +- .../mcm/interpreter/MemoryEventProvider.kt | 7 +- .../algorithm/mdd/MddAnalysisStatistics.java | 10 +- .../theta/analysis/algorithm/mdd/MddCex.java | 2 +- .../analysis/algorithm/mdd/MddChecker.java | 2 +- .../analysis/algorithm/mdd/MddProof.java | 2 +- .../algorithm/mdd/MddValuationCollector.java | 25 +- .../mdd/ansd/AbstractNextStateDescriptor.java | 2 +- .../algorithm/mdd/ansd/StateSpaceInfo.java | 36 +- .../mdd/ansd/impl/AnyNextStateDescriptor.java | 9 +- .../ansd/impl/EmptyNextStateDescriptor.java | 8 +- .../impl/IdentityNextStateDescriptor.java | 14 +- .../mdd/ansd/impl/MddNodeInitializer.java | 2 +- .../ansd/impl/MddNodeNextStateDescriptor.java | 2 +- .../mdd/ansd/impl/OrNextStateDescriptor.java | 51 +- .../expressionnode/ExprLatticeDefinition.java | 13 +- .../mdd/expressionnode/LitExprConverter.java | 2 +- .../MddExpressionRepresentation.java | 2 +- .../expressionnode/MddExpressionTemplate.java | 50 +- .../algorithm/mdd/fixedpoint/BfsProvider.java | 65 +- .../CursorGeneralizedSaturationProvider.java | 357 +++--- .../CursorRelationalProductProvider.java | 192 ++- .../GeneralizedSaturationProvider.java | 2 +- .../LegacyRelationalProductProvider.java | 2 +- .../mdd/fixedpoint/MddStateSpaceInfo.java | 2 +- .../fixedpoint/RelationalProductProvider.java | 6 +- .../mdd/fixedpoint/SaturationCache.java | 13 +- .../fixedpoint/SimpleSaturationProvider.java | 2 +- .../StateSpaceEnumerationProvider.java | 9 +- .../mdd/varordering/ForceVarOrdering.kt | 2 +- .../analysis/algorithm/oc/BasicOcChecker.kt | 2 +- .../theta/analysis/algorithm/oc/OcChecker.kt | 2 +- .../theta/analysis/algorithm/oc/OcTypes.kt | 2 +- .../algorithm/oc/UserPropagatorOcChecker.kt | 2 +- .../mit/theta/analysis/expl/ExplAnalysis.java | 6 +- .../mit/theta/analysis/expl/ExplInitFunc.java | 14 +- .../mit/theta/analysis/expl/ExplLattice.java | 3 +- .../bme/mit/theta/analysis/expl/ExplOrd.java | 6 +- .../bme/mit/theta/analysis/expl/ExplPrec.java | 18 +- .../mit/theta/analysis/expl/ExplState.java | 23 +- .../analysis/expl/ExplStatePredicate.java | 5 +- .../theta/analysis/expl/ExplStmtAnalysis.java | 11 +- .../analysis/expl/ExplStmtOptimizer.java | 7 +- .../analysis/expl/ExplStmtTransFunc.java | 32 +- .../theta/analysis/expl/ExplTransFunc.java | 23 +- .../theta/analysis/expl/ItpRefToExplPrec.java | 5 +- .../mit/theta/analysis/expl/StmtApplier.java | 93 +- .../analysis/expl/VarsRefToExplPrec.java | 5 +- .../analysis/expr/BasicExprMeetStrategy.java | 9 +- .../theta/analysis/expr/BasicExprState.java | 2 +- .../mit/theta/analysis/expr/ExprAction.java | 3 +- .../mit/theta/analysis/expr/ExprLattice.java | 12 +- .../theta/analysis/expr/ExprMeetStrategy.java | 6 +- .../bme/mit/theta/analysis/expr/ExprOrd.java | 3 +- .../mit/theta/analysis/expr/ExprState.java | 2 +- .../analysis/expr/ExprStatePredicate.java | 5 +- .../theta/analysis/expr/ExprStateUtils.java | 26 +- .../mit/theta/analysis/expr/ExprStates.java | 54 +- .../theta/analysis/expr/ExprTraceUtils.java | 22 +- .../analysis/expr/IndexedExprInitFunc.java | 7 +- .../expr/IndexedExprInvTransFunc.java | 21 +- .../theta/analysis/expr/IndexedExprState.java | 14 +- .../analysis/expr/IndexedExprTransFunc.java | 21 +- .../expr/SemanticExprMeetStrategy.java | 6 +- .../mit/theta/analysis/expr/StmtAction.java | 10 +- .../expr/SyntacticExprMeetStrategy.java | 2 +- .../expr/refinement/AasporRefiner.java | 2 +- .../refinement/ExprTraceBwBinItpChecker.java | 46 +- .../expr/refinement/ExprTraceChecker.java | 2 +- .../refinement/ExprTraceCombinedChecker.java | 21 +- .../refinement/ExprTraceCombinedCheckers.java | 29 +- .../refinement/ExprTraceFwBinItpChecker.java | 38 +- .../refinement/ExprTraceNewtonChecker.java | 661 ++++++----- .../refinement/ExprTraceSeqItpChecker.java | 33 +- .../expr/refinement/ExprTraceStatus.java | 19 +- .../refinement/ExprTraceStatusMerger.java | 9 +- .../refinement/ExprTraceStatusMergers.java | 27 +- .../expr/refinement/ExprTraceUCBChecker.java | 89 +- .../refinement/ExprTraceUnsatCoreChecker.java | 42 +- .../expr/refinement/ItpRefutation.java | 16 +- .../expr/refinement/JoiningPrecRefiner.java | 9 +- .../refinement/MultiExprTraceRefiner.java | 2 +- .../analysis/expr/refinement/NodePruner.java | 8 +- .../analysis/expr/refinement/PrecRefiner.java | 14 +- .../expr/refinement/PruneStrategy.java | 5 +- .../analysis/expr/refinement/Refutation.java | 2 +- .../expr/refinement/RefutationToPrec.java | 2 +- .../refinement/SingleExprTraceRefiner.java | 2 +- .../expr/refinement/VarsRefutation.java | 10 +- .../expr/refinement/autoexpl/AutoExpl.java | 3 +- .../refinement/autoexpl/NewAtomsAutoExpl.java | 43 +- .../autoexpl/NewOperandsAutoExpl.java | 73 +- .../refinement/autoexpl/StaticAutoExpl.java | 10 +- .../analysis/impl/PrecMappingAnalysis.java | 23 +- .../analysis/impl/PrecMappingInitFunc.java | 23 +- .../analysis/impl/PrecMappingTransFunc.java | 23 +- .../mit/theta/analysis/multi/MultiAction.java | 3 +- .../theta/analysis/multi/MultiAnalysis.java | 118 +- .../mit/theta/analysis/multi/MultiLts.java | 45 +- .../mit/theta/analysis/multi/MultiPrec.java | 7 +- .../mit/theta/analysis/multi/MultiSide.java | 6 +- .../mit/theta/analysis/multi/MultiState.java | 45 +- .../analysis/multi/MultiStatePredicate.java | 10 +- .../analysis/multi/NextSideFunctions.java | 32 +- .../theta/analysis/multi/RefToMultiPrec.java | 24 +- .../multi/builder/MultiBuilderResultPOJO.java | 62 +- .../builder/stmt/StmtMultiBuilderPair.java | 64 +- .../analysis/multi/stmt/ExprMultiState.java | 26 +- .../analysis/multi/stmt/StmtMultiAction.java | 30 +- .../multi/stmt/StmtMultiAnalysis.java | 96 +- .../analysis/multi/stmt/StmtMultiLts.java | 52 +- .../bme/mit/theta/analysis/package-info.java | 5 +- .../theta/analysis/pred/ExprSplitters.java | 24 +- .../theta/analysis/pred/ItpRefToPredPrec.java | 13 +- .../theta/analysis/pred/PredAbstractors.java | 109 +- .../mit/theta/analysis/pred/PredAnalysis.java | 16 +- .../mit/theta/analysis/pred/PredInitFunc.java | 21 +- .../bme/mit/theta/analysis/pred/PredOrd.java | 3 +- .../bme/mit/theta/analysis/pred/PredPrec.java | 35 +- .../mit/theta/analysis/pred/PredState.java | 41 +- .../analysis/pred/PredStmtOptimizer.java | 7 +- .../theta/analysis/pred/PredTransFunc.java | 30 +- .../DefaultPreStrengtheningOperator.java | 13 +- .../prod2/PreStrengtheningOperator.java | 3 +- .../theta/analysis/prod2/Prod2Analysis.java | 67 +- .../theta/analysis/prod2/Prod2InitFunc.java | 42 +- .../mit/theta/analysis/prod2/Prod2Ord.java | 14 +- .../mit/theta/analysis/prod2/Prod2Prec.java | 11 +- .../mit/theta/analysis/prod2/Prod2State.java | 51 +- .../analysis/prod2/Prod2StmtOptimizer.java | 21 +- .../theta/analysis/prod2/Prod2TransFunc.java | 91 +- .../analysis/prod2/StrengtheningOperator.java | 12 +- .../AutomaticItpRefToProd2ExplPredPrec.java | 48 +- .../ItpRefToProd2ExplPredPrec.java | 32 +- .../Prod2ExplPredAbstractors.java | 64 +- .../prod2explpred/Prod2ExplPredAnalysis.java | 36 +- .../Prod2ExplPredDedicatedTransFunc.java | 33 +- ...Prod2ExplPredPreStrengtheningOperator.java | 14 +- .../Prod2ExplPredStmtOptimizer.java | 4 +- .../Prod2ExplPredStrengtheningOperator.java | 13 +- .../theta/analysis/prod3/Prod3Analysis.java | 53 +- .../theta/analysis/prod3/Prod3InitFunc.java | 48 +- .../mit/theta/analysis/prod3/Prod3Ord.java | 17 +- .../mit/theta/analysis/prod3/Prod3Prec.java | 20 +- .../mit/theta/analysis/prod3/Prod3State.java | 74 +- .../theta/analysis/prod3/Prod3TransFunc.java | 72 +- .../theta/analysis/prod4/Prod4Analysis.java | 67 +- .../theta/analysis/prod4/Prod4InitFunc.java | 59 +- .../mit/theta/analysis/prod4/Prod4Ord.java | 24 +- .../mit/theta/analysis/prod4/Prod4Prec.java | 33 +- .../mit/theta/analysis/prod4/Prod4State.java | 107 +- .../theta/analysis/prod4/Prod4TransFunc.java | 87 +- .../mit/theta/analysis/ptr/ItpRefToPtrPrec.kt | 2 +- .../bme/mit/theta/analysis/ptr/PtrAction.kt | 2 +- .../bme/mit/theta/analysis/ptr/PtrAnalysis.kt | 2 +- .../hu/bme/mit/theta/analysis/ptr/PtrPrec.kt | 9 +- .../hu/bme/mit/theta/analysis/ptr/PtrState.kt | 21 +- .../hu/bme/mit/theta/analysis/ptr/PtrUtils.kt | 2 +- .../theta/analysis/reachedset/Partition.java | 6 +- .../theta/analysis/reachedset/ReachedSet.java | 6 +- .../analysis/runtimemonitor/CexMonitor.kt | 2 +- .../theta/analysis/runtimemonitor/Monitor.kt | 6 +- .../runtimemonitor/MonitorCheckpoint.kt | 2 +- .../container/CexHashStorage.kt | 22 +- .../container/RuntimeDataCollection.kt | 7 +- .../stmtoptimizer/DefaultStmtOptimizer.java | 3 +- .../analysis/stmtoptimizer/StmtOptimizer.java | 3 +- .../mit/theta/analysis/unit/UnitAnalysis.java | 8 +- .../mit/theta/analysis/unit/UnitInitFunc.java | 2 +- .../bme/mit/theta/analysis/unit/UnitOrd.java | 6 +- .../bme/mit/theta/analysis/unit/UnitPrec.java | 6 +- .../mit/theta/analysis/unit/UnitState.java | 6 +- .../theta/analysis/unit/UnitTransFunc.java | 14 +- .../theta/analysis/utils/ArgVisualizer.java | 2 +- .../mit/theta/analysis/utils/LDGVisualizer.kt | 2 +- .../utils/MddNodeCacheVisualizer.java | 68 +- .../analysis/utils/MddNodeVisualizer.java | 2 +- .../theta/analysis/utils/ProofVisualizer.java | 2 +- .../theta/analysis/utils/TraceVisualizer.java | 58 +- .../theta/analysis/waitlist/FifoWaitlist.java | 9 +- .../theta/analysis/waitlist/LifoWaitlist.java | 9 +- .../analysis/waitlist/PriorityWaitlist.java | 13 +- .../analysis/waitlist/RandomWaitlist.java | 10 +- .../mit/theta/analysis/waitlist/Waitlist.java | 2 +- .../theta/analysis/waitlist/package-info.java | 5 +- .../bme/mit/theta/analysis/zone/BasicDbm.java | 10 +- .../mit/theta/analysis/zone/BoundFunc.java | 69 +- .../hu/bme/mit/theta/analysis/zone/DBM.java | 112 +- .../mit/theta/analysis/zone/DbmRelation.java | 7 +- .../mit/theta/analysis/zone/DbmSignature.java | 26 +- .../mit/theta/analysis/zone/DiffBounds.java | 11 +- .../bme/mit/theta/analysis/zone/ZeroVar.java | 6 +- .../mit/theta/analysis/zone/ZoneLattice.java | 2 +- .../bme/mit/theta/analysis/zone/ZoneOrd.java | 6 +- .../bme/mit/theta/analysis/zone/ZonePrec.java | 10 +- .../mit/theta/analysis/zone/ZoneState.java | 43 +- .../theta/analysis/multi/MultiAnalysisSide.kt | 24 +- .../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 +- .../multi/builder/stmt/StmtMultiBuilder.kt | 30 +- .../analysis/multi/config/MultiConfig.kt | 28 +- .../multi/config/StmtMultiConfigBuilder.kt | 2 +- .../hu/bme/mit/theta/analysis/TraceTest.java | 7 +- .../theta/analysis/algorithm/BoundedTest.kt | 2 +- .../analysis/algorithm/ExprActionStub.java | 4 +- .../analysis/algorithm/ExprStateStub.java | 3 +- .../mit/theta/analysis/algorithm/HornTest.kt | 63 +- .../analysis/algorithm/arg/ArgCexTest.java | 24 +- .../algorithm/arg/ArgNodeComparatorsTest.java | 48 +- .../algorithm/arg/ArgPruningTest.java | 15 +- .../arg/ArgStructuralEqualityTest.java | 31 +- .../ASGAbstractorCheckingTest.java | 8 +- .../loopchecker/ASGCegarVerifierTest.java | 8 +- .../loopchecker/ASGTraceCheckerTest.java | 6 +- .../loopchecker/ldg/ASGTraceTest.java | 2 +- .../utils/VarCollectorStmtVisitorTest.kt | 2 +- .../algorithm/mdd/MddCheckerTest.java | 2 +- .../mdd/MddConstrainedCursorTest.java | 2 +- .../algorithm/mdd/MddExpressionTest.java | 97 +- .../algorithm/mdd/MddRelProdTest.java | 2 +- .../algorithm/mdd/MddStateSpaceInfoTest.java | 2 +- .../theta/analysis/expl/ExplInitFuncTest.java | 33 +- .../mit/theta/analysis/expl/ExplOrdTest.java | 11 +- .../mit/theta/analysis/expl/ExplPrecTest.java | 16 +- .../analysis/expl/ExplStatePredicateTest.java | 50 +- .../theta/analysis/expl/ExplStateTest.java | 13 +- .../analysis/expl/ExplStmtTransFuncTest.java | 58 +- .../analysis/expl/ExplTransFuncTest.java | 41 +- .../theta/analysis/expl/StmtApplierTest.java | 125 +- .../theta/analysis/expr/ExprOrdLeqTest.java | 38 +- .../theta/analysis/expr/ExprStatesTest.java | 42 +- .../analysis/expr/ExprTraceCheckersTest.java | 34 +- .../analysis/pred/ExplSplittersTest.java | 10 +- .../theta/analysis/pred/PredInitFuncTest.java | 32 +- .../mit/theta/analysis/pred/PredOrdTest.java | 7 +- .../mit/theta/analysis/pred/PredPrecTest.java | 11 +- .../analysis/pred/PredTransFuncTest.java | 27 +- .../mit/theta/analysis/ptr/PtrAnalysisTest.kt | 2 +- .../mit/theta/analysis/stubs/ActionStub.java | 3 +- .../theta/analysis/stubs/PartialOrdStub.java | 3 +- .../mit/theta/analysis/stubs/PrecStub.java | 3 +- .../mit/theta/analysis/stubs/StateStub.java | 3 +- .../theta/analysis/waitlist/WaitlistTest.java | 8 +- .../theta/analysis/zone/DiffBoundTest.java | 3 +- .../theta/analysis/multi/MultiAnalysisTest.kt | 234 ++-- subprojects/common/common/build.gradle.kts | 2 +- .../hu/bme/mit/theta/common/CliUtils.java | 5 +- .../bme/mit/theta/common/DispatchTable.java | 21 +- .../bme/mit/theta/common/DispatchTable2.java | 22 +- .../java/hu/bme/mit/theta/common/Either.java | 12 +- .../bme/mit/theta/common/GrowingIntArray.java | 3 +- .../hu/bme/mit/theta/common/IntMatrix.java | 3 +- .../mit/theta/common/LispStringBuilder.java | 19 +- .../hu/bme/mit/theta/common/OsHelper.java | 13 +- .../hu/bme/mit/theta/common/QuadFunction.java | 6 +- .../bme/mit/theta/common/QuintFunction.java | 10 +- .../bme/mit/theta/common/TernaryOperator.java | 15 +- .../hu/bme/mit/theta/common/TriFunction.java | 2 +- .../java/hu/bme/mit/theta/common/Try.java | 10 +- .../java/hu/bme/mit/theta/common/Tuple.java | 10 +- .../java/hu/bme/mit/theta/common/Tuple1.java | 11 +- .../java/hu/bme/mit/theta/common/Tuple2.java | 12 +- .../java/hu/bme/mit/theta/common/Tuple3.java | 12 +- .../java/hu/bme/mit/theta/common/Tuple4.java | 19 +- .../java/hu/bme/mit/theta/common/Tuple5.java | 23 +- .../java/hu/bme/mit/theta/common/Tuple6.java | 26 +- .../java/hu/bme/mit/theta/common/Tuple7.java | 45 +- .../java/hu/bme/mit/theta/common/TupleN.java | 25 +- .../java/hu/bme/mit/theta/common/Unit.java | 6 +- .../java/hu/bme/mit/theta/common/Utils.java | 18 +- .../theta/common/container/Containers.java | 8 +- .../container/factory/ContainerFactory.java | 3 +- .../factory/HashContainerFactory.java | 2 +- .../factory/LinkedHashContainerFactory.java | 2 +- .../bme/mit/theta/common/datalog/Datalog.java | 248 ++-- .../theta/common/datalog/DatalogArgument.java | 7 +- .../datalog/GenericDatalogArgument.java | 3 +- .../common/datalog/StringDatalogArgument.java | 3 +- .../theta/common/dsl/BasicDynamicScope.java | 6 +- .../bme/mit/theta/common/dsl/BasicScope.java | 3 +- .../theta/common/dsl/BasicScopedSymbol.java | 9 +- .../mit/theta/common/dsl/DynamicScope.java | 3 +- .../java/hu/bme/mit/theta/common/dsl/Env.java | 25 +- .../mit/theta/common/dsl/MutableScope.java | 3 +- .../hu/bme/mit/theta/common/dsl/Scope.java | 3 +- .../mit/theta/common/dsl/ScopedSymbol.java | 6 +- .../hu/bme/mit/theta/common/dsl/Symbol.java | 3 +- .../bme/mit/theta/common/dsl/SymbolTable.java | 6 +- .../exception/NotSolvableException.java | 5 +- .../mit/theta/common/logging/BaseLogger.java | 7 +- .../common/logging/ConsoleLabelledLogger.java | 2 +- .../theta/common/logging/ConsoleLogger.java | 3 +- .../mit/theta/common/logging/FileLogger.java | 10 +- .../bme/mit/theta/common/logging/Logger.java | 2 +- .../mit/theta/common/logging/NullLogger.java | 6 +- .../common/logging/UniqueWarningLogger.java | 2 +- .../theta/common/logging/package-info.java | 5 +- .../theta/common/parser/LexerException.java | 3 +- .../mit/theta/common/parser/LispLexer.java | 3 +- .../mit/theta/common/parser/LispParser.java | 7 +- .../theta/common/parser/ParserException.java | 3 +- .../hu/bme/mit/theta/common/parser/SExpr.java | 27 +- .../hu/bme/mit/theta/common/parser/Token.java | 3 +- .../mit/theta/common/parser/TokenType.java | 7 +- .../common/process/SimpleProcessRunner.kt | 2 +- .../theta/common/table/BasicTableWriter.java | 14 +- .../theta/common/table/HtmlTableWriter.java | 7 +- .../mit/theta/common/table/TableWriter.java | 6 +- .../mit/theta/common/table/package-info.java | 5 +- .../theta/common/visualization/Alignment.java | 6 +- .../common/visualization/CompositeNode.java | 6 +- .../mit/theta/common/visualization/Edge.java | 7 +- .../common/visualization/EdgeAttributes.java | 12 +- .../mit/theta/common/visualization/Graph.java | 10 +- .../common/visualization/JSONWriter.java | 65 +- .../theta/common/visualization/LineStyle.java | 6 +- .../mit/theta/common/visualization/Node.java | 7 +- .../common/visualization/NodeAttributes.java | 18 +- .../mit/theta/common/visualization/Shape.java | 6 +- .../visualization/WebDebuggerLogger.java | 16 +- .../common/visualization/package-info.java | 5 +- .../writer/AbstractGraphWriter.java | 11 +- .../visualization/writer/GraphWriter.java | 9 +- .../visualization/writer/GraphvizWriter.java | 47 +- .../visualization/writer/YedWriter.java | 55 +- .../theta/common/datalog/DatalogJavaTest.java | 38 +- .../common/datalog/DatalogStringTest.java | 46 +- .../theta/common/parser/LispLexerTest.java | 64 +- .../bme/mit/theta/common/parser/SExpTest.java | 36 +- .../theta/common/table/TableWriterTest.java | 6 +- .../visualization/VisualizationTest.java | 23 +- subprojects/common/core/build.gradle.kts | 2 +- .../java/hu/bme/mit/theta/core/ChcUtils.kt | 2 +- .../theta/core/clock/constr/AndConstr.java | 16 +- .../theta/core/clock/constr/AtomicConstr.java | 3 +- .../theta/core/clock/constr/ClockConstr.java | 6 +- .../core/clock/constr/ClockConstrVisitor.java | 3 +- .../theta/core/clock/constr/ClockConstrs.java | 76 +- .../theta/core/clock/constr/DiffConstr.java | 11 +- .../theta/core/clock/constr/DiffEqConstr.java | 18 +- .../core/clock/constr/DiffGeqConstr.java | 22 +- .../theta/core/clock/constr/DiffGtConstr.java | 18 +- .../core/clock/constr/DiffLeqConstr.java | 22 +- .../theta/core/clock/constr/DiffLtConstr.java | 18 +- .../clock/constr/FailClockConstrVisitor.java | 3 +- .../theta/core/clock/constr/FalseConstr.java | 10 +- .../theta/core/clock/constr/TrueConstr.java | 10 +- .../theta/core/clock/constr/UnitConstr.java | 7 +- .../theta/core/clock/constr/UnitEqConstr.java | 13 +- .../core/clock/constr/UnitGeqConstr.java | 13 +- .../theta/core/clock/constr/UnitGtConstr.java | 13 +- .../core/clock/constr/UnitLeqConstr.java | 13 +- .../theta/core/clock/constr/UnitLtConstr.java | 13 +- .../bme/mit/theta/core/clock/op/ClockOp.java | 6 +- .../theta/core/clock/op/ClockOpVisitor.java | 3 +- .../bme/mit/theta/core/clock/op/ClockOps.java | 25 +- .../bme/mit/theta/core/clock/op/CopyOp.java | 14 +- .../core/clock/op/FailClockOpVisitor.java | 3 +- .../bme/mit/theta/core/clock/op/FreeOp.java | 10 +- .../bme/mit/theta/core/clock/op/GuardOp.java | 10 +- .../bme/mit/theta/core/clock/op/ResetOp.java | 14 +- .../bme/mit/theta/core/clock/op/ShiftOp.java | 14 +- .../mit/theta/core/clock/package-info.java | 5 +- .../mit/theta/core/decl/BasicConstDecl.java | 3 +- .../hu/bme/mit/theta/core/decl/ConstDecl.java | 9 +- .../java/hu/bme/mit/theta/core/decl/Decl.java | 3 +- .../hu/bme/mit/theta/core/decl/Decls.java | 10 +- .../mit/theta/core/decl/IndexedConstDecl.java | 3 +- .../mit/theta/core/decl/IndexedVarDecl.java | 6 +- .../hu/bme/mit/theta/core/decl/ParamDecl.java | 2 +- .../hu/bme/mit/theta/core/decl/VarDecl.java | 13 +- .../bme/mit/theta/core/decl/package-info.java | 17 +- .../mit/theta/core/dsl/CoreDslManager.java | 16 +- .../hu/bme/mit/theta/core/dsl/DeclSymbol.java | 7 +- .../bme/mit/theta/core/dsl/ParamBinding.java | 28 +- .../mit/theta/core/dsl/ParseException.java | 13 +- .../theta/core/dsl/impl/CoreDslHelper.java | 33 +- .../core/dsl/impl/ExprCreatorVisitor.java | 257 ++-- .../mit/theta/core/dsl/impl/ExprWriter.java | 446 +++---- .../core/dsl/impl/StmtCreatorVisitor.java | 13 +- .../mit/theta/core/dsl/impl/StmtWriter.java | 6 +- .../core/dsl/impl/TypeCreatorVisitor.java | 10 +- .../bme/mit/theta/core/dsl/package-info.java | 5 +- .../theta/core/model/BasicSubstitution.java | 24 +- .../theta/core/model/ImmutableValuation.java | 17 +- .../model/MutablePartitionedValuation.java | 29 +- .../theta/core/model/MutableValuation.java | 25 +- .../theta/core/model/NestedSubstitution.java | 15 +- .../mit/theta/core/model/Substitution.java | 11 +- .../bme/mit/theta/core/model/Valuation.java | 18 +- .../mit/theta/core/model/package-info.java | 5 +- .../theta/core/parser/CoreInterpreter.java | 26 +- .../bme/mit/theta/core/parser/CoreParser.java | 6 +- .../hu/bme/mit/theta/core/parser/Env.java | 18 +- .../bme/mit/theta/core/stmt/AssignStmt.java | 23 +- .../bme/mit/theta/core/stmt/AssumeStmt.java | 10 +- .../hu/bme/mit/theta/core/stmt/HavocStmt.java | 6 +- .../hu/bme/mit/theta/core/stmt/IfStmt.java | 15 +- .../hu/bme/mit/theta/core/stmt/LoopStmt.java | 28 +- .../mit/theta/core/stmt/MemoryAssignStmt.java | 33 +- .../bme/mit/theta/core/stmt/NonDetStmt.java | 4 +- .../hu/bme/mit/theta/core/stmt/OrtStmt.java | 6 +- .../bme/mit/theta/core/stmt/SequenceStmt.java | 4 +- .../hu/bme/mit/theta/core/stmt/SkipStmt.java | 10 +- .../java/hu/bme/mit/theta/core/stmt/Stmt.java | 3 +- .../bme/mit/theta/core/stmt/StmtVisitor.java | 6 +- .../hu/bme/mit/theta/core/stmt/Stmts.java | 11 +- .../bme/mit/theta/core/stmt/package-info.java | 5 +- .../bme/mit/theta/core/type/BinaryExpr.java | 24 +- .../bme/mit/theta/core/type/DomainSize.java | 16 +- .../java/hu/bme/mit/theta/core/type/Expr.java | 6 +- .../hu/bme/mit/theta/core/type/LitExpr.java | 6 +- .../bme/mit/theta/core/type/MultiaryExpr.java | 18 +- .../bme/mit/theta/core/type/NullaryExpr.java | 6 +- .../java/hu/bme/mit/theta/core/type/Type.java | 2 +- .../hu/bme/mit/theta/core/type/UnaryExpr.java | 13 +- .../core/type/abstracttype/AbstractExprs.java | 101 +- .../theta/core/type/abstracttype/AddExpr.java | 13 +- .../core/type/abstracttype/Additive.java | 3 +- .../core/type/abstracttype/CastExpr.java | 3 +- .../core/type/abstracttype/Castable.java | 3 +- .../theta/core/type/abstracttype/DivExpr.java | 10 +- .../core/type/abstracttype/Divisible.java | 2 +- .../theta/core/type/abstracttype/EqExpr.java | 14 +- .../core/type/abstracttype/Equational.java | 3 +- .../theta/core/type/abstracttype/GeqExpr.java | 10 +- .../theta/core/type/abstracttype/GtExpr.java | 10 +- .../theta/core/type/abstracttype/LeqExpr.java | 10 +- .../theta/core/type/abstracttype/LtExpr.java | 10 +- .../theta/core/type/abstracttype/ModExpr.java | 17 +- .../theta/core/type/abstracttype/MulExpr.java | 13 +- .../type/abstracttype/Multiplicative.java | 3 +- .../theta/core/type/abstracttype/NegExpr.java | 10 +- .../theta/core/type/abstracttype/NeqExpr.java | 14 +- .../theta/core/type/abstracttype/Ordered.java | 3 +- .../theta/core/type/abstracttype/PosExpr.java | 14 +- .../theta/core/type/abstracttype/RemExpr.java | 17 +- .../theta/core/type/abstracttype/SubExpr.java | 14 +- .../core/type/abstracttype/package-info.java | 37 +- .../theta/core/type/anytype/Dereference.java | 28 +- .../mit/theta/core/type/anytype/Exprs.java | 2 +- .../core/type/anytype/InvalidLitExpr.java | 5 +- .../mit/theta/core/type/anytype/IteExpr.java | 43 +- .../theta/core/type/anytype/PrimeExpr.java | 3 +- .../mit/theta/core/type/anytype/RefExpr.java | 7 +- .../theta/core/type/anytype/Reference.java | 19 +- .../theta/core/type/anytype/package-info.java | 9 +- .../core/type/arraytype/ArrayEqExpr.java | 32 +- .../theta/core/type/arraytype/ArrayExprs.java | 56 +- .../core/type/arraytype/ArrayInitExpr.java | 80 +- .../core/type/arraytype/ArrayLitExpr.java | 70 +- .../core/type/arraytype/ArrayNeqExpr.java | 32 +- .../core/type/arraytype/ArrayReadExpr.java | 44 +- .../theta/core/type/arraytype/ArrayType.java | 14 +- .../core/type/arraytype/ArrayWriteExpr.java | 57 +- .../core/type/arraytype/package-info.java | 29 +- .../mit/theta/core/type/booltype/AndExpr.java | 14 +- .../theta/core/type/booltype/BoolExprs.java | 57 +- .../theta/core/type/booltype/BoolLitExpr.java | 3 +- .../theta/core/type/booltype/BoolType.java | 6 +- .../theta/core/type/booltype/ExistsExpr.java | 21 +- .../theta/core/type/booltype/FalseExpr.java | 10 +- .../theta/core/type/booltype/ForallExpr.java | 20 +- .../mit/theta/core/type/booltype/IffExpr.java | 13 +- .../theta/core/type/booltype/ImplyExpr.java | 13 +- .../mit/theta/core/type/booltype/NotExpr.java | 9 +- .../mit/theta/core/type/booltype/OrExpr.java | 14 +- .../core/type/booltype/QuantifiedExpr.java | 31 +- .../core/type/booltype/SmartBoolExprs.java | 61 +- .../theta/core/type/booltype/TrueExpr.java | 10 +- .../mit/theta/core/type/booltype/XorExpr.java | 16 +- .../core/type/booltype/package-info.java | 35 +- .../mit/theta/core/type/bvtype/BvAddExpr.java | 23 +- .../mit/theta/core/type/bvtype/BvAndExpr.java | 22 +- .../type/bvtype/BvArithShiftRightExpr.java | 14 +- .../theta/core/type/bvtype/BvConcatExpr.java | 22 +- .../mit/theta/core/type/bvtype/BvEqExpr.java | 14 +- .../mit/theta/core/type/bvtype/BvExprs.java | 29 +- .../theta/core/type/bvtype/BvExtractExpr.java | 40 +- .../mit/theta/core/type/bvtype/BvLitExpr.java | 101 +- .../type/bvtype/BvLogicShiftRightExpr.java | 14 +- .../mit/theta/core/type/bvtype/BvMulExpr.java | 23 +- .../mit/theta/core/type/bvtype/BvNegExpr.java | 8 +- .../mit/theta/core/type/bvtype/BvNeqExpr.java | 14 +- .../mit/theta/core/type/bvtype/BvNotExpr.java | 7 +- .../mit/theta/core/type/bvtype/BvOrExpr.java | 23 +- .../mit/theta/core/type/bvtype/BvPosExpr.java | 8 +- .../core/type/bvtype/BvRotateLeftExpr.java | 12 +- .../core/type/bvtype/BvRotateRightExpr.java | 12 +- .../theta/core/type/bvtype/BvSDivExpr.java | 13 +- .../theta/core/type/bvtype/BvSExtExpr.java | 17 +- .../theta/core/type/bvtype/BvSGeqExpr.java | 16 +- .../mit/theta/core/type/bvtype/BvSGtExpr.java | 16 +- .../theta/core/type/bvtype/BvSLeqExpr.java | 16 +- .../mit/theta/core/type/bvtype/BvSLtExpr.java | 16 +- .../theta/core/type/bvtype/BvSModExpr.java | 13 +- .../theta/core/type/bvtype/BvSRemExpr.java | 13 +- .../core/type/bvtype/BvShiftLeftExpr.java | 12 +- .../core/type/bvtype/BvSignChangeExpr.java | 8 +- .../mit/theta/core/type/bvtype/BvSubExpr.java | 14 +- .../mit/theta/core/type/bvtype/BvType.java | 26 +- .../theta/core/type/bvtype/BvUDivExpr.java | 13 +- .../theta/core/type/bvtype/BvUGeqExpr.java | 16 +- .../mit/theta/core/type/bvtype/BvUGtExpr.java | 16 +- .../theta/core/type/bvtype/BvULeqExpr.java | 16 +- .../mit/theta/core/type/bvtype/BvULtExpr.java | 16 +- .../theta/core/type/bvtype/BvURemExpr.java | 13 +- .../mit/theta/core/type/bvtype/BvXorExpr.java | 22 +- .../theta/core/type/bvtype/BvZExtExpr.java | 17 +- .../theta/core/type/bvtype/package-info.java | 81 +- .../theta/core/type/enumtype/EnumEqExpr.java | 9 +- .../theta/core/type/enumtype/EnumLitExpr.java | 14 +- .../theta/core/type/enumtype/EnumNeqExpr.java | 9 +- .../theta/core/type/enumtype/EnumType.java | 2 +- .../mit/theta/core/type/fptype/FpAbsExpr.java | 9 +- .../mit/theta/core/type/fptype/FpAddExpr.java | 39 +- .../theta/core/type/fptype/FpAssignExpr.java | 15 +- .../mit/theta/core/type/fptype/FpDivExpr.java | 26 +- .../mit/theta/core/type/fptype/FpEqExpr.java | 14 +- .../mit/theta/core/type/fptype/FpExprs.java | 52 +- .../theta/core/type/fptype/FpFromBvExpr.java | 51 +- .../mit/theta/core/type/fptype/FpGeqExpr.java | 14 +- .../mit/theta/core/type/fptype/FpGtExpr.java | 14 +- .../core/type/fptype/FpIsInfiniteExpr.java | 14 +- .../theta/core/type/fptype/FpIsNanExpr.java | 11 +- .../mit/theta/core/type/fptype/FpLeqExpr.java | 14 +- .../mit/theta/core/type/fptype/FpLitExpr.java | 86 +- .../mit/theta/core/type/fptype/FpLtExpr.java | 14 +- .../mit/theta/core/type/fptype/FpMaxExpr.java | 15 +- .../mit/theta/core/type/fptype/FpMinExpr.java | 15 +- .../mit/theta/core/type/fptype/FpMulExpr.java | 39 +- .../mit/theta/core/type/fptype/FpNegExpr.java | 7 +- .../mit/theta/core/type/fptype/FpNeqExpr.java | 14 +- .../mit/theta/core/type/fptype/FpPosExpr.java | 7 +- .../mit/theta/core/type/fptype/FpRemExpr.java | 19 +- .../type/fptype/FpRoundToIntegralExpr.java | 21 +- .../core/type/fptype/FpRoundingMode.java | 3 +- .../theta/core/type/fptype/FpSqrtExpr.java | 14 +- .../mit/theta/core/type/fptype/FpSubExpr.java | 30 +- .../theta/core/type/fptype/FpToBvExpr.java | 46 +- .../theta/core/type/fptype/FpToFpExpr.java | 34 +- .../mit/theta/core/type/fptype/FpType.java | 18 +- .../theta/core/type/functype/FuncAppExpr.java | 34 +- .../theta/core/type/functype/FuncExprs.java | 57 +- .../theta/core/type/functype/FuncLitExpr.java | 27 +- .../theta/core/type/functype/FuncType.java | 19 +- .../theta/core/type/inttype/IntAddExpr.java | 12 +- .../theta/core/type/inttype/IntDivExpr.java | 13 +- .../theta/core/type/inttype/IntEqExpr.java | 15 +- .../mit/theta/core/type/inttype/IntExprs.java | 50 +- .../theta/core/type/inttype/IntGeqExpr.java | 14 +- .../theta/core/type/inttype/IntGtExpr.java | 15 +- .../theta/core/type/inttype/IntLeqExpr.java | 15 +- .../theta/core/type/inttype/IntLitExpr.java | 19 +- .../theta/core/type/inttype/IntLtExpr.java | 15 +- .../theta/core/type/inttype/IntModExpr.java | 13 +- .../theta/core/type/inttype/IntMulExpr.java | 12 +- .../theta/core/type/inttype/IntNegExpr.java | 9 +- .../theta/core/type/inttype/IntNeqExpr.java | 15 +- .../theta/core/type/inttype/IntPosExpr.java | 9 +- .../theta/core/type/inttype/IntRemExpr.java | 13 +- .../theta/core/type/inttype/IntSubExpr.java | 13 +- .../theta/core/type/inttype/IntToRatExpr.java | 11 +- .../mit/theta/core/type/inttype/IntType.java | 23 +- .../theta/core/type/inttype/package-info.java | 49 +- .../bme/mit/theta/core/type/package-info.java | 29 +- .../theta/core/type/rattype/RatAddExpr.java | 12 +- .../theta/core/type/rattype/RatDivExpr.java | 13 +- .../theta/core/type/rattype/RatEqExpr.java | 15 +- .../mit/theta/core/type/rattype/RatExprs.java | 49 +- .../theta/core/type/rattype/RatGeqExpr.java | 14 +- .../theta/core/type/rattype/RatGtExpr.java | 15 +- .../theta/core/type/rattype/RatLeqExpr.java | 15 +- .../theta/core/type/rattype/RatLitExpr.java | 72 +- .../theta/core/type/rattype/RatLtExpr.java | 15 +- .../theta/core/type/rattype/RatMulExpr.java | 12 +- .../theta/core/type/rattype/RatNegExpr.java | 9 +- .../theta/core/type/rattype/RatNeqExpr.java | 15 +- .../theta/core/type/rattype/RatPosExpr.java | 9 +- .../theta/core/type/rattype/RatSubExpr.java | 13 +- .../theta/core/type/rattype/RatToIntExpr.java | 11 +- .../mit/theta/core/type/rattype/RatType.java | 10 +- .../theta/core/type/rattype/package-info.java | 41 +- .../hu/bme/mit/theta/core/utils/BvUtils.java | 2 +- .../theta/core/utils/ExprAtomCollector.java | 42 +- .../mit/theta/core/utils/ExprCanonizer.java | 2 +- .../bme/mit/theta/core/utils/ExprCloser.java | 19 +- .../mit/theta/core/utils/ExprCnfChecker.java | 10 +- .../theta/core/utils/ExprCnfTransformer.java | 45 +- .../core/utils/ExprIndexedVarCollector.java | 6 +- .../theta/core/utils/ExprIteEliminator.java | 21 +- .../theta/core/utils/ExprPrimeApplier.java | 10 +- .../mit/theta/core/utils/ExprReverser.java | 2 +- .../mit/theta/core/utils/ExprSimplifier.java | 2 +- .../bme/mit/theta/core/utils/ExprUtils.java | 2 +- .../hu/bme/mit/theta/core/utils/FpUtils.java | 69 +- .../bme/mit/theta/core/utils/IndexedVars.java | 27 +- .../hu/bme/mit/theta/core/utils/Lens.java | 3 +- .../bme/mit/theta/core/utils/PathUtils.java | 71 +- .../mit/theta/core/utils/PrimeCounter.java | 17 +- .../mit/theta/core/utils/SimplifierLevel.java | 5 +- .../hu/bme/mit/theta/core/utils/SpState.java | 33 +- .../theta/core/utils/StmtAtomCollector.java | 20 +- .../theta/core/utils/StmtCounterVisitor.java | 15 +- .../mit/theta/core/utils/StmtSimplifier.java | 98 +- .../core/utils/StmtToExprTransformer.java | 2 +- .../theta/core/utils/StmtUnfoldResult.java | 11 +- .../bme/mit/theta/core/utils/StmtUtils.java | 19 +- .../bme/mit/theta/core/utils/TypeUtils.java | 53 +- .../core/utils/VarCollectorStmtVisitor.java | 20 +- .../bme/mit/theta/core/utils/VarPoolUtil.java | 13 +- .../hu/bme/mit/theta/core/utils/WpState.java | 49 +- .../utils/indexings/BasicVarIndexing.java | 52 +- .../core/utils/indexings/VarIndexing.java | 3 +- .../utils/indexings/VarIndexingBuilder.java | 4 +- .../utils/indexings/VarIndexingFactory.java | 4 +- .../mit/theta/core/utils/package-info.java | 5 +- .../mit/theta/core/utils/VarChangerUtils.kt | 70 +- .../bme/mit/theta/core/dsl/ExprDslTest.java | 61 +- .../bme/mit/theta/core/dsl/ExprWriteTest.java | 102 +- .../bme/mit/theta/core/dsl/StmtDslTest.java | 32 +- .../bme/mit/theta/core/dsl/StmtWriteTest.java | 36 +- .../bme/mit/theta/core/dsl/TypeDslTest.java | 47 +- .../mit/theta/core/expr/EvaluationTest.java | 34 +- .../hu/bme/mit/theta/core/expr/ExprTest.java | 3 +- .../bme/mit/theta/core/expr/IdentityTest.java | 11 +- .../mit/theta/core/expr/RatLitExprTest.java | 34 +- .../mit/theta/core/expr/SmartExprsTest.java | 71 +- .../core/model/SubstitutionApplyTest.java | 44 +- .../theta/core/model/SubstitutionTest.java | 21 +- .../mit/theta/core/model/ValuationTest.java | 8 +- .../mit/theta/core/parser/CoreParserTest.java | 93 +- .../bme/mit/theta/core/type/BvTypeTest.java | 41 +- .../bme/mit/theta/core/type/FpTypeTest.java | 60 +- .../core/utils/ExprAtomCollectorTest.java | 33 +- .../theta/core/utils/ExprCanonizerTest.java | 221 ++-- .../theta/core/utils/ExprCnfCheckerTest.java | 65 +- .../utils/ExprIndexedVarCollectorTest.java | 39 +- .../core/utils/ExprIteEliminatorTest.java | 47 +- .../theta/core/utils/ExprSimplifierTest.java | 436 +++---- .../mit/theta/core/utils/ExprSizeTest.java | 38 +- .../core/utils/ExprVarCollectorTest.java | 33 +- .../mit/theta/core/utils/PathUtilsTest.java | 54 +- .../bme/mit/theta/core/utils/PonateTest.java | 7 +- .../theta/core/utils/PrimeCounterTest.java | 60 +- .../theta/core/utils/StmtSimplifierTest.java | 176 ++- .../core/utils/StmtToExprTransformerTest.java | 2 +- .../utils/VarCollectorStmtVisitorTest.java | 40 +- .../mit/theta/core/utils/VarIndexingTest.java | 27 +- .../bme/mit/theta/core/utils/WpStateTest.java | 51 +- .../mit/theta/core/utils/ArrayTestUtils.java | 73 +- .../mit/theta/core/utils/BoolTestUtils.java | 84 +- .../bme/mit/theta/core/utils/BvTestUtils.java | 342 +++--- .../mit/theta/core/utils/ExpressionUtils.java | 17 +- .../bme/mit/theta/core/utils/FpTestUtils.java | 411 ++++--- .../mit/theta/core/utils/FuncTestUtils.java | 30 +- .../mit/theta/core/utils/IntTestUtils.java | 111 +- .../mit/theta/core/utils/RatTestUtils.java | 98 +- subprojects/common/grammar/build.gradle.kts | 2 +- .../bme/mit/theta/grammar/dsl/SimpleScope.kt | 38 +- .../hu/bme/mit/theta/grammar/dsl/Utils.kt | 2 +- .../mit/theta/grammar/dsl/expr/ExprParser.kt | 2 +- .../mit/theta/grammar/dsl/stmt/StmtParser.kt | 2 +- .../mit/theta/grammar/dsl/type/TypeParser.kt | 86 +- .../bme/mit/theta/grammar/gson/ArgAdapter.kt | 2 +- .../theta/grammar/gson/ArgAdapterHelper.kt | 2 +- .../mit/theta/grammar/gson/OptionalAdapter.kt | 64 +- .../bme/mit/theta/grammar/gson/PairAdapter.kt | 102 +- .../theta/grammar/gson/SafetyResultAdapter.kt | 2 +- .../mit/theta/grammar/gson/StateAdapters.kt | 2 +- .../theta/grammar/gson/StringTypeAdapter.kt | 27 +- .../mit/theta/grammar/gson/TraceAdapter.kt | 2 +- .../mit/theta/grammar/gson/TripleAdapter.kt | 114 +- .../mit/theta/grammar/gson/VarDeclAdapter.kt | 2 +- .../hu/bme/mit/theta/grammar/dsl/ExprTest.kt | 2 +- .../hu/bme/mit/theta/grammar/dsl/StmtTest.kt | 2 +- .../hu/bme/mit/theta/grammar/dsl/TypeTest.kt | 2 +- .../hu/bme/mit/theta/grammar/gson/TestGson.kt | 2 +- subprojects/common/ltl-cli/build.gradle.kts | 2 +- .../kotlin/common/ltl/cli/LtlCliOptions.kt | 8 +- subprojects/common/ltl/build.gradle.kts | 2 +- .../common/cfa/buchi/Ltl2BuchiTransformer.kt | 2 +- .../cfa/buchi/hoa/APGeneratorVisitor.kt | 2 +- .../common/cfa/buchi/hoa/BuchiBuilder.kt | 4 +- .../common/cfa/buchi/hoa/ExternalLtl2Hoaf.kt | 2 +- .../common/cfa/buchi/hoa/LTLExprVisitor.kt | 2 +- .../cfa/buchi/hoa/Ltl2BuchiThroughHoaf.kt | 2 +- .../theta/common/cfa/buchi/hoa/Ltl2Hoaf.kt | 2 +- .../common/cfa/buchi/hoa/Ltl2HoafFromDir.kt | 2 +- .../common/cfa/buchi/hoa/ToStringVisitor.kt | 2 +- .../hu/bme/mit/theta/common/ltl/LtlChecker.kt | 6 +- .../common/ltl/LtlCheckTestWithCfaExpl.kt | 6 +- .../common/ltl/LtlCheckTestWithCfaPred.kt | 14 +- .../common/ltl/LtlCheckTestWithXstsExpl.kt | 6 +- .../common/ltl/LtlCheckTestWithXstsPred.kt | 8 +- .../common/multi-tests/build.gradle.kts | 2 +- .../kotlin/multi/MultiAlternating3Test.kt | 108 +- .../test/kotlin/multi/MultiAlternatingTest.kt | 2 +- .../MultiNondetDiningPhilosophersTest.kt | 2 +- .../test/kotlin/multi/MultiSelfProductTest.kt | 97 +- .../frontends/c-frontend/build.gradle.kts | 4 +- .../hu/bme/mit/theta/frontend/CStatistics.kt | 2 +- .../mit/theta/frontend/FrontendMetadata.java | 30 +- .../bme/mit/theta/frontend/ParseContext.java | 7 +- .../UnsupportedFrontendElementException.java | 3 +- .../transformation/ArchitectureConfig.java | 72 +- .../frontend/transformation/CStmtCounter.java | 3 +- .../grammar/expression/ExpressionVisitor.java | 2 +- .../expression/UnsupportedInitializer.java | 10 +- .../grammar/function/FunctionVisitor.java | 2 +- .../grammar/preprocess/ArithmeticTrait.java | 10 +- .../grammar/preprocess/BitwiseChecker.java | 7 +- .../preprocess/GlobalDeclUsageVisitor.java | 47 +- .../grammar/preprocess/TypedefVisitor.java | 37 +- .../grammar/type/DeclarationVisitor.java | 79 +- .../grammar/type/TypeVisitor.java | 120 +- .../model/declaration/CDeclaration.java | 2 +- .../model/statements/CAssignment.java | 43 +- .../model/statements/CAssume.java | 7 +- .../model/statements/CBreak.java | 3 +- .../model/statements/CCall.java | 14 +- .../model/statements/CCase.java | 3 +- .../model/statements/CCompound.java | 5 +- .../model/statements/CContinue.java | 3 +- .../model/statements/CDecls.java | 4 +- .../model/statements/CDefault.java | 3 +- .../model/statements/CDoWhile.java | 3 +- .../model/statements/CExpr.java | 3 +- .../transformation/model/statements/CFor.java | 10 +- .../model/statements/CFunction.java | 2 +- .../model/statements/CGoto.java | 3 +- .../transformation/model/statements/CIf.java | 9 +- .../model/statements/CInitializerList.java | 9 +- .../model/statements/CProgram.java | 4 +- .../transformation/model/statements/CRet.java | 3 +- .../model/statements/CStatement.java | 2 +- .../model/statements/CStatementVisitor.java | 3 +- .../statements/CStatementVisitorBase.java | 3 +- .../model/statements/CSwitch.java | 3 +- .../model/statements/CWhile.java | 5 +- .../model/types/complex/CComplexType.java | 72 +- .../model/types/complex/CVoid.java | 3 +- .../model/types/complex/compound/CArray.java | 2 +- .../types/complex/compound/CCompound.java | 3 +- .../types/complex/compound/CFunction.java | 4 +- .../types/complex/compound/CPointer.java | 3 +- .../model/types/complex/compound/CStruct.java | 9 +- .../model/types/complex/integer/CInteger.java | 3 +- .../model/types/complex/integer/Fitsall.java | 4 +- .../model/types/complex/integer/Signed.java | 7 +- .../model/types/complex/integer/Unsigned.java | 7 +- .../types/complex/integer/c128/C128.java | 3 +- .../complex/integer/c128/CSigned128.java | 3 +- .../complex/integer/c128/CUnsigned128.java | 3 +- .../types/complex/integer/cbool/CBool.java | 4 +- .../types/complex/integer/cchar/CChar.java | 4 +- .../complex/integer/cchar/CSignedChar.java | 3 +- .../complex/integer/cchar/CUnsignedChar.java | 3 +- .../types/complex/integer/cint/CInt.java | 4 +- .../complex/integer/cint/CSignedInt.java | 3 +- .../complex/integer/cint/CUnsignedInt.java | 3 +- .../types/complex/integer/clong/CLong.java | 4 +- .../complex/integer/clong/CSignedLong.java | 3 +- .../complex/integer/clong/CUnsignedLong.java | 3 +- .../complex/integer/clonglong/CLongLong.java | 3 +- .../integer/clonglong/CSignedLongLong.java | 3 +- .../integer/clonglong/CUnsignedLongLong.java | 3 +- .../types/complex/integer/cshort/CShort.java | 3 +- .../complex/integer/cshort/CSignedShort.java | 3 +- .../integer/cshort/CUnsignedShort.java | 3 +- .../model/types/complex/real/CDouble.java | 3 +- .../model/types/complex/real/CFloat.java | 3 +- .../model/types/complex/real/CLongDouble.java | 3 +- .../model/types/complex/real/CReal.java | 7 +- .../visitors/bitvector/CastVisitor.java | 63 +- .../visitors/bitvector/LimitVisitor.java | 7 +- .../visitors/bitvector/NullValueVisitor.java | 7 +- .../visitors/bitvector/TypeVisitor.java | 4 +- .../visitors/bitvector/UnitValueVisitor.java | 6 +- .../visitors/bitvector/ValueVisitor.java | 7 +- .../complex/visitors/integer/CastVisitor.java | 24 +- .../visitors/integer/LimitVisitor.java | 113 +- .../visitors/integer/NullValueVisitor.java | 7 +- .../complex/visitors/integer/TypeVisitor.java | 8 +- .../visitors/integer/UnitValueVisitor.java | 8 +- .../visitors/integer/ValueVisitor.java | 9 +- .../model/types/simple/Atomic.java | 8 +- .../model/types/simple/CSimpleType.java | 8 +- .../types/simple/CSimpleTypeFactory.java | 10 +- .../model/types/simple/DeclaredName.java | 3 +- .../model/types/simple/Enum.java | 5 +- .../model/types/simple/Extern.java | 9 +- .../model/types/simple/NamedType.java | 54 +- .../model/types/simple/Signed.java | 8 +- .../model/types/simple/Struct.java | 16 +- .../model/types/simple/ThreadLocal.java | 8 +- .../model/types/simple/Typedef.java | 9 +- .../model/types/simple/Unsigned.java | 9 +- .../model/types/simple/Volatile.java | 9 +- .../frontends/chc-frontend/build.gradle.kts | 2 +- .../frontend/chc/ChcBackwardXcfaBuilder.java | 2 +- .../frontend/chc/ChcForwardXcfaBuilder.java | 2 +- .../mit/theta/frontend/chc/ChcFrontend.java | 17 +- .../bme/mit/theta/frontend/chc/ChcUtils.java | 84 +- .../theta/frontend/chc/ChcXcfaBuilder.java | 3 +- subprojects/frontends/llvm/build.gradle.kts | 2 +- .../petrinet-analysis/build.gradle.kts | 4 +- .../petrinet/analysis/ModelProperties.java | 17 +- .../analysis/PtNetDependency2Gxl.java | 37 +- .../petrinet/analysis/PtNetInitializer.java | 10 +- .../petrinet/analysis/PtNetSystem.java | 71 +- .../PtNetTransitionNextStateDescriptor.java | 25 +- .../analysis/VariableOrderingFactory.java | 14 +- .../frontend/petrinet/analysis/BfsTest.java | 29 +- .../analysis/GeneralizedSaturationTest.java | 39 +- .../analysis/RelationalProductTest.java | 8 +- .../analysis/SimpleSaturationTest.java | 32 +- .../frontend/petrinet/analysis/TestData.java | 2 +- .../petrinet-model/build.gradle.kts | 4 +- .../frontend/petrinet/model/Identified.java | 2 +- .../theta/frontend/petrinet/model/PTArc.java | 2 +- .../frontend/petrinet/model/PetriNet.java | 11 +- .../theta/frontend/petrinet/model/Place.java | 2 +- .../theta/frontend/petrinet/model/TPArc.java | 2 +- .../frontend/petrinet/model/Transition.java | 2 +- .../model/utils/GraphVizSerializer.java | 35 +- .../petrinet/pnml/Lip6PnmlToPetrinet.java | 31 +- .../petrinet/pnml/PetriNetParser.java | 3 +- .../petrinet/pnml/PnmlParseException.java | 2 +- .../petrinet/pnml/XMLPnmlToPetrinet.java | 104 +- .../petrinet-xsts/build.gradle.kts | 4 +- .../petrinet/xsts/PetriNetToXSTS.java | 62 +- .../PnmlTest.java | 97 +- .../solver/graph-solver/build.gradle.kts | 2 +- .../java/hu/bme/mit/theta/graphsolver/3VL.kt | 11 +- .../hu/bme/mit/theta/graphsolver/Utils.kt | 13 +- .../compilers/DefaultGraphPatternCompiler.kt | 2 +- .../compilers/GraphPatternCompiler.kt | 2 +- .../pattern2expr/Pattern2ExprCompiler.kt | 2 +- .../patterns/constraints/Acyclic.kt | 7 +- .../patterns/constraints/Cyclic.kt | 7 +- .../graphsolver/patterns/constraints/Empty.kt | 7 +- .../patterns/constraints/GraphConstraint.kt | 7 +- .../patterns/constraints/Irreflexive.kt | 7 +- .../patterns/constraints/Nonempty.kt | 7 +- .../patterns/constraints/Reflexive.kt | 7 +- .../patterns/patterns/BasicEventSet.kt | 12 +- .../patterns/patterns/BasicRelation.kt | 12 +- .../patterns/patterns/CartesianProduct.kt | 6 +- .../patterns/patterns/Complement.kt | 6 +- .../patterns/patterns/ComplementNode.kt | 6 +- .../patterns/patterns/Difference.kt | 6 +- .../patterns/patterns/DifferenceNode.kt | 6 +- .../graphsolver/patterns/patterns/Domain.kt | 6 +- .../patterns/patterns/EdgePattern.kt | 5 +- .../graphsolver/patterns/patterns/EmptyRel.kt | 6 +- .../graphsolver/patterns/patterns/EmptySet.kt | 6 +- .../patterns/patterns/GraphPattern.kt | 10 +- .../patterns/patterns/IdentityClosure.kt | 6 +- .../patterns/patterns/Intersection.kt | 6 +- .../patterns/patterns/IntersectionNode.kt | 6 +- .../graphsolver/patterns/patterns/Inverse.kt | 6 +- .../patterns/patterns/NodePattern.kt | 5 +- .../graphsolver/patterns/patterns/Range.kt | 6 +- .../patterns/ReflexiveTransitiveClosure.kt | 6 +- .../graphsolver/patterns/patterns/Self.kt | 6 +- .../graphsolver/patterns/patterns/Sequence.kt | 6 +- .../graphsolver/patterns/patterns/Toid.kt | 6 +- .../patterns/patterns/TransitiveClosure.kt | 6 +- .../graphsolver/patterns/patterns/Union.kt | 6 +- .../patterns/patterns/UnionNode.kt | 6 +- .../theta/graphsolver/solvers/GraphSolver.kt | 14 +- .../graphsolver/solvers/SATGraphSolver.kt | 14 +- .../mit/theta/graphsolver/GraphSolverTest.kt | 2 +- .../solver/solver-javasmt/build.gradle.kts | 2 +- .../javasmt/JavaSMTDeclTransformer.java | 33 +- .../javasmt/JavaSMTExprTransformer.java | 802 ++++++------- .../solver/javasmt/JavaSMTInterpolant.java | 8 +- .../solver/javasmt/JavaSMTItpMarker.java | 8 +- .../solver/javasmt/JavaSMTItpPattern.java | 24 +- .../solver/javasmt/JavaSMTItpSolver.java | 66 +- .../theta/solver/javasmt/JavaSMTSolver.java | 2 +- .../javasmt/JavaSMTSolverException.java | 4 +- .../solver/javasmt/JavaSMTSolverFactory.java | 175 +-- .../solver/javasmt/JavaSMTSolverManager.java | 19 +- .../solver/javasmt/JavaSMTSymbolTable.java | 19 +- .../javasmt/JavaSMTTermTransformer.java | 1037 +++++++++++------ .../javasmt/JavaSMTTransformationManager.java | 5 +- .../javasmt/JavaSMTTypeTransformer.java | 19 +- .../solver/javasmt/JavaSMTUserPropagator.java | 58 +- .../solver/javasmt/JavaSMTItpSolverTest.java | 81 +- .../javasmt/JavaSMTSolverArrayTest.java | 35 +- .../solver/javasmt/JavaSMTSolverBVTest.java | 43 +- .../javasmt/JavaSMTSolverBooleanTest.java | 35 +- .../solver/javasmt/JavaSMTSolverFPTest.java | 63 +- .../solver/javasmt/JavaSMTSolverIntTest.java | 35 +- .../solver/javasmt/JavaSMTSolverRatTest.java | 35 +- .../solver/javasmt/JavaSMTSolverTest.java | 191 +-- .../javasmt/JavaSMTTransformerTest.java | 98 +- .../javasmt/JavaSMTUserPropagatorTest.java | 47 +- .../theta/solver/javasmt/SolverUtilsTest.java | 52 +- .../solver/solver-smtlib-cli/build.gradle.kts | 2 +- .../theta/solver/smtlib/cli/SmtLibCli.java | 240 ++-- .../solver/solver-smtlib/build.gradle.kts | 2 +- .../solver/smtlib/SmtLibSolverManager.java | 133 ++- .../bitwuzla/BitwuzlaSmtLibSolverFactory.java | 4 +- .../BitwuzlaSmtLibSolverInstaller.java | 59 +- .../BoolectorSmtLibSolverFactory.java | 3 +- .../BoolectorSmtLibSolverInstaller.java | 66 +- .../impl/cvc4/CVC4SmtLibSolverFactory.java | 4 +- .../impl/cvc4/CVC4SmtLibSolverInstaller.java | 52 +- .../smtlib/impl/cvc5/CVC5SmtLibItpMarker.java | 6 +- .../smtlib/impl/cvc5/CVC5SmtLibItpSolver.java | 85 +- .../impl/cvc5/CVC5SmtLibSolverFactory.java | 29 +- .../impl/cvc5/CVC5SmtLibSolverInstaller.java | 132 ++- .../eldarica/EldaricaSmtLibSolverFactory.java | 15 +- .../EldaricaSmtLibSolverInstaller.java | 46 +- .../impl/generic/GenericHornSolver.java | 65 +- .../generic/GenericSmtLibDeclTransformer.java | 28 +- .../generic/GenericSmtLibExprTransformer.java | 423 +++---- .../impl/generic/GenericSmtLibHornSolver.java | 69 +- .../GenericSmtLibOneshotSolverBinary.java | 8 +- .../generic/GenericSmtLibSolverBinary.java | 35 +- .../generic/GenericSmtLibSolverFactory.java | 47 +- .../generic/GenericSmtLibSolverInstaller.java | 26 +- .../generic/GenericSmtLibSymbolTable.java | 27 +- .../generic/GenericSmtLibTermTransformer.java | 444 +++---- .../GenericSmtLibTransformationManager.java | 8 +- .../generic/GenericSmtLibTypeTransformer.java | 13 +- .../impl/golem/GolemSmtLibSolverFactory.java | 6 +- .../golem/GolemSmtLibSolverInstaller.java | 46 +- .../mathsat/MathSATSmtLibExprTransformer.java | 8 +- .../impl/mathsat/MathSATSmtLibItpMarker.java | 2 +- .../impl/mathsat/MathSATSmtLibItpSolver.java | 67 +- .../mathsat/MathSATSmtLibSolverFactory.java | 19 +- .../mathsat/MathSATSmtLibSolverInstaller.java | 181 +-- .../MathSATSmtLibTransformationManager.java | 5 +- .../princess/PrincessSmtLibItpMarker.java | 6 +- .../princess/PrincessSmtLibItpSolver.java | 54 +- .../princess/PrincessSmtLibSolverFactory.java | 24 +- .../PrincessSmtLibSolverInstaller.java | 58 +- .../SMTInterpolSmtLibItpMarker.java | 6 +- .../SMTInterpolSmtLibItpSolver.java | 63 +- .../SMTInterpolSmtLibSolverFactory.java | 31 +- .../SMTInterpolSmtLibSolverInstaller.java | 74 +- .../smtlib/impl/z3/Z3NewSmtLibItpSolver.java | 72 +- .../smtlib/impl/z3/Z3OldSmtLibItpSolver.java | 63 +- .../smtlib/impl/z3/Z3SmtLibItpMarker.java | 2 +- .../smtlib/impl/z3/Z3SmtLibSolverFactory.java | 19 +- .../impl/z3/Z3SmtLibSolverInstaller.java | 224 ++-- .../smtlib/solver/SmtLibEnumStrategy.java | 83 +- .../solver/smtlib/solver/SmtLibItpSolver.java | 63 +- .../solver/smtlib/solver/SmtLibSolver.java | 91 +- .../smtlib/solver/SmtLibSolverException.java | 2 +- .../solver/binary/SmtLibSolverBinary.java | 2 +- .../binary/SmtLibSolverBinaryException.java | 2 +- .../installer/SmtLibSolverInstaller.java | 91 +- .../SmtLibSolverInstallerException.java | 2 +- .../interpolation/SmtLibInterpolant.java | 8 +- .../solver/interpolation/SmtLibItpMarker.java | 7 +- .../interpolation/SmtLibItpPattern.java | 22 +- .../smtlib/solver/model/SmtLibModel.java | 2 +- .../smtlib/solver/model/SmtLibValuation.java | 14 +- .../solver/parser/CheckSatResponse.java | 13 +- .../smtlib/solver/parser/GeneralResponse.java | 50 +- .../solver/parser/GetModelResponse.java | 96 +- .../solver/parser/GetProofResponse.java | 31 +- .../solver/parser/GetUnsatCoreResponse.java | 10 +- .../solver/parser/SpecificResponse.java | 63 +- .../parser/ThrowExceptionErrorListener.java | 13 +- .../transformer/SmtLibDeclTransformer.java | 2 +- .../transformer/SmtLibExprTransformer.java | 2 +- .../solver/transformer/SmtLibSymbolTable.java | 2 +- .../transformer/SmtLibTermTransformer.java | 10 +- .../SmtLibTransformationManager.java | 2 +- .../transformer/SmtLibTypeTransformer.java | 2 +- .../theta/solver/smtlib/utils/Compress.java | 78 +- .../mit/theta/solver/smtlib/utils/SemVer.java | 27 +- .../smtlib/GenericSmtLibHornSolverTest.kt | 2 +- .../solver/smtlib/SmtLibItpSolverTest.java | 46 +- .../theta/solver/smtlib/SmtLibParserTest.java | 20 +- .../solver/smtlib/SmtLibSolverBVTest.java | 51 +- .../solver/smtlib/SmtLibSolverFPTest.java | 61 +- .../theta/solver/smtlib/SmtLibSolverTest.java | 187 +-- .../solver/solver-z3-legacy/build.gradle.kts | 2 +- .../solver/z3legacy/Z3DeclTransformer.java | 25 +- .../solver/z3legacy/Z3ExprTransformer.java | 726 ++++++------ .../theta/solver/z3legacy/Z3Interpolant.java | 6 +- .../theta/solver/z3legacy/Z3ItpMarker.java | 8 +- .../theta/solver/z3legacy/Z3ItpPattern.java | 24 +- .../theta/solver/z3legacy/Z3ItpSolver.java | 58 +- .../z3legacy/Z3LegacySolverFactory.java | 30 +- .../mit/theta/solver/z3legacy/Z3Solver.java | 44 +- .../solver/z3legacy/Z3SolverManager.java | 12 +- .../theta/solver/z3legacy/Z3SymbolTable.java | 15 +- .../solver/z3legacy/Z3TermTransformer.java | 2 +- .../z3legacy/Z3TransformationManager.java | 2 +- .../solver/z3legacy/Z3TypeTransformer.java | 33 +- .../theta/solver/z3legacy/package-info.java | 13 +- .../solver/z3legacy/SolverUtilsTest.java | 14 +- .../solver/z3legacy/Z3ItpSolverTest.java | 41 +- .../theta/solver/z3legacy/Z3ModelTest.java | 2 +- .../theta/solver/z3legacy/Z3SolverBVTest.java | 47 +- .../theta/solver/z3legacy/Z3SolverFPTest.java | 57 +- .../theta/solver/z3legacy/Z3SolverTest.java | 139 ++- subprojects/solver/solver-z3/build.gradle.kts | 2 +- .../theta/solver/z3/Z3DeclTransformer.java | 25 +- .../theta/solver/z3/Z3ExprTransformer.java | 677 +++++------ .../bme/mit/theta/solver/z3/Z3HornSolver.java | 60 +- .../mit/theta/solver/z3/Z3Interpolant.java | 6 +- .../bme/mit/theta/solver/z3/Z3ItpMarker.java | 8 +- .../bme/mit/theta/solver/z3/Z3ItpPattern.java | 24 +- .../bme/mit/theta/solver/z3/Z3ItpSolver.java | 101 +- .../hu/bme/mit/theta/solver/z3/Z3Solver.java | 2 +- .../mit/theta/solver/z3/Z3SolverFactory.java | 40 +- .../mit/theta/solver/z3/Z3SolverManager.java | 12 +- .../mit/theta/solver/z3/Z3SymbolTable.java | 8 +- .../theta/solver/z3/Z3TermTransformer.java | 253 ++-- .../solver/z3/Z3TransformationManager.java | 3 +- .../theta/solver/z3/Z3TypeTransformer.java | 33 +- .../bme/mit/theta/solver/z3/package-info.java | 13 +- .../mit/theta/solver/z3/SolverUtilsTest.java | 13 +- .../mit/theta/solver/z3/Z3HornSolverTest.kt | 2 +- .../mit/theta/solver/z3/Z3ItpSolverTest.java | 45 +- .../bme/mit/theta/solver/z3/Z3ModelTest.java | 7 +- .../mit/theta/solver/z3/Z3SolverBVTest.java | 43 +- .../mit/theta/solver/z3/Z3SolverFPTest.java | 57 +- .../bme/mit/theta/solver/z3/Z3SolverTest.java | 143 ++- subprojects/solver/solver/build.gradle.kts | 2 +- .../hu/bme/mit/theta/solver/HornSolver.java | 13 +- .../hu/bme/mit/theta/solver/Interpolant.java | 3 +- .../hu/bme/mit/theta/solver/ItpMarker.java | 6 +- .../bme/mit/theta/solver/ItpMarkerTree.java | 10 +- .../hu/bme/mit/theta/solver/ItpPattern.java | 21 +- .../hu/bme/mit/theta/solver/ItpSolver.java | 18 +- .../hu/bme/mit/theta/solver/ProofNode.java | 22 +- .../java/hu/bme/mit/theta/solver/Solver.java | 10 +- .../hu/bme/mit/theta/solver/SolverBase.java | 2 +- .../bme/mit/theta/solver/SolverFactory.java | 3 +- .../bme/mit/theta/solver/SolverManager.java | 7 +- .../hu/bme/mit/theta/solver/SolverPool.java | 24 +- .../hu/bme/mit/theta/solver/SolverStatus.java | 6 +- .../java/hu/bme/mit/theta/solver/Stack.java | 3 +- .../hu/bme/mit/theta/solver/UCSolver.java | 18 +- .../solver/UnknownSolverStatusException.java | 3 +- .../bme/mit/theta/solver/impl/NullSolver.java | 9 +- .../bme/mit/theta/solver/impl/StackImpl.java | 5 +- .../hu/bme/mit/theta/solver/package-info.java | 9 +- .../mit/theta/solver/utils/SolverUtils.java | 40 +- .../mit/theta/solver/utils/WithPushPop.java | 8 +- .../validator/ItpSolverValidatorWrapper.java | 8 +- .../validator/SolverValidationException.java | 3 +- .../validator/SolverValidatorWrapper.java | 11 +- .../SolverValidatorWrapperFactory.java | 3 +- .../validator/UCSolverValidatorWrapper.java | 8 +- .../hu/bme/mit/theta/solver/SolverStub.java | 5 +- .../hu/bme/mit/theta/solver/StackTest.java | 37 +- .../bme/mit/theta/solver/WithPushPopTest.java | 5 +- subprojects/sts/sts-analysis/build.gradle.kts | 2 +- .../bme/mit/theta/sts/analysis/StsAction.java | 10 +- .../hu/bme/mit/theta/sts/analysis/StsLts.java | 8 +- .../sts/analysis/StsTraceConcretizer.java | 17 +- .../theta/sts/analysis/config/StsConfig.java | 3 +- .../sts/analysis/config/StsConfigBuilder.java | 2 +- .../analysis/initprec/StsEmptyInitPrec.java | 7 +- .../sts/analysis/initprec/StsInitPrec.java | 14 +- .../analysis/initprec/StsPropInitPrec.java | 3 +- .../mit/theta/sts/analysis/package-info.java | 8 +- .../analysis/utils/StsTraceVisualizer.java | 17 +- .../theta/sts/analysis/StsToMonolithicExpr.kt | 9 +- .../mit/theta/sts/analysis/StsExplTest.java | 2 +- .../theta/sts/analysis/StsMddCheckerTest.java | 2 +- .../mit/theta/sts/analysis/StsPredTest.java | 2 +- .../bme/mit/theta/sts/analysis/StsTest.java | 69 +- subprojects/sts/sts-cli/build.gradle.kts | 2 +- .../java/hu/bme/mit/theta/sts/cli/StsCli.java | 2 +- subprojects/sts/sts/build.gradle.kts | 2 +- .../main/java/hu/bme/mit/theta/sts/STS.java | 46 +- .../java/hu/bme/mit/theta/sts/StsUtils.java | 9 +- .../bme/mit/theta/sts/aiger/AigerParser.java | 34 +- .../bme/mit/theta/sts/aiger/AigerToSts.java | 35 +- .../theta/sts/aiger/elements/AigerNode.java | 6 +- .../theta/sts/aiger/elements/AigerSystem.java | 7 +- .../theta/sts/aiger/elements/AigerWire.java | 7 +- .../mit/theta/sts/aiger/elements/AndGate.java | 10 +- .../theta/sts/aiger/elements/FalseConst.java | 6 +- .../theta/sts/aiger/elements/InputVar.java | 6 +- .../mit/theta/sts/aiger/elements/Latch.java | 6 +- .../theta/sts/aiger/elements/OutputVar.java | 6 +- .../sts/aiger/elements/package-info.java | 5 +- .../bme/mit/theta/sts/aiger/package-info.java | 5 +- .../mit/theta/sts/aiger/utils/AigerCoi.java | 26 +- .../theta/sts/aiger/utils/AigerConstProp.java | 37 +- .../sts/aiger/utils/AigerVisualizer.java | 18 +- .../theta/sts/aiger/utils/package-info.java | 9 +- .../bme/mit/theta/sts/dsl/PropDeclSymbol.java | 11 +- .../hu/bme/mit/theta/sts/dsl/StsCreator.java | 13 +- .../bme/mit/theta/sts/dsl/StsDeclSymbol.java | 19 +- .../hu/bme/mit/theta/sts/dsl/StsDefScope.java | 22 +- .../bme/mit/theta/sts/dsl/StsDslHelper.java | 59 +- .../bme/mit/theta/sts/dsl/StsDslManager.java | 25 +- .../theta/sts/dsl/StsExprCreatorVisitor.java | 92 +- .../hu/bme/mit/theta/sts/dsl/StsSpec.java | 15 +- .../bme/mit/theta/sts/dsl/StsSpecSymbol.java | 18 +- .../theta/sts/dsl/StsTypeCreatorVisitor.java | 10 +- .../bme/mit/theta/sts/dsl/package-info.java | 5 +- .../mit/theta/sts/parser/StsInterpreter.java | 14 +- .../bme/mit/theta/sts/parser/StsParser.java | 6 +- .../bme/mit/theta/sts/aiger/AigerCoiTest.java | 30 +- .../theta/sts/aiger/AigerConstPropTest.java | 38 +- .../hu/bme/mit/theta/sts/dsl/StsDslTest.java | 19 +- .../mit/theta/sts/parser/StsParserTest.java | 19 +- subprojects/xcfa/c2xcfa/build.gradle.kts | 2 +- .../java/hu/bme/mit/theta/c2xcfa/CMetaData.kt | 2 +- .../mit/theta/c2xcfa/FrontendXcfaBuilder.kt | 2 +- .../java/hu/bme/mit/theta/c2xcfa/Utils.kt | 2 +- .../hu/bme/mit/theta/c2xcfa/XcfaStatistics.kt | 2 +- .../theta/c2xcfa/TestFrontendXcfaBuilder.kt | 96 +- subprojects/xcfa/cat/build.gradle.kts | 3 +- .../bme/mit/theta/cat/dsl/CatDslManager.java | 14 +- .../hu/bme/mit/theta/cat/dsl/CatVisitor.kt | 2 +- .../cat/dsl/FileNameAntlrErrorListener.java | 21 +- .../hu/bme/mit/theta/xcfa/cat/ParseTest.java | 67 +- subprojects/xcfa/litmus2xcfa/build.gradle.kts | 4 +- .../litmus2xcfa/LitmusInterpreter.java | 12 +- .../litmus2xcfa/dsl/LitmusAArch64.java | 2 +- .../theta/fronted/litmus2xcfa/LitmusTest.java | 2 +- subprojects/xcfa/llvm2xcfa/build.gradle.kts | 2 +- .../mit/theta/llvm2xcfa/ArithmeticType.java | 5 +- .../mit/theta/llvm2xcfa/LlvmIrProvider.java | 81 +- .../bme/mit/theta/llvm2xcfa/LlvmMetadata.java | 2 +- .../bme/mit/theta/llvm2xcfa/SSAProvider.java | 12 +- .../hu/bme/mit/theta/llvm2xcfa/Utils.java | 2 +- .../hu/bme/mit/theta/llvm2xcfa/XcfaUtils.java | 131 ++- .../handlers/BaseInstructionHandler.java | 9 +- .../theta/llvm2xcfa/handlers/Instruction.java | 38 +- .../handlers/InstructionHandler.java | 10 +- .../handlers/InstructionHandlerManager.java | 65 +- .../handlers/arguments/Argument.java | 4 +- .../handlers/arguments/ConstantArgument.java | 8 +- .../handlers/arguments/LabelArgument.java | 4 +- .../handlers/arguments/LocalArgument.java | 3 +- .../handlers/arguments/RegArgument.java | 8 +- .../handlers/arguments/StringArgument.java | 4 +- .../concrete/AggregateInstructionHandler.java | 22 +- .../concrete/ArrayIntrinsicsHandler.java | 2 +- .../concrete/BinaryInstructionHandler.java | 183 ++- .../concrete/BitvectorInstructionHandler.java | 666 +++++++++-- .../concrete/BitwiseInstructionHandler.java | 93 +- .../concrete/BuiltinFunctionHandler.java | 44 +- .../ConversionInstructionHandler.java | 155 ++- .../concrete/MemoryInstructionHandler.java | 2 +- .../concrete/OtherInstructionHandler.java | 2 +- .../TerminatorInstructionHandler.java | 210 +++- .../concrete/UnaryInstructionHandler.java | 33 +- .../concrete/VectorInstructionHandler.java | 22 +- .../checks/PointerArithmeticCheck.java | 12 +- .../llvm2xcfa/handlers/states/BlockState.java | 3 +- .../llvm2xcfa/handlers/states/BuiltState.java | 8 +- .../handlers/states/FunctionState.java | 2 +- .../handlers/states/GlobalState.java | 17 +- .../utils/PlaceholderAssignmentStmt.java | 13 +- .../bme/mit/theta/llvm2xcfa/TestLlvm2Xcfa.kt | 130 +-- .../xcfa/xcfa-analysis/build.gradle.kts | 2 +- .../hu/bme/mit/theta/xcfa/analysis/Utils.kt | 2 +- .../bme/mit/theta/xcfa/analysis/XcfaAction.kt | 2 +- .../theta/xcfa/analysis/XcfaActionAdapter.kt | 58 +- .../mit/theta/xcfa/analysis/XcfaAnalysis.kt | 2 +- .../theta/xcfa/analysis/XcfaArgAbstractor.kt | 2 +- .../bme/mit/theta/xcfa/analysis/XcfaPrec.kt | 26 +- .../theta/xcfa/analysis/XcfaPrecRefiner.kt | 2 +- .../analysis/XcfaSingeExprTraceRefiner.kt | 2 +- .../bme/mit/theta/xcfa/analysis/XcfaState.kt | 2 +- .../theta/xcfa/analysis/XcfaStateAdapter.kt | 2 +- .../xcfa/analysis/XcfaToMonolithicExpr.kt | 2 +- .../mit/theta/xcfa/analysis/coi/XcfaCoi.kt | 277 +++-- .../xcfa/analysis/coi/XcfaCoiMultiThread.kt | 2 +- .../xcfa/analysis/coi/XcfaCoiSingleThread.kt | 104 +- .../mit/theta/xcfa/analysis/oc/XcfaExactPo.kt | 2 +- .../theta/xcfa/analysis/oc/XcfaOcChecker.kt | 2 +- .../analysis/oc/XcfaOcCorrectnessValidator.kt | 2 +- .../analysis/oc/XcfaOcPreConflictFinder.kt | 2 +- .../xcfa/analysis/oc/XcfaOcReasonParser.kt | 2 +- .../xcfa/analysis/oc/XcfaOcTraceExtractor.kt | 2 +- .../mit/theta/xcfa/analysis/oc/XcfaOcTypes.kt | 2 +- .../xcfa/analysis/por/AtomicNodePruner.java | 11 +- .../xcfa/analysis/por/ExtensionProperty.kt | 29 +- .../xcfa/analysis/por/XcfaAasporCoiLts.kt | 20 +- .../theta/xcfa/analysis/por/XcfaAasporLts.kt | 2 +- .../theta/xcfa/analysis/por/XcfaDporLts.kt | 2 +- .../theta/xcfa/analysis/por/XcfaSporCoiLts.kt | 35 +- .../theta/xcfa/analysis/por/XcfaSporLts.kt | 2 +- .../xcfa/analysis/XcfaExplAnalysisTest.kt | 2 +- .../xcfa/analysis/XcfaPredAnalysisTest.kt | 2 +- .../theta/xcfa/analysis/XcfaStateLtsTest.kt | 2 +- subprojects/xcfa/xcfa-cli/build.gradle.kts | 2 +- .../bme/mit/theta/xcfa/cli/ExecuteConfig.kt | 2 +- .../java/hu/bme/mit/theta/xcfa/cli/XcfaCli.kt | 2 +- .../cli/checkers/ConfigToBoundedChecker.kt | 2 +- .../xcfa/cli/checkers/ConfigToCegarChecker.kt | 2 +- .../xcfa/cli/checkers/ConfigToChecker.kt | 2 +- .../xcfa/cli/checkers/ConfigToHornChecker.kt | 2 +- .../xcfa/cli/checkers/ConfigToMddChecker.kt | 2 +- .../xcfa/cli/checkers/ConfigToOcChecker.kt | 2 +- .../xcfa/cli/checkers/ConfigToPortfolio.kt | 2 +- .../xcfa/cli/checkers/InProcessChecker.kt | 2 +- .../mit/theta/xcfa/cli/params/ExitCodes.kt | 129 +- .../mit/theta/xcfa/cli/params/ParamValues.kt | 2 +- .../mit/theta/xcfa/cli/params/TypeAdapters.kt | 252 ++-- .../mit/theta/xcfa/cli/params/Validators.kt | 9 +- .../mit/theta/xcfa/cli/params/XcfaConfig.kt | 2 +- .../mit/theta/xcfa/cli/portfolio/bounded24.kt | 2 +- .../mit/theta/xcfa/cli/portfolio/bounded25.kt | 2 +- .../mit/theta/xcfa/cli/portfolio/complex23.kt | 2 +- .../mit/theta/xcfa/cli/portfolio/complex24.kt | 2 +- .../mit/theta/xcfa/cli/portfolio/complex25.kt | 2 +- .../mit/theta/xcfa/cli/portfolio/horn25.kt | 2 +- .../bme/mit/theta/xcfa/cli/portfolio/stm.kt | 2 +- .../xcfa/cli/utils/CachingFileSerializer.kt | 44 +- .../xcfa/cli/utils/GraphmlWitnessWriter.kt | 2 +- .../bme/mit/theta/xcfa/cli/utils/GsonUtils.kt | 2 +- .../mit/theta/xcfa/cli/utils/PropertyUtils.kt | 2 +- .../xcfa/cli/utils/SolverRegistration.kt | 40 +- .../theta/xcfa/cli/utils/WitnessWriter.java | 68 +- .../cli/utils/XcfaDistToErrComparator.java | 34 +- .../mit/theta/xcfa/cli/utils/XcfaParser.kt | 2 +- .../theta/xcfa/cli/utils/YmlWitnessWriter.kt | 2 +- .../theta/xcfa/cli/witnesses/CommonWitness.kt | 2 +- .../xcfa/cli/witnesses/GraphmlWitness.kt | 2 +- .../xcfa/cli/witnesses/TraceToWitness.kt | 2 +- .../cli/witnesses/XcfaTraceConcretizer.java | 2 +- .../theta/xcfa/cli/witnesses/YamlWitness.kt | 2 +- .../mit/theta/xcfa/cli/XcfaCliParseTest.kt | 2 +- .../theta/xcfa/cli/XcfaCliPortfolioTest.kt | 2 +- .../mit/theta/xcfa/cli/XcfaCliProofTest.kt | 2 +- .../mit/theta/xcfa/cli/XcfaCliVerifyTest.kt | 2 +- .../hu/bme/mit/theta/xcfa/cli/XcfaDslTest.kt | 2 +- .../hu/bme/mit/theta/xcfa/cli/XcfaToCTest.kt | 2 +- .../bme/mit/theta/xcfa/cli/YamlParseTest.kt | 2 +- .../src/test/resources/dsl/async.xcfa.kts | 45 +- .../src/test/resources/dsl/sync.xcfa.kts | 35 +- .../xcfa-cli/src/test/resources/simple.kts | 2 +- subprojects/xcfa/xcfa/build.gradle.kts | 2 +- .../main/java/hu/bme/mit/theta/xcfa/Utils.kt | 2 +- .../java/hu/bme/mit/theta/xcfa/XcfaScope.kt | 44 +- .../java/hu/bme/mit/theta/xcfa/XcfaToC.kt | 2 +- .../xcfa/gson/FrontendMetadataAdapter.kt | 172 ++- .../mit/theta/xcfa/gson/MetaDataAdapter.kt | 40 +- .../theta/xcfa/gson/ParseContextAdapter.kt | 156 +-- .../hu/bme/mit/theta/xcfa/gson/XcfaAdapter.kt | 2 +- .../mit/theta/xcfa/gson/XcfaLabelAdapter.kt | 2 +- .../theta/xcfa/gson/XcfaLocationAdapter.kt | 2 +- .../hu/bme/mit/theta/xcfa/model/Builders.kt | 2 +- .../java/hu/bme/mit/theta/xcfa/model/Dsl.kt | 2 +- .../hu/bme/mit/theta/xcfa/model/MetaData.kt | 2 +- .../hu/bme/mit/theta/xcfa/model/PtrSize.kt | 2 +- .../hu/bme/mit/theta/xcfa/model/Visualizer.kt | 2 +- .../java/hu/bme/mit/theta/xcfa/model/XCFA.kt | 2 +- .../theta/xcfa/model/XcfaFurtherOptimizer.kt | 2 +- .../hu/bme/mit/theta/xcfa/model/XcfaLabel.kt | 2 +- .../xcfa/passes/AssumeFalseRemovalPass.kt | 2 +- .../xcfa/passes/AtomicReadsOneWritePass.kt | 2 +- .../xcfa/passes/CLibraryFunctionsPass.kt | 2 +- .../mit/theta/xcfa/passes/CallGraphPass.kt | 42 +- .../theta/xcfa/passes/DeterministicPass.kt | 36 +- .../theta/xcfa/passes/EliminateSelfLoops.kt | 2 +- .../theta/xcfa/passes/EmptyEdgeRemovalPass.kt | 2 +- .../theta/xcfa/passes/ErrorLocationPass.kt | 2 +- .../xcfa/passes/FetchExecuteWriteback.kt | 2 +- .../theta/xcfa/passes/FinalLocationPass.kt | 2 +- .../xcfa/passes/FpFunctionsToExprsPass.kt | 2 +- .../xcfa/passes/HavocPromotionAndRange.kt | 2 +- .../theta/xcfa/passes/InlineProceduresPass.kt | 2 +- .../hu/bme/mit/theta/xcfa/passes/LbePass.kt | 2 +- .../mit/theta/xcfa/passes/LoopUnrollPass.kt | 2 +- .../theta/xcfa/passes/MallocFunctionPass.kt | 2 +- .../mit/theta/xcfa/passes/MemsafetyPass.kt | 2 +- .../mit/theta/xcfa/passes/MutexToVarPass.kt | 2 +- .../mit/theta/xcfa/passes/NoSideEffectPass.kt | 2 +- .../theta/xcfa/passes/NondetFunctionPass.kt | 2 +- .../mit/theta/xcfa/passes/NormalizePass.kt | 2 +- .../mit/theta/xcfa/passes/ProcedurePass.kt | 7 +- .../theta/xcfa/passes/ProcedurePassManager.kt | 2 +- .../theta/xcfa/passes/ReferenceElimination.kt | 2 +- .../mit/theta/xcfa/passes/RemoveDeadEnds.kt | 2 +- .../theta/xcfa/passes/SimplifyExprsPass.kt | 150 +-- .../hu/bme/mit/theta/xcfa/passes/SsaPass.kt | 168 +-- .../mit/theta/xcfa/passes/StaticCoiPass.kt | 188 +-- .../theta/xcfa/passes/SvCompIntrinsicsPass.kt | 2 +- .../theta/xcfa/passes/UnusedLocRemovalPass.kt | 23 +- .../mit/theta/xcfa/passes/UnusedVarPass.kt | 2 +- .../hu/bme/mit/theta/xcfa/passes/Utils.kt | 2 +- .../hu/bme/mit/theta/xcfa/gson/GsonTest.kt | 2 +- .../bme/mit/theta/xcfa/model/XcfaDslTest.kt | 94 +- .../theta/xcfa/model/XcfaSerializationTest.kt | 82 +- .../hu/bme/mit/theta/xcfa/passes/PassTests.kt | 2 +- .../hu/bme/mit/theta/xcfa/passes/UtilsTest.kt | 2 +- subprojects/xcfa/xcfa2chc/build.gradle.kts | 2 +- .../hu/bme/mit/theta/xcfa2chc/Xcfa2Chc.kt | 100 +- .../hu/bme/mit/theta/xcfa2chc/TestChcUtils.kt | 2 +- .../xsts/xsts-analysis/build.gradle.kts | 2 +- .../mit/theta/xsts/analysis/XstsAction.java | 3 +- .../mit/theta/xsts/analysis/XstsAnalysis.java | 6 +- .../mit/theta/xsts/analysis/XstsInitFunc.java | 7 +- .../bme/mit/theta/xsts/analysis/XstsLts.java | 7 +- .../bme/mit/theta/xsts/analysis/XstsOrd.java | 6 +- .../mit/theta/xsts/analysis/XstsState.java | 18 +- .../xsts/analysis/XstsStatePredicate.java | 7 +- .../xsts/analysis/XstsStmtOptimizer.java | 4 +- .../theta/xsts/analysis/XstsTransFunc.java | 19 +- .../xsts/analysis/autoexpl/XstsAutoExpl.java | 3 +- .../autoexpl/XstsNewAtomsAutoExpl.java | 14 +- .../autoexpl/XstsNewOperandsAutoExpl.java | 38 +- .../analysis/autoexpl/XstsStaticAutoExpl.java | 2 +- .../xsts/analysis/concretizer/VarFilter.java | 4 +- .../concretizer/XstsStateSequence.java | 22 +- .../concretizer/XstsTraceConcretizerUtil.java | 33 +- .../xsts/analysis/config/XstsConfig.java | 5 +- .../analysis/config/XstsConfigBuilder.java | 2 +- .../initprec/XstsAllVarsInitPrec.java | 2 +- .../analysis/initprec/XstsCtrlInitPrec.java | 2 +- .../analysis/initprec/XstsEmptyInitPrec.java | 3 +- .../xsts/analysis/initprec/XstsInitPrec.java | 14 +- .../analysis/initprec/XstsPropInitPrec.java | 6 +- .../xsts/analysis/mdd/XstsMddChecker.java | 2 +- .../xsts/analysis/XstsToMonolithicExpr.kt | 40 +- .../theta/xsts/analysis/XstsToRelations.kt | 2 +- .../theta/xsts/analysis/XstsVarOrdering.kt | 2 +- .../theta/xsts/analysis/util/RandomXsts.kt | 2 +- .../analysis/util/XstsCombineExtractUtils.kt | 2 +- .../xsts/analysis/util/XstsControlInitFunc.kt | 7 +- .../xsts/analysis/util/XstsSerializer.kt | 4 +- .../xsts/analysis/XstsBfsMddCheckerTest.java | 6 +- .../xsts/analysis/XstsEnumSemanticsTest.java | 12 +- .../xsts/analysis/XstsGsatMddCheckerTest.java | 6 +- .../mit/theta/xsts/analysis/XstsHornTest.java | 2 +- .../xsts/analysis/XstsInitExprNodeTest.java | 33 +- .../xsts/analysis/XstsMddCheckerTest.java | 2 +- ...tsMddStructuralSymbolicComparisonTest.java | 98 +- .../xsts/analysis/XstsSatMddCheckerTest.java | 2 +- .../bme/mit/theta/xsts/analysis/XstsTest.java | 844 +++++++++----- .../mit/theta/xsts/analysis/util/ChcUtils.kt | 24 +- .../util/XstsCombineExtractUtilsUnitTest.kt | 45 +- .../util/XstsControlInitFuncUnitTest.kt | 37 +- subprojects/xsts/xsts-cli/build.gradle.kts | 2 +- .../mit/theta/xsts/cli/XstsCliBaseCommand.kt | 108 +- .../bme/mit/theta/xsts/cli/XstsCliBounded.kt | 2 +- .../hu/bme/mit/theta/xsts/cli/XstsCliCegar.kt | 2 +- .../hu/bme/mit/theta/xsts/cli/XstsCliChc.kt | 67 +- .../bme/mit/theta/xsts/cli/XstsCliHeader.kt | 163 +-- .../bme/mit/theta/xsts/cli/XstsCliLtlCegar.kt | 2 +- .../hu/bme/mit/theta/xsts/cli/XstsCliMain.kt | 2 +- .../hu/bme/mit/theta/xsts/cli/XstsCliMdd.kt | 2 +- .../bme/mit/theta/xsts/cli/XstsCliMetrics.kt | 82 +- .../mit/theta/xsts/cli/XstsCliPetrinetMdd.kt | 242 ++-- .../xsts/cli/optiongroup/InputOptions.kt | 60 +- .../xsts/cli/optiongroup/OutputOptions.kt | 30 +- .../PetrinetDependencyOutputOptions.kt | 29 +- subprojects/xsts/xsts/build.gradle.kts | 2 +- .../main/java/hu/bme/mit/theta/xsts/XSTS.java | 2 +- .../xsts/dsl/CustomTypeDeclarationUtil.java | 16 +- .../xsts/dsl/XstsCustomLiteralSymbol.java | 6 +- .../theta/xsts/dsl/XstsCustomTypeSymbol.java | 3 +- .../mit/theta/xsts/dsl/XstsDslManager.java | 14 +- .../mit/theta/xsts/dsl/XstsExpression.java | 157 +-- .../mit/theta/xsts/dsl/XstsSpecification.java | 2 +- .../bme/mit/theta/xsts/dsl/XstsStatement.java | 100 +- .../mit/theta/xsts/dsl/XstsTransitionSet.java | 25 +- .../hu/bme/mit/theta/xsts/dsl/XstsType.java | 22 +- .../theta/xsts/dsl/XstsVariableSymbol.java | 12 +- .../theta/xsts/passes/XstsNormalizerPass.kt | 2 +- .../hu/bme/mit/theta/xsts/passes/XstsPass.kt | 2 +- .../mit/theta/xsts/utils/XSTSVarChanger.kt | 2 +- .../xsts/utils/XSTSVarChangerUnitTest.kt | 55 +- subprojects/xta/xta-analysis/build.gradle.kts | 2 +- .../bme/mit/theta/xta/analysis/XtaAction.java | 214 ++-- .../mit/theta/xta/analysis/XtaAnalysis.java | 17 +- .../mit/theta/xta/analysis/XtaInitFunc.java | 14 +- .../hu/bme/mit/theta/xta/analysis/XtaLts.java | 86 +- .../hu/bme/mit/theta/xta/analysis/XtaOrd.java | 7 +- .../bme/mit/theta/xta/analysis/XtaState.java | 16 +- .../mit/theta/xta/analysis/XtaTransFunc.java | 20 +- .../xta/analysis/expl/XtaExplAnalysis.java | 5 +- .../xta/analysis/expl/XtaExplInitFunc.java | 10 +- .../xta/analysis/expl/XtaExplTransFunc.java | 10 +- .../theta/xta/analysis/expl/XtaExplUtils.java | 119 +- .../analysis/expl/itp/ItpExplAnalysis.java | 7 +- .../analysis/expl/itp/ItpExplInitFunc.java | 10 +- .../xta/analysis/expl/itp/ItpExplOrd.java | 6 +- .../xta/analysis/expl/itp/ItpExplState.java | 20 +- .../analysis/expl/itp/ItpExplTransFunc.java | 18 +- .../xta/analysis/lazy/AlgorithmStrategy.java | 25 +- .../xta/analysis/lazy/BwItpExplStrategy.java | 13 +- .../xta/analysis/lazy/BwItpZoneStrategy.java | 13 +- .../xta/analysis/lazy/ClockStrategies.java | 28 +- .../xta/analysis/lazy/ClockStrategy.java | 6 +- .../xta/analysis/lazy/CombinedStrategy.java | 68 +- .../xta/analysis/lazy/DataStrategies.java | 27 +- .../theta/xta/analysis/lazy/DataStrategy.java | 6 +- .../theta/xta/analysis/lazy/ExplStrategy.java | 28 +- .../xta/analysis/lazy/FwItpExplStrategy.java | 13 +- .../xta/analysis/lazy/FwItpZoneStrategy.java | 13 +- .../xta/analysis/lazy/ItpExplStrategy.java | 60 +- .../xta/analysis/lazy/ItpZoneStrategy.java | 58 +- .../xta/analysis/lazy/LazyXtaChecker.java | 67 +- .../analysis/lazy/LazyXtaCheckerFactory.java | 64 +- .../xta/analysis/lazy/LazyXtaStatistics.java | 17 +- .../bme/mit/theta/xta/analysis/lazy/Lens.java | 3 +- .../xta/analysis/lazy/LuZoneStrategy.java | 58 +- .../xta/analysis/zone/XtaActZoneUtils.java | 19 +- .../xta/analysis/zone/XtaLuZoneUtils.java | 25 +- .../xta/analysis/zone/XtaZoneAnalysis.java | 8 +- .../xta/analysis/zone/XtaZoneInitFunc.java | 11 +- .../xta/analysis/zone/XtaZoneTransFunc.java | 16 +- .../theta/xta/analysis/zone/XtaZoneUtils.java | 64 +- .../analysis/zone/itp/ItpZoneAnalysis.java | 9 +- .../analysis/zone/itp/ItpZoneInitFunc.java | 8 +- .../xta/analysis/zone/itp/ItpZoneOrd.java | 6 +- .../xta/analysis/zone/itp/ItpZoneState.java | 20 +- .../analysis/zone/itp/ItpZoneTransFunc.java | 17 +- .../xta/analysis/zone/lu/LuZoneAnalysis.java | 5 +- .../xta/analysis/zone/lu/LuZoneInitFunc.java | 8 +- .../theta/xta/analysis/zone/lu/LuZoneOrd.java | 6 +- .../xta/analysis/zone/lu/LuZoneState.java | 35 +- .../xta/analysis/zone/lu/LuZoneTransFunc.java | 18 +- .../xta/analysis/LazyXtaCheckerTest.java | 2 +- .../theta/xta/analysis/XtaAnalysisTest.java | 2 +- .../xta/analysis/XtaZoneAnalysisTest.java | 2 +- subprojects/xta/xta-cli/build.gradle.kts | 2 +- .../java/hu/bme/mit/theta/xta/cli/XtaCli.java | 2 +- subprojects/xta/xta/build.gradle.kts | 2 +- .../main/java/hu/bme/mit/theta/xta/Guard.java | 7 +- .../main/java/hu/bme/mit/theta/xta/Label.java | 15 +- .../main/java/hu/bme/mit/theta/xta/Sync.java | 28 +- .../java/hu/bme/mit/theta/xta/Update.java | 8 +- .../java/hu/bme/mit/theta/xta/XtaProcess.java | 39 +- .../java/hu/bme/mit/theta/xta/XtaSystem.java | 11 +- .../hu/bme/mit/theta/xta/XtaVisualizer.java | 98 +- .../bme/mit/theta/xta/dsl/XtaDslManager.java | 19 +- .../bme/mit/theta/xta/dsl/XtaExpression.java | 100 +- .../mit/theta/xta/dsl/XtaFunctionSymbol.java | 3 +- .../bme/mit/theta/xta/dsl/XtaInitialiser.java | 10 +- .../theta/xta/dsl/XtaInstantiationSymbol.java | 22 +- .../mit/theta/xta/dsl/XtaIteratorSymbol.java | 7 +- .../mit/theta/xta/dsl/XtaParameterSymbol.java | 14 +- .../mit/theta/xta/dsl/XtaProcessSymbol.java | 63 +- .../mit/theta/xta/dsl/XtaSpecification.java | 27 +- .../bme/mit/theta/xta/dsl/XtaStateSymbol.java | 23 +- .../hu/bme/mit/theta/xta/dsl/XtaSync.java | 11 +- .../bme/mit/theta/xta/dsl/XtaTransition.java | 16 +- .../hu/bme/mit/theta/xta/dsl/XtaType.java | 29 +- .../bme/mit/theta/xta/dsl/XtaTypeSymbol.java | 7 +- .../hu/bme/mit/theta/xta/dsl/XtaUpdate.java | 11 +- .../mit/theta/xta/dsl/XtaVariableSymbol.java | 49 +- .../hu/bme/mit/theta/xta/utils/ChanType.java | 5 +- .../hu/bme/mit/theta/xta/utils/ClockType.java | 5 +- .../hu/bme/mit/theta/xta/utils/LabelExpr.java | 14 +- .../hu/bme/mit/theta/xta/utils/RangeType.java | 8 +- .../mit/theta/xta/dsl/XtaDslManagerTest.java | 34 +- 1615 files changed, 23278 insertions(+), 20230 deletions(-) rename subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/{LoopcheckerSearchStrategy.kt => LoopCheckerSearchStrategy.kt} (90%) diff --git a/build.gradle.kts b/build.gradle.kts index 6dbea77c7d..6a99a2c3cf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 114d14bf7a..a2db555cf4 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties index 144d0ea9d7..9530ecaea2 100644 --- a/buildSrc/gradle.properties +++ b/buildSrc/gradle.properties @@ -1,5 +1,5 @@ # -# Copyright 2024 Budapest University of Technology and Economics +# Copyright 2025 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. diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index e9304fb0ab..6abf2ef91f 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 9c869af882..6618e45452 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/antlr-grammar.gradle.kts b/buildSrc/src/main/kotlin/antlr-grammar.gradle.kts index 2d6030f111..2606d3345e 100644 --- a/buildSrc/src/main/kotlin/antlr-grammar.gradle.kts +++ b/buildSrc/src/main/kotlin/antlr-grammar.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/cli-tool.gradle.kts b/buildSrc/src/main/kotlin/cli-tool.gradle.kts index 74335e814d..fbc27fd65d 100644 --- a/buildSrc/src/main/kotlin/cli-tool.gradle.kts +++ b/buildSrc/src/main/kotlin/cli-tool.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/jacoco-common.gradle.kts b/buildSrc/src/main/kotlin/jacoco-common.gradle.kts index 4f8c7b9522..6de4cc17ca 100644 --- a/buildSrc/src/main/kotlin/jacoco-common.gradle.kts +++ b/buildSrc/src/main/kotlin/jacoco-common.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/java-common.gradle.kts b/buildSrc/src/main/kotlin/java-common.gradle.kts index 838b4d4f41..15224651c8 100644 --- a/buildSrc/src/main/kotlin/java-common.gradle.kts +++ b/buildSrc/src/main/kotlin/java-common.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/kaml-serialization.gradle.kts b/buildSrc/src/main/kotlin/kaml-serialization.gradle.kts index b3e7da0b1c..c234488520 100644 --- a/buildSrc/src/main/kotlin/kaml-serialization.gradle.kts +++ b/buildSrc/src/main/kotlin/kaml-serialization.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,7 @@ import gradle.kotlin.dsl.accessors._07de9d51edfbede3e6fa517ade9dcf20.implementation /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/kotlin-common.gradle.kts b/buildSrc/src/main/kotlin/kotlin-common.gradle.kts index 59eef2f722..a1f8362ddb 100644 --- a/buildSrc/src/main/kotlin/kotlin-common.gradle.kts +++ b/buildSrc/src/main/kotlin/kotlin-common.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/maven-artifact.gradle.kts b/buildSrc/src/main/kotlin/maven-artifact.gradle.kts index 95ddb2d588..618d2823da 100644 --- a/buildSrc/src/main/kotlin/maven-artifact.gradle.kts +++ b/buildSrc/src/main/kotlin/maven-artifact.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/buildSrc/src/main/kotlin/tool-common.gradle.kts b/buildSrc/src/main/kotlin/tool-common.gradle.kts index 9e666b2a0c..0436d33b0d 100644 --- a/buildSrc/src/main/kotlin/tool-common.gradle.kts +++ b/buildSrc/src/main/kotlin/tool-common.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/gradle/shared-with-buildSrc/mirrors.gradle.kts b/gradle/shared-with-buildSrc/mirrors.gradle.kts index 2645019d84..f10ee7598e 100644 --- a/gradle/shared-with-buildSrc/mirrors.gradle.kts +++ b/gradle/shared-with-buildSrc/mirrors.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/scripts/complex.kts b/scripts/complex.kts index b90d3907cc..28363042e1 100644 --- a/scripts/complex.kts +++ b/scripts/complex.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/scripts/simple.kts b/scripts/simple.kts index 78c2678a13..46387fef9c 100644 --- a/scripts/simple.kts +++ b/scripts/simple.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/settings.gradle.kts b/settings.gradle.kts index b7711bbe31..f9024354e6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/build.gradle.kts b/subprojects/cfa/cfa-analysis/build.gradle.kts index 9dda88d6a8..87fac2048c 100644 --- a/subprojects/cfa/cfa-analysis/build.gradle.kts +++ b/subprojects/cfa/cfa-analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAction.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAction.java index 68aedd549f..939334028b 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAction.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.cfa.analysis; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expr.StmtAction; import hu.bme.mit.theta.cfa.CFA.Edge; import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.stmt.Stmt; - import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - public final class CfaAction extends StmtAction { private final List edges; @@ -39,8 +38,9 @@ private CfaAction(final Loc source, final Loc target, final List edges) { this.source = checkNotNull(source); this.target = checkNotNull(target); this.edges = Collections.unmodifiableList(checkNotNull(edges)); - this.stmts = Collections.unmodifiableList( - edges.stream().map(Edge::getStmt).collect(Collectors.toList())); + this.stmts = + Collections.unmodifiableList( + edges.stream().map(Edge::getStmt).collect(Collectors.toList())); } public static CfaAction create(final Edge edge) { diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAnalysis.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAnalysis.java index c62b8e6747..92a9dba4f5 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAnalysis.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expr.ExprState; @@ -32,8 +32,8 @@ public final class CfaAnalysis private final InitFunc, CfaPrec

> initFunc; private final TransFunc, CfaAction, CfaPrec

> transFunc; - private CfaAnalysis(final Loc initLoc, - final Analysis analysis) { + private CfaAnalysis( + final Loc initLoc, final Analysis analysis) { checkNotNull(initLoc); checkNotNull(analysis); partialOrd = CfaOrd.create(analysis.getPartialOrd()); @@ -41,8 +41,8 @@ private CfaAnalysis(final Loc initLoc, transFunc = CfaTransFunc.create(analysis.getTransFunc()); } - public static CfaAnalysis create(final Loc initLoc, - final Analysis analysis) { + public static CfaAnalysis create( + final Loc initLoc, final Analysis analysis) { return new CfaAnalysis<>(initLoc, analysis); } @@ -60,5 +60,4 @@ public InitFunc, CfaPrec

> getInitFunc() { public TransFunc, CfaAction, CfaPrec

> getTransFunc() { return transFunc; } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitFunc.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitFunc.java index ce5cf779e3..2ed47c214f 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitFunc.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.cfa.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.cfa.CFA.Loc; - import java.util.ArrayList; import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class CfaInitFunc implements - InitFunc, CfaPrec

> { +public final class CfaInitFunc + implements InitFunc, CfaPrec

> { private final Loc initLoc; private final InitFunc initFunc; @@ -36,8 +35,8 @@ private CfaInitFunc(final Loc initLoc, final InitFunc initFunc) { this.initFunc = checkNotNull(initFunc); } - public static CfaInitFunc create(final Loc initLoc, - final InitFunc initFunc) { + public static CfaInitFunc create( + final Loc initLoc, final InitFunc initFunc) { return new CfaInitFunc<>(initLoc, initFunc); } @@ -54,5 +53,4 @@ public Collection> getInitStates(final CfaPrec

prec) { } return initStates; } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitPrecs.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitPrecs.java index a4c0635d03..b755124120 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitPrecs.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaInitPrecs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,20 +20,17 @@ import hu.bme.mit.theta.cfa.analysis.prec.GlobalCfaPrec; import hu.bme.mit.theta.cfa.analysis.prec.LocalCfaPrec; import hu.bme.mit.theta.common.Utils; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.Map; import java.util.Set; public final class CfaInitPrecs { - private CfaInitPrecs() { - } + private CfaInitPrecs() {} public static LocalCfaPrec collectAssumesLocal(CFA cfa) { Map precs = Containers.createMap(); diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaOrd.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaOrd.java index 3bb3581d4d..e6c8622bd7 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaOrd.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -34,8 +34,7 @@ public static CfaOrd create(final PartialOrd partial @Override public boolean isLeq(final CfaState state1, final CfaState state2) { - return state1.getLoc().equals(state2.getLoc()) && partialOrd.isLeq(state1.getState(), - state2.getState()); + return state1.getLoc().equals(state2.getLoc()) + && partialOrd.isLeq(state1.getState(), state2.getState()); } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaPrec.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaPrec.java index aecae2f8ce..b4a77e5b90 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaPrec.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaState.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaState.java index bbc3de53ca..08349f4266 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaState.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.cfa.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static com.google.common.base.Preconditions.checkNotNull; - public final class CfaState implements ExprState { private static final int HASH_SEED = 3613; @@ -101,8 +101,10 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).add(loc.getName()).body() - .add(state).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .add(loc.getName()) + .body() + .add(state) + .toString(); } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTraceConcretizer.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTraceConcretizer.java index 50362a5ed4..ea9a658bf5 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTraceConcretizer.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTraceConcretizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,6 @@ import static com.google.common.base.Preconditions.checkArgument; -import java.util.ArrayList; -import java.util.List; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expl.ExplState; @@ -31,11 +28,12 @@ import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.booltype.BoolExprs; import hu.bme.mit.theta.solver.SolverFactory; +import java.util.ArrayList; +import java.util.List; public final class CfaTraceConcretizer { - private CfaTraceConcretizer() { - } + private CfaTraceConcretizer() {} public static Trace, CfaAction> concretize( final Trace, CfaAction> trace, SolverFactory solverFactory) { @@ -53,9 +51,9 @@ public static Trace, CfaAction> concretize( sbeStates.add(trace.getState(i + 1)); } Trace, CfaAction> sbeTrace = Trace.of(sbeStates, sbeActions); - final ExprTraceChecker checker = ExprTraceFwBinItpChecker.create( - BoolExprs.True(), - BoolExprs.True(), solverFactory.createItpSolver()); + final ExprTraceChecker checker = + ExprTraceFwBinItpChecker.create( + BoolExprs.True(), BoolExprs.True(), solverFactory.createItpSolver()); final ExprTraceStatus status = checker.check(sbeTrace); checkArgument(status.isFeasible(), "Infeasible trace."); final Trace valuations = status.asFeasible().getValuations(); @@ -65,7 +63,8 @@ public static Trace, CfaAction> concretize( final List> cfaStates = new ArrayList<>(); for (int i = 0; i < sbeTrace.getStates().size(); ++i) { cfaStates.add( - CfaState.of(sbeTrace.getState(i).getLoc(), ExplState.of(valuations.getState(i)))); + CfaState.of( + sbeTrace.getState(i).getLoc(), ExplState.of(valuations.getState(i)))); } return Trace.of(cfaStates, sbeTrace.getActions()); diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTransFunc.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTransFunc.java index 049931f011..e4d2ef428e 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTransFunc.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/CfaTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,16 +18,15 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; - import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.cfa.CFA.Loc; +import java.util.ArrayList; +import java.util.Collection; -final class CfaTransFunc implements - TransFunc, CfaAction, CfaPrec

> { +final class CfaTransFunc + implements TransFunc, CfaAction, CfaPrec

> { private final TransFunc transFunc; @@ -41,8 +40,8 @@ public static CfaTransFunc create( } @Override - public Collection> getSuccStates(final CfaState state, final CfaAction action, - final CfaPrec

prec) { + public Collection> getSuccStates( + final CfaState state, final CfaAction action, final CfaPrec

prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); @@ -56,13 +55,12 @@ public Collection> getSuccStates(final CfaState state, final CfaA final P subPrec = prec.getPrec(target); final S subState = state.getState(); - final Collection subSuccStates = transFunc.getSuccStates(subState, action, - subPrec); + final Collection subSuccStates = + transFunc.getSuccStates(subState, action, subPrec); for (final S subSuccState : subSuccStates) { final CfaState succState = CfaState.of(target, subSuccState); succStates.add(succState); } return succStates; } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/DistToErrComparator.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/DistToErrComparator.java index ffdc127294..ed43cd5db8 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/DistToErrComparator.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/DistToErrComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,6 @@ import static com.google.common.base.Preconditions.checkArgument; -import hu.bme.mit.theta.common.container.Containers; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -30,10 +24,12 @@ import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.CFA.Edge; import hu.bme.mit.theta.cfa.CFA.Loc; +import hu.bme.mit.theta.common.container.Containers; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; -/** - * A comparator for ArgNodes that is based on the distance from the error location. - */ +/** A comparator for ArgNodes that is based on the distance from the error location. */ public class DistToErrComparator implements ArgNodeComparator { private static final long serialVersionUID = -6915823336852930450L; @@ -48,8 +44,8 @@ public DistToErrComparator(final CFA cfa, final Loc errLoc) { this(cfa, errLoc, 1, 0); } - public DistToErrComparator(final CFA cfa, final Loc errLoc, final int errorWeight, - final int depthWeight) { + public DistToErrComparator( + final CFA cfa, final Loc errLoc, final int errorWeight, final int depthWeight) { this.cfa = cfa; this.errLoc = errLoc; this.errorWeight = errorWeight; @@ -58,8 +54,9 @@ public DistToErrComparator(final CFA cfa, final Loc errLoc, final int errorWeigh } @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { final int dist1 = getWeightedDistance(n1); final int dist2 = getWeightedDistance(n2); @@ -112,4 +109,4 @@ static Map calculateDistancesToError(final CFA cfa, final Loc errL public String toString() { return getClass().getSimpleName(); } -} \ No newline at end of file +} diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfig.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfig.java index 299bc4a494..134b927813 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfig.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -38,5 +38,4 @@ public static CfaConfig, Trace> check() { return checker.check(initPrec); } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfigBuilder.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfigBuilder.java index 37c30260ea..c44614291c 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfigBuilder.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/config/CfaConfigBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactChecker.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactChecker.java index 8aa315a5ab..6213e81d26 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactChecker.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,39 +17,41 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Optional; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.Trace; +import hu.bme.mit.theta.analysis.algorithm.SafetyChecker; import hu.bme.mit.theta.analysis.algorithm.SafetyResult; import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.analysis.algorithm.arg.ArgBuilder; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; import hu.bme.mit.theta.analysis.algorithm.arg.ArgTrace; -import hu.bme.mit.theta.analysis.algorithm.SafetyChecker; import hu.bme.mit.theta.analysis.reachedset.ReachedSet; import hu.bme.mit.theta.analysis.waitlist.FifoWaitlist; import hu.bme.mit.theta.analysis.waitlist.Waitlist; +import java.util.Optional; +import java.util.function.Function; -public final class ImpactChecker implements - SafetyChecker, Trace, P> { +public final class ImpactChecker + implements SafetyChecker, Trace, P> { private final ArgBuilder argBuilder; private final ImpactRefiner refiner; private final Function partitioning; - private ImpactChecker(final ArgBuilder argBuilder, final ImpactRefiner refiner, - final Function partitioning) { + private ImpactChecker( + final ArgBuilder argBuilder, + final ImpactRefiner refiner, + final Function partitioning) { this.argBuilder = checkNotNull(argBuilder); this.refiner = checkNotNull(refiner); this.partitioning = checkNotNull(partitioning); } public static ImpactChecker create( - final ArgBuilder argBuilder, final ImpactRefiner refiner, + final ArgBuilder argBuilder, + final ImpactRefiner refiner, final Function partitioning) { return new ImpactChecker<>(argBuilder, refiner, partitioning); } @@ -119,8 +121,8 @@ private Optional> unwind() { reachedSet.addAll(arg.getInitNodes()); while (true) { - final Optional> anyIncompleteNode = arg.getIncompleteNodes() - .findAny(); + final Optional> anyIncompleteNode = + arg.getIncompleteNodes().findAny(); if (anyIncompleteNode.isPresent()) { final ArgNode v = anyIncompleteNode.get(); @@ -168,6 +170,5 @@ private void refine(final ArgNode v) { } } } - } } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactReachedSet.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactReachedSet.java index 1324239d88..996b2bf9c8 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactReachedSet.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactReachedSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,23 +17,20 @@ import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.analysis.Action; +import hu.bme.mit.theta.analysis.State; +import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; +import hu.bme.mit.theta.analysis.reachedset.ReachedSet; +import hu.bme.mit.theta.common.container.Containers; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.List; import java.util.Map; import java.util.function.Function; -import hu.bme.mit.theta.analysis.Action; -import hu.bme.mit.theta.analysis.State; -import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; -import hu.bme.mit.theta.analysis.reachedset.ReachedSet; - -public final class ImpactReachedSet implements - ReachedSet { +public final class ImpactReachedSet + implements ReachedSet { private final Function partitioning; @@ -54,8 +51,8 @@ public void add(final ArgNode node) { checkNotNull(node); final S state = node.getState(); final K key = partitioning.apply(state); - final Collection> partition = partitions.computeIfAbsent(key, - k -> new ArrayList<>()); + final Collection> partition = + partitions.computeIfAbsent(key, k -> new ArrayList<>()); partition.add(node); } @@ -64,8 +61,8 @@ public void tryToCover(final ArgNode node) { checkNotNull(node); final S state = node.getState(); final K key = partitioning.apply(state); - final Collection> partition = partitions.getOrDefault(key, - Collections.emptyList()); + final Collection> partition = + partitions.getOrDefault(key, Collections.emptyList()); for (final ArgNode nodeToCoverWith : partition) { if (nodeToCoverWith.getId() < node.getId()) { if (nodeToCoverWith.mayCover(node)) { @@ -77,5 +74,4 @@ public void tryToCover(final ArgNode node) { } } } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactRefiner.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactRefiner.java index 9e59f58bc1..48776f4b7f 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactRefiner.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/ImpactRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,8 +27,7 @@ public interface ImpactRefiner { abstract class RefinementResult { - private RefinementResult() { - } + private RefinementResult() {} public static Succesful succesful( final Trace trace) { @@ -83,8 +82,7 @@ public Unsuccesful asUnsuccesful() { final class Unsuccesful extends RefinementResult { - private Unsuccesful() { - } + private Unsuccesful() {} @Override public boolean isSuccesful() { @@ -106,5 +104,4 @@ public Unsuccesful asUnsuccesful() { return this; } } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactChecker.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactChecker.java index 81882c1683..975a78b52b 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactChecker.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.cfa.analysis.impact; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static java.util.Collections.emptySet; + import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.LTS; import hu.bme.mit.theta.analysis.Trace; @@ -37,55 +41,64 @@ import hu.bme.mit.theta.cfa.analysis.prec.GlobalCfaPrec; import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.Solver; - import java.util.function.Predicate; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static java.util.Collections.emptySet; - -public final class PredImpactChecker implements SafetyChecker, CfaAction>, Trace, CfaAction>, UnitPrec> { +public final class PredImpactChecker + implements SafetyChecker< + ARG, CfaAction>, + Trace, CfaAction>, + UnitPrec> { private final ImpactChecker, CfaAction, UnitPrec> checker; - private PredImpactChecker(final LTS, CfaAction> lts, final Loc initLoc, - final Predicate targetLocs, - final Solver abstractionSolver, final ItpSolver refinementSolver) { + private PredImpactChecker( + final LTS, CfaAction> lts, + final Loc initLoc, + final Predicate targetLocs, + final Solver abstractionSolver, + final ItpSolver refinementSolver) { checkNotNull(lts); checkNotNull(initLoc); checkNotNull(abstractionSolver); checkNotNull(refinementSolver); - final Analysis predAnalysis = PredAnalysis.create(abstractionSolver, - PredAbstractors.booleanSplitAbstractor(abstractionSolver), True()); + final Analysis predAnalysis = + PredAnalysis.create( + abstractionSolver, + PredAbstractors.booleanSplitAbstractor(abstractionSolver), + True()); final CfaPrec fixedPrec = GlobalCfaPrec.create(PredPrec.of(emptySet())); - final Analysis, CfaAction, CfaPrec> cfaAnalysis = CfaAnalysis.create(initLoc, - predAnalysis); + final Analysis, CfaAction, CfaPrec> cfaAnalysis = + CfaAnalysis.create(initLoc, predAnalysis); - final Analysis, CfaAction, UnitPrec> analysis = PrecMappingAnalysis.create(cfaAnalysis, - np -> fixedPrec); + final Analysis, CfaAction, UnitPrec> analysis = + PrecMappingAnalysis.create(cfaAnalysis, np -> fixedPrec); final Predicate> target = s -> targetLocs.test(s.getLoc()); - final ArgBuilder, CfaAction, UnitPrec> argBuilder = ArgBuilder.create(lts, analysis, - target); + final ArgBuilder, CfaAction, UnitPrec> argBuilder = + ArgBuilder.create(lts, analysis, target); - final ImpactRefiner, CfaAction> refiner = PredImpactRefiner.create(refinementSolver); + final ImpactRefiner, CfaAction> refiner = + PredImpactRefiner.create(refinementSolver); checker = ImpactChecker.create(argBuilder, refiner, CfaState::getLoc); } - public static PredImpactChecker create(final LTS, CfaAction> lts, - final Loc initLoc, final Predicate targetLocs, - final Solver abstractionSolver, final ItpSolver refinementSolver) { + public static PredImpactChecker create( + final LTS, CfaAction> lts, + final Loc initLoc, + final Predicate targetLocs, + final Solver abstractionSolver, + final ItpSolver refinementSolver) { return new PredImpactChecker(lts, initLoc, targetLocs, abstractionSolver, refinementSolver); } @Override - public SafetyResult, CfaAction>, Trace, CfaAction>> check(final UnitPrec prec) { + public SafetyResult, CfaAction>, Trace, CfaAction>> + check(final UnitPrec prec) { return checker.check(prec); } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactRefiner.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactRefiner.java index d8bd980827..57bdb3749e 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactRefiner.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/impact/PredImpactRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,9 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import java.util.ArrayList; -import java.util.List; - import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.analysis.expr.ExprState; @@ -34,6 +31,8 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.ItpSolver; +import java.util.ArrayList; +import java.util.List; public final class PredImpactRefiner implements ImpactRefiner, CfaAction> { @@ -84,5 +83,4 @@ public RefinementResult, CfaAction> refine( throw new AssertionError(); } } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaCachedLts.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaCachedLts.java index b5da7f8c92..469642c97a 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaCachedLts.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaCachedLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,12 @@ */ package hu.bme.mit.theta.cfa.analysis.lts; -import java.util.Collection; - -import hu.bme.mit.theta.common.container.Containers; - -import java.util.Map; - import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.cfa.analysis.CfaAction; import hu.bme.mit.theta.cfa.analysis.CfaState; +import hu.bme.mit.theta.common.container.Containers; +import java.util.Collection; +import java.util.Map; /** * A caching layer over CFA LTS implementations. It only computes actions for each location once and @@ -47,5 +44,4 @@ public Collection getEnabledActionsFor(final CfaState state) { } return actionCache.get(loc); } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLbeLts.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLbeLts.java index 3d77393840..8394576a44 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLbeLts.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLbeLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.cfa.analysis.lts; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; +import static com.google.common.base.Preconditions.checkNotNull; import hu.bme.mit.theta.cfa.CFA.Edge; import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.cfa.analysis.CfaAction; import hu.bme.mit.theta.cfa.analysis.CfaState; import hu.bme.mit.theta.common.Utils; - -import static com.google.common.base.Preconditions.checkNotNull; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; /** * Large block encoding (LBE) implementation for CFA LTS. It maps each path (with no branching) into @@ -53,7 +52,8 @@ public Collection getEnabledActionsFor(final CfaState state) { final List edges = new LinkedList<>(); edges.add(edge); Loc running = edge.getTarget(); - while (running.getInEdges().size() == 1 && running.getOutEdges().size() == 1 + while (running.getInEdges().size() == 1 + && running.getOutEdges().size() == 1 && !running.equals(targetLoc)) { final Edge next = Utils.singleElementOf(running.getOutEdges()); edges.add(next); @@ -64,5 +64,4 @@ public Collection getEnabledActionsFor(final CfaState state) { return actions; } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLts.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLts.java index 381506fc3d..760cf28659 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLts.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,6 +19,4 @@ import hu.bme.mit.theta.cfa.analysis.CfaAction; import hu.bme.mit.theta.cfa.analysis.CfaState; -public interface CfaLts extends LTS, CfaAction> { - -} +public interface CfaLts extends LTS, CfaAction> {} diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaSbeLts.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaSbeLts.java index 7c28b180b4..5212ac5ee1 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaSbeLts.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/CfaSbeLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,13 @@ */ package hu.bme.mit.theta.cfa.analysis.lts; -import java.util.Collection; -import java.util.stream.Collectors; - import hu.bme.mit.theta.cfa.analysis.CfaAction; import hu.bme.mit.theta.cfa.analysis.CfaState; +import java.util.Collection; +import java.util.stream.Collectors; /** - * Single block encoding (SBE) implementation for CFA LTS. It returns a single CFA edges as - * actions. + * Single block encoding (SBE) implementation for CFA LTS. It returns a single CFA edges as actions. */ public final class CfaSbeLts implements CfaLts { @@ -32,8 +30,7 @@ private static final class LazyHolder { private static final CfaSbeLts INSTANCE = new CfaSbeLts(); } - private CfaSbeLts() { - } + private CfaSbeLts() {} public static CfaSbeLts getInstance() { return LazyHolder.INSTANCE; @@ -41,7 +38,8 @@ public static CfaSbeLts getInstance() { @Override public Collection getEnabledActionsFor(final CfaState state) { - return state.getLoc().getOutEdges().stream().map(CfaAction::create) + return state.getLoc().getOutEdges().stream() + .map(CfaAction::create) .collect(Collectors.toList()); } } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/package-info.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/package-info.java index ad9a12a765..3115c1aa09 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/package-info.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/lts/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ * @see hu.bme.mit.theta.cfa.analysis.lts.CfaSbeLts * @see hu.bme.mit.theta.cfa.analysis.lts.CfaCachedLts */ - -package hu.bme.mit.theta.cfa.analysis.lts; \ No newline at end of file +package hu.bme.mit.theta.cfa.analysis.lts; diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/package-info.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/package-info.java index 72e7fafcc5..73e37b2607 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/package-info.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,5 +17,4 @@ * This package contains the CFA specific analysis modules that can be plugged into the analysis * algorithms. Most of the modules work by extending existing modules with a location component. */ - -package hu.bme.mit.theta.cfa.analysis; \ No newline at end of file +package hu.bme.mit.theta.cfa.analysis; diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrec.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrec.java index 47cb6ab1d6..4fadea7d0c 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrec.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.cfa.analysis.prec; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.cfa.analysis.CfaPrec; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Represents an immutable global precision that maps the same precision to each location. A refiner * is also implemented. diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrecRefiner.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrecRefiner.java index 7d9b6e4f74..e639a88f9f 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrecRefiner.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/GlobalCfaPrecRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,7 +28,8 @@ import hu.bme.mit.theta.cfa.analysis.CfaPrec; import hu.bme.mit.theta.cfa.analysis.CfaState; -public final class GlobalCfaPrecRefiner +public final class GlobalCfaPrecRefiner< + S extends ExprState, A extends Action, P extends Prec, R extends Refutation> implements PrecRefiner, A, CfaPrec

, R> { private final RefutationToPrec refToPrec; @@ -37,14 +38,14 @@ private GlobalCfaPrecRefiner(final RefutationToPrec refToPrec) { this.refToPrec = checkNotNull(refToPrec); } - public static GlobalCfaPrecRefiner create( - final RefutationToPrec refToPrec) { + public static + GlobalCfaPrecRefiner create(final RefutationToPrec refToPrec) { return new GlobalCfaPrecRefiner<>(refToPrec); } @Override - public CfaPrec

refine(final CfaPrec

prec, final Trace, A> trace, - final R refutation) { + public CfaPrec

refine( + final CfaPrec

prec, final Trace, A> trace, final R refutation) { checkNotNull(trace); checkNotNull(prec); checkNotNull(refutation); @@ -64,5 +65,4 @@ public CfaPrec

refine(final CfaPrec

prec, final Trace, A> trac public String toString() { return getClass().getSimpleName(); } - } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrec.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrec.java index 55274df736..8f34d48592 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrec.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.cfa.analysis.prec; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Streams; @@ -25,7 +27,6 @@ import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -35,8 +36,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Represents an immutable local precision that can assign a precision to each location. A refiner * is also implemented. @@ -67,8 +66,8 @@ public static

LocalCfaPrec

create(final P defaultPrec) { return new LocalCfaPrec<>(Collections.emptyMap(), Optional.of(defaultPrec)); } - public static

LocalCfaPrec

create(final Map mapping, - final P defaultPrec) { + public static

LocalCfaPrec

create( + final Map mapping, final P defaultPrec) { return new LocalCfaPrec<>(mapping, Optional.of(defaultPrec)); } @@ -114,7 +113,11 @@ public String toString() { builder.add(Utils.lispStringBuilder("default").add(defaultPrec.get()).toString()); } mapping.entrySet() - .forEach(e -> builder.add(Utils.lispStringBuilder(e.getKey() + "").add(e.getValue()))); + .forEach( + e -> + builder.add( + Utils.lispStringBuilder(e.getKey() + "") + .add(e.getValue()))); return builder.toString(); } @@ -137,8 +140,12 @@ public int hashCode() { @Override public Collection> getUsedVars() { - return mapping.values().stream().map(Prec::getUsedVars).reduce( - (varDecls, varDecls2) -> Streams.concat(varDecls.stream(), varDecls2.stream()) - .collect(Collectors.toSet())).orElse(Set.of()); + return mapping.values().stream() + .map(Prec::getUsedVars) + .reduce( + (varDecls, varDecls2) -> + Streams.concat(varDecls.stream(), varDecls2.stream()) + .collect(Collectors.toSet())) + .orElse(Set.of()); } } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrecRefiner.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrecRefiner.java index e36e2b0479..f4dc911979 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrecRefiner.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/LocalCfaPrecRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,10 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import hu.bme.mit.theta.common.container.Containers; - -import java.util.Map; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.Trace; @@ -32,8 +28,11 @@ import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.cfa.analysis.CfaPrec; import hu.bme.mit.theta.cfa.analysis.CfaState; +import hu.bme.mit.theta.common.container.Containers; +import java.util.Map; -public final class LocalCfaPrecRefiner +public final class LocalCfaPrecRefiner< + S extends ExprState, A extends Action, P extends Prec, R extends Refutation> implements PrecRefiner, A, CfaPrec

, R> { private final RefutationToPrec refToPrec; @@ -42,14 +41,14 @@ private LocalCfaPrecRefiner(final RefutationToPrec refToPrec) { this.refToPrec = checkNotNull(refToPrec); } - public static LocalCfaPrecRefiner create( - final RefutationToPrec refToPrec) { + public static + LocalCfaPrecRefiner create(final RefutationToPrec refToPrec) { return new LocalCfaPrecRefiner<>(refToPrec); } @Override - public CfaPrec

refine(final CfaPrec

prec, final Trace, A> trace, - final R refutation) { + public CfaPrec

refine( + final CfaPrec

prec, final Trace, A> trace, final R refutation) { checkNotNull(trace); checkNotNull(prec); checkNotNull(refutation); diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrec.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrec.java index a99228f08b..c1fb1f76a8 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrec.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,7 +21,8 @@ import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.analysis.CfaPrec; -public class RefutationToGlobalCfaPrec

implements RefutationToPrec, R> { +public class RefutationToGlobalCfaPrec

+ implements RefutationToPrec, R> { private final RefutationToPrec refToPrec; private final CFA.Loc referenceLocation; @@ -39,6 +40,7 @@ public GlobalCfaPrec

toPrec(R refutation, int index) { @Override public GlobalCfaPrec

join(CfaPrec

prec1, CfaPrec

prec2) { - return GlobalCfaPrec.create(refToPrec.join(prec1.getPrec(referenceLocation), prec2.getPrec(referenceLocation))); + return GlobalCfaPrec.create( + refToPrec.join(prec1.getPrec(referenceLocation), prec2.getPrec(referenceLocation))); } } diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/package-info.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/package-info.java index 2cdb82737a..cc516f3bb5 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/package-info.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/prec/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ * @see hu.bme.mit.theta.cfa.analysis.prec.GlobalCfaPrec * @see hu.bme.mit.theta.cfa.analysis.prec.LocalCfaPrec */ - -package hu.bme.mit.theta.cfa.analysis.prec; \ No newline at end of file +package hu.bme.mit.theta.cfa.analysis.prec; diff --git a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/utils/CfaVisualizer.java b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/utils/CfaVisualizer.java index 87da3778b6..1a2b4a1e4a 100644 --- a/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/utils/CfaVisualizer.java +++ b/subprojects/cfa/cfa-analysis/src/main/java/hu/bme/mit/theta/cfa/analysis/utils/CfaVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtils.kt b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtils.kt index 2c8100578c..cc465c2332 100644 --- a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtils.kt +++ b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.cfa.analysis import hu.bme.mit.theta.analysis.Prec @@ -23,17 +22,17 @@ import hu.bme.mit.theta.analysis.unit.UnitState import hu.bme.mit.theta.cfa.analysis.prec.GlobalCfaPrec fun cfaCombineStates(cfaState: CfaState, dataState: S): CfaState { - return CfaState.of(cfaState.loc, dataState) + return CfaState.of(cfaState.loc, dataState) } fun cfaExtractControlState(cfaState: CfaState<*>): CfaState { - return CfaState.of(cfaState.loc, UnitState.getInstance()) + return CfaState.of(cfaState.loc, UnitState.getInstance()) } fun cfaExtractDataState(cfaState: CfaState): S { - return cfaState.state + return cfaState.state } fun cfaExtractControlPrec(p: CfaPrec): CfaPrec { - return GlobalCfaPrec.create(UnitPrec.getInstance()) -} \ No newline at end of file + return GlobalCfaPrec.create(UnitPrec.getInstance()) +} diff --git a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFunc.kt b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFunc.kt index 5bc1dd665f..f599823ab3 100644 --- a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFunc.kt +++ b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFunc.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.cfa.analysis import hu.bme.mit.theta.analysis.Prec import hu.bme.mit.theta.analysis.unit.UnitState import hu.bme.mit.theta.cfa.CFA -/** - * Used in a multianalysis to create initial location with no data state. - */ +/** Used in a multianalysis to create initial location with no data state. */ internal fun

cfaControlInitFunc(initLoc: CFA.Loc): CfaInitFunc { - return CfaInitFunc.create(initLoc) { _: P -> listOf(UnitState.getInstance()) } -} \ No newline at end of file + return CfaInitFunc.create(initLoc) { _: P -> listOf(UnitState.getInstance()) } +} diff --git a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaErrorlocPredicate.kt b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaErrorlocPredicate.kt index a1a782c2f2..6d5ba276de 100644 --- a/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaErrorlocPredicate.kt +++ b/subprojects/cfa/cfa-analysis/src/main/kotlin/hu/bme/mit/theta/cfa/analysis/CfaErrorlocPredicate.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,18 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.cfa.analysis import hu.bme.mit.theta.analysis.expr.ExprState import hu.bme.mit.theta.cfa.CFA import java.util.function.Predicate -/** - * Simple CFA location predicate for error locations - */ +/** Simple CFA location predicate for error locations */ class CfaErrorlocPredicate(private val errorLoc: CFA.Loc) : Predicate> { - override fun test(t: CfaState) = t.loc == this.errorLoc - -} \ No newline at end of file + override fun test(t: CfaState) = t.loc == this.errorLoc +} 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 37529a6bfc..74e15224fe 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaMddCheckerTest.java b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaMddCheckerTest.java index ca6abc822d..4b7d3b136e 100644 --- a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaMddCheckerTest.java +++ b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaMddCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaTest.java b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaTest.java index a996b3fc83..15397b3533 100644 --- a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaTest.java +++ b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/CfaTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,19 @@ */ package hu.bme.mit.theta.cfa.analysis; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.EXPL; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.PRED_BOOL; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.PRED_CART; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.BW_BIN_ITP; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.NWT_IT_WP; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.SEQ_ITP; +import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.UCB; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.algorithm.SafetyResult; -import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.analysis.config.CfaConfig; @@ -32,24 +39,15 @@ import hu.bme.mit.theta.solver.SolverManager; import hu.bme.mit.theta.solver.smtlib.SmtLibSolverManager; import hu.bme.mit.theta.solver.z3legacy.Z3SolverManager; +import java.io.FileInputStream; +import java.util.Arrays; +import java.util.Collection; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.io.FileInputStream; -import java.util.Arrays; -import java.util.Collection; - -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.EXPL; -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.PRED_BOOL; -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Domain.PRED_CART; -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.BW_BIN_ITP; -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.NWT_IT_WP; -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.SEQ_ITP; -import static hu.bme.mit.theta.cfa.analysis.config.CfaConfigBuilder.Refinement.UCB; - @RunWith(value = Parameterized.class) public class CfaTest { @@ -73,83 +71,123 @@ public class CfaTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}, {4}, {5}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"src/test/resources/arithmetic-bool00.cfa", PRED_CART, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool00.cfa", PRED_BOOL, BW_BIN_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool00.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool01.cfa", PRED_CART, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool01.cfa", PRED_BOOL, BW_BIN_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool01.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool10.cfa", PRED_BOOL, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool10.cfa", PRED_CART, BW_BIN_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool10.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool11.cfa", PRED_CART, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool11.cfa", PRED_BOOL, BW_BIN_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-bool11.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, - - {"src/test/resources/arithmetic-int.cfa", PRED_CART, SEQ_ITP, false, 13, "Z3"}, - - {"src/test/resources/arithmetic-int.cfa", PRED_BOOL, BW_BIN_ITP, false, 13, "Z3"}, - - {"src/test/resources/arithmetic-int.cfa", EXPL, SEQ_ITP, false, 13, "Z3"}, - - {"src/test/resources/arithmetic-mod.cfa", PRED_CART, SEQ_ITP, true, 0, "Z3"}, - - {"src/test/resources/arithmetic-mod.cfa", EXPL, BW_BIN_ITP, true, 0, "Z3"}, - - {"src/test/resources/arrays.cfa", PRED_CART, SEQ_ITP, false, 8, "Z3"}, - - {"src/test/resources/arrays.cfa", PRED_BOOL, BW_BIN_ITP, false, 8, "Z3"}, - - {"src/test/resources/arrayinit.cfa", PRED_CART, BW_BIN_ITP, false, 3, "Z3"}, - - {"src/test/resources/arrays.cfa", EXPL, SEQ_ITP, false, 8, "Z3"}, - - {"src/test/resources/counter5_true.cfa", PRED_BOOL, SEQ_ITP, true, 0, "Z3"}, - - {"src/test/resources/counter5_true.cfa", PRED_CART, BW_BIN_ITP, true, 0, "Z3"}, - - {"src/test/resources/counter5_true.cfa", EXPL, SEQ_ITP, true, 0, "Z3"}, - - {"src/test/resources/counter_bv_true.cfa", EXPL, NWT_IT_WP, true, 0, "Z3"}, - - {"src/test/resources/counter_bv_false.cfa", EXPL, NWT_IT_WP, false, 13, "Z3"}, - - {"src/test/resources/counter_bv_true.cfa", PRED_CART, NWT_IT_WP, true, 0, "Z3"}, - - {"src/test/resources/counter_bv_false.cfa", PRED_CART, UCB, false, 13, "Z3"}, - - {"src/test/resources/counter_bv_true.cfa", EXPL, SEQ_ITP, true, 0, "mathsat:latest"}, - - {"src/test/resources/counter_bv_false.cfa", EXPL, SEQ_ITP, false, 13, "mathsat:latest"}, - - {"src/test/resources/fp1.cfa", PRED_CART, NWT_IT_WP, true, 0, "Z3"}, - - {"src/test/resources/fp2.cfa", PRED_CART, NWT_IT_WP, false, 5, "Z3"}, - - {"src/test/resources/counter_fp_true.cfa", EXPL, NWT_IT_WP, true, 0, "Z3"}, - - {"src/test/resources/ifelse.cfa", PRED_CART, SEQ_ITP, false, 3, "Z3"}, - - {"src/test/resources/ifelse.cfa", PRED_BOOL, BW_BIN_ITP, false, 3, "Z3"}, - - {"src/test/resources/ifelse.cfa", EXPL, SEQ_ITP, false, 3, "Z3"}, - - {"src/test/resources/locking.cfa", PRED_CART, SEQ_ITP, true, 0, "Z3"}, - - }); + return Arrays.asList( + new Object[][] { + { + "src/test/resources/arithmetic-bool00.cfa", + PRED_CART, + SEQ_ITP, + false, + 15, + "Z3" + }, + { + "src/test/resources/arithmetic-bool00.cfa", + PRED_BOOL, + BW_BIN_ITP, + false, + 15, + "Z3" + }, + {"src/test/resources/arithmetic-bool00.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, + { + "src/test/resources/arithmetic-bool01.cfa", + PRED_CART, + SEQ_ITP, + false, + 15, + "Z3" + }, + { + "src/test/resources/arithmetic-bool01.cfa", + PRED_BOOL, + BW_BIN_ITP, + false, + 15, + "Z3" + }, + {"src/test/resources/arithmetic-bool01.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, + { + "src/test/resources/arithmetic-bool10.cfa", + PRED_BOOL, + SEQ_ITP, + false, + 15, + "Z3" + }, + { + "src/test/resources/arithmetic-bool10.cfa", + PRED_CART, + BW_BIN_ITP, + false, + 15, + "Z3" + }, + {"src/test/resources/arithmetic-bool10.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, + { + "src/test/resources/arithmetic-bool11.cfa", + PRED_CART, + SEQ_ITP, + false, + 15, + "Z3" + }, + { + "src/test/resources/arithmetic-bool11.cfa", + PRED_BOOL, + BW_BIN_ITP, + false, + 15, + "Z3" + }, + {"src/test/resources/arithmetic-bool11.cfa", EXPL, SEQ_ITP, false, 15, "Z3"}, + {"src/test/resources/arithmetic-int.cfa", PRED_CART, SEQ_ITP, false, 13, "Z3"}, + { + "src/test/resources/arithmetic-int.cfa", + PRED_BOOL, + BW_BIN_ITP, + false, + 13, + "Z3" + }, + {"src/test/resources/arithmetic-int.cfa", EXPL, SEQ_ITP, false, 13, "Z3"}, + {"src/test/resources/arithmetic-mod.cfa", PRED_CART, SEQ_ITP, true, 0, "Z3"}, + {"src/test/resources/arithmetic-mod.cfa", EXPL, BW_BIN_ITP, true, 0, "Z3"}, + {"src/test/resources/arrays.cfa", PRED_CART, SEQ_ITP, false, 8, "Z3"}, + {"src/test/resources/arrays.cfa", PRED_BOOL, BW_BIN_ITP, false, 8, "Z3"}, + {"src/test/resources/arrayinit.cfa", PRED_CART, BW_BIN_ITP, false, 3, "Z3"}, + {"src/test/resources/arrays.cfa", EXPL, SEQ_ITP, false, 8, "Z3"}, + {"src/test/resources/counter5_true.cfa", PRED_BOOL, SEQ_ITP, true, 0, "Z3"}, + {"src/test/resources/counter5_true.cfa", PRED_CART, BW_BIN_ITP, true, 0, "Z3"}, + {"src/test/resources/counter5_true.cfa", EXPL, SEQ_ITP, true, 0, "Z3"}, + {"src/test/resources/counter_bv_true.cfa", EXPL, NWT_IT_WP, true, 0, "Z3"}, + {"src/test/resources/counter_bv_false.cfa", EXPL, NWT_IT_WP, false, 13, "Z3"}, + {"src/test/resources/counter_bv_true.cfa", PRED_CART, NWT_IT_WP, true, 0, "Z3"}, + {"src/test/resources/counter_bv_false.cfa", PRED_CART, UCB, false, 13, "Z3"}, + { + "src/test/resources/counter_bv_true.cfa", + EXPL, + SEQ_ITP, + true, + 0, + "mathsat:latest" + }, + { + "src/test/resources/counter_bv_false.cfa", + EXPL, + SEQ_ITP, + false, + 13, + "mathsat:latest" + }, + {"src/test/resources/fp1.cfa", PRED_CART, NWT_IT_WP, true, 0, "Z3"}, + {"src/test/resources/fp2.cfa", PRED_CART, NWT_IT_WP, false, 5, "Z3"}, + {"src/test/resources/counter_fp_true.cfa", EXPL, NWT_IT_WP, true, 0, "Z3"}, + {"src/test/resources/ifelse.cfa", PRED_CART, SEQ_ITP, false, 3, "Z3"}, + {"src/test/resources/ifelse.cfa", PRED_BOOL, BW_BIN_ITP, false, 3, "Z3"}, + {"src/test/resources/ifelse.cfa", EXPL, SEQ_ITP, false, 3, "Z3"}, + {"src/test/resources/locking.cfa", PRED_CART, SEQ_ITP, true, 0, "Z3"}, + }); } @Test @@ -170,21 +208,20 @@ public void test() throws Exception { try { CFA cfa = CfaDslManager.createCfa(new FileInputStream(filePath)); - CfaConfig config - = new CfaConfigBuilder(domain, refinement, solverFactory).build(cfa, - cfa.getErrorLoc().get()); + CfaConfig config = + new CfaConfigBuilder(domain, refinement, solverFactory) + .build(cfa, cfa.getErrorLoc().get()); SafetyResult result = config.check(); Assert.assertEquals(isSafe, result.isSafe()); if (result.isUnsafe()) { - Trace, CfaAction> trace = CfaTraceConcretizer.concretize( - (Trace, CfaAction>) result.asUnsafe().getCex(), - solverFactory); + Trace, CfaAction> trace = + CfaTraceConcretizer.concretize( + (Trace, CfaAction>) result.asUnsafe().getCex(), + solverFactory); Assert.assertEquals(cexLength, trace.length()); } } finally { SolverManager.closeAll(); } } - - } diff --git a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/DistanceToErrorLocComparatorTest.java b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/DistanceToErrorLocComparatorTest.java index 05eb7b12c7..2109de42f7 100644 --- a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/DistanceToErrorLocComparatorTest.java +++ b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/DistanceToErrorLocComparatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,15 @@ */ package hu.bme.mit.theta.cfa.analysis; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.CFA.Builder; import hu.bme.mit.theta.cfa.CFA.Loc; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.stmt.Stmts; import hu.bme.mit.theta.core.type.booltype.BoolExprs; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; public class DistanceToErrorLocComparatorTest { @@ -49,8 +47,8 @@ public void test() { builder.createEdge(loc2, locFinal, stmt); final CFA cfa = builder.build(); - final Map distancesToError = DistToErrComparator.calculateDistancesToError( - cfa, cfa.getErrorLoc().get()); + final Map distancesToError = + DistToErrComparator.calculateDistancesToError(cfa, cfa.getErrorLoc().get()); Assert.assertEquals(0, (int) distancesToError.get(locErr)); Assert.assertEquals(2, (int) distancesToError.get(loc0)); diff --git a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/EncodingTest.java b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/EncodingTest.java index ecdff59d1b..906d357c48 100644 --- a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/EncodingTest.java +++ b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/EncodingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,18 +22,15 @@ import hu.bme.mit.theta.cfa.analysis.lts.CfaLts; import hu.bme.mit.theta.cfa.analysis.lts.CfaSbeLts; import hu.bme.mit.theta.cfa.dsl.CfaDslManager; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - import java.io.FileInputStream; import java.io.IOException; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.Set; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; public class EncodingTest { diff --git a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/LocPrecTest.java b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/LocPrecTest.java index 3c31d09e5e..26fbbdc6d8 100644 --- a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/LocPrecTest.java +++ b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/LocPrecTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,11 +22,10 @@ import hu.bme.mit.theta.cfa.analysis.prec.GlobalCfaPrec; import hu.bme.mit.theta.cfa.analysis.prec.LocalCfaPrec; import hu.bme.mit.theta.core.decl.VarDecl; -import org.junit.Assert; -import org.junit.Test; - import java.util.Collection; import java.util.Set; +import org.junit.Assert; +import org.junit.Test; public class LocPrecTest { @@ -121,6 +120,5 @@ public void testGenericLocPrecEquals2() { final LocalCfaPrec refinedBack = refined.refine(l1, p0); Assert.assertEquals(original, refinedBack); - } } diff --git a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/impact/CfaPredImpactCheckerTest.java b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/impact/CfaPredImpactCheckerTest.java index 111600967f..6eb136982a 100644 --- a/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/impact/CfaPredImpactCheckerTest.java +++ b/subprojects/cfa/cfa-analysis/src/test/java/hu/bme/mit/theta/cfa/analysis/impact/CfaPredImpactCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtilsUnitTest.kt b/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtilsUnitTest.kt index d637108f6d..f424b8d059 100644 --- a/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtilsUnitTest.kt +++ b/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaCombineExtractUtilsUnitTest.kt @@ -1,17 +1,18 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. + * 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.cfa.analysis import hu.bme.mit.theta.analysis.pred.PredState @@ -23,20 +24,19 @@ import org.junit.jupiter.api.Test class CfaCombineExtractUtilsUnitTest { - val dataState = PredState.of() - val loc = CFA.builder().createLoc() - val controlState = CfaState.of(loc, UnitState.getInstance()) - val cfaState = CfaState.of(loc, dataState) + val dataState = PredState.of() + val loc = CFA.builder().createLoc() + val controlState = CfaState.of(loc, UnitState.getInstance()) + val cfaState = CfaState.of(loc, dataState) - @Test - fun `Utils work as expected`() { - assert(cfaState == cfaCombineStates(controlState, dataState)) - assert(cfaExtractControlState(cfaState) == controlState) - assert(cfaExtractDataState(cfaState) == dataState) - assert( - cfaExtractControlPrec(GlobalCfaPrec.create(UnitPrec.getInstance())) == GlobalCfaPrec.create( - UnitPrec.getInstance() - ) - ) - } -} \ No newline at end of file + @Test + fun `Utils work as expected`() { + assert(cfaState == cfaCombineStates(controlState, dataState)) + assert(cfaExtractControlState(cfaState) == controlState) + assert(cfaExtractDataState(cfaState) == dataState) + assert( + cfaExtractControlPrec(GlobalCfaPrec.create(UnitPrec.getInstance())) == + GlobalCfaPrec.create(UnitPrec.getInstance()) + ) + } +} diff --git a/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFuncUnitTest.kt b/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFuncUnitTest.kt index f314ebf328..3d736ddc54 100644 --- a/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFuncUnitTest.kt +++ b/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/CfaControlInitFuncUnitTest.kt @@ -1,17 +1,18 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. + * 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.cfa.analysis import hu.bme.mit.theta.analysis.pred.PredPrec @@ -22,14 +23,12 @@ import org.junit.jupiter.api.Test class CfaControlInitFuncUnitTest { - @Test - fun `Init func should return 1 element UnitState set`() { - val cfaLoc = CFA.builder().createLoc() - val initFunc = cfaControlInitFunc(cfaLoc) - val initStates = initFunc.getInitStates(LocalCfaPrec.create(PredPrec.of())) - assert(initStates.size == 1) - assert(initStates.all { - it.state == UnitState.getInstance() - }) - } -} \ No newline at end of file + @Test + fun `Init func should return 1 element UnitState set`() { + val cfaLoc = CFA.builder().createLoc() + val initFunc = cfaControlInitFunc(cfaLoc) + val initStates = initFunc.getInitStates(LocalCfaPrec.create(PredPrec.of())) + assert(initStates.size == 1) + assert(initStates.all { it.state == UnitState.getInstance() }) + } +} diff --git a/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrecUnitTest.kt b/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrecUnitTest.kt index 0e88da9321..2ea563e907 100644 --- a/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrecUnitTest.kt +++ b/subprojects/cfa/cfa-analysis/src/test/kotlin/hu/bme/mit/theta/cfa/analysis/prec/RefutationToGlobalCfaPrecUnitTest.kt @@ -1,17 +1,18 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. + * 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.cfa.analysis.prec import hu.bme.mit.theta.analysis.expl.ExplPrec @@ -24,31 +25,31 @@ import org.junit.jupiter.api.Test class RefutationToGlobalCfaPrecUnitTest { - val refToPrec = ItpRefToExplPrec() - val loc = CFA.builder().createLoc()!! - val refToCfaPrec = RefutationToGlobalCfaPrec(refToPrec, loc) - val var1 = Decls.Var("b1", BoolType.getInstance()) - val var2 = Decls.Var("b2", BoolType.getInstance()) + val refToPrec = ItpRefToExplPrec() + val loc = CFA.builder().createLoc()!! + val refToCfaPrec = RefutationToGlobalCfaPrec(refToPrec, loc) + val var1 = Decls.Var("b1", BoolType.getInstance()) + val var2 = Decls.Var("b2", BoolType.getInstance()) - @Test - fun `Result precision simply contains what's in the refutation`() { - val refutation = ItpRefutation.sequence(listOf(var1.ref)) + @Test + fun `Result precision simply contains what's in the refutation`() { + val refutation = ItpRefutation.sequence(listOf(var1.ref)) - val result = refToCfaPrec.toPrec(refutation, 0) + val result = refToCfaPrec.toPrec(refutation, 0) - assert(result.prec.vars.size == 1) - assert(result.prec.vars.contains(var1)) - } + assert(result.prec.vars.size == 1) + assert(result.prec.vars.contains(var1)) + } - @Test - fun `Join should simply join the two expl precisions`() { - val prec1 = ExplPrec.of(listOf(var1)) - val prec2 = ExplPrec.of(listOf(var2)) - val cfaPrec1 = GlobalCfaPrec.create(prec1) - val cfaPrec2 = GlobalCfaPrec.create(prec2) + @Test + fun `Join should simply join the two expl precisions`() { + val prec1 = ExplPrec.of(listOf(var1)) + val prec2 = ExplPrec.of(listOf(var2)) + val cfaPrec1 = GlobalCfaPrec.create(prec1) + val cfaPrec2 = GlobalCfaPrec.create(prec2) - val result = refToCfaPrec.join(cfaPrec1, cfaPrec2) + val result = refToCfaPrec.join(cfaPrec1, cfaPrec2) - assert(result.prec.vars.contains(var1) && result.prec.vars.contains(var2)) - } -} \ No newline at end of file + assert(result.prec.vars.contains(var1) && result.prec.vars.contains(var2)) + } +} diff --git a/subprojects/cfa/cfa-cli/build.gradle.kts b/subprojects/cfa/cfa-cli/build.gradle.kts index bb62725072..a6061d6239 100644 --- a/subprojects/cfa/cfa-cli/build.gradle.kts +++ b/subprojects/cfa/cfa-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaCli.java b/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaCli.java index eda6c15702..2438e93338 100644 --- a/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaCli.java +++ b/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaCli.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaMetrics.java b/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaMetrics.java index 2f70a3a9f1..8f8cae7353 100644 --- a/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaMetrics.java +++ b/subprojects/cfa/cfa-cli/src/main/java/hu/bme/mit/theta/cfa/cli/CfaMetrics.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,6 +16,7 @@ package hu.bme.mit.theta.cfa.cli; import hu.bme.mit.theta.cfa.CFA; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.core.stmt.AssignStmt; import hu.bme.mit.theta.core.stmt.AssumeStmt; @@ -24,37 +25,49 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.bvtype.BvType; import hu.bme.mit.theta.core.type.inttype.IntType; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.LinkedList; import java.util.Queue; import java.util.Set; public final class CfaMetrics { - private CfaMetrics() { - } + private CfaMetrics() {} public static void printMetrics(Logger logger, CFA cfa) { logger.write(Logger.Level.RESULT, "Vars: %s%n", cfa.getVars().size()); - logger.write(Logger.Level.RESULT, " Bool vars: %s%n", + logger.write( + Logger.Level.RESULT, + " Bool vars: %s%n", cfa.getVars().stream().filter(v -> v.getType() instanceof BoolType).count()); - logger.write(Logger.Level.RESULT, " Int vars: %s%n", + logger.write( + Logger.Level.RESULT, + " Int vars: %s%n", cfa.getVars().stream().filter(v -> v.getType() instanceof IntType).count()); - logger.write(Logger.Level.RESULT, " Bitvector vars: %s%n", + logger.write( + Logger.Level.RESULT, + " Bitvector vars: %s%n", cfa.getVars().stream().filter(v -> v.getType() instanceof BvType).count()); - logger.write(Logger.Level.RESULT, " Array vars: %s%n", + logger.write( + Logger.Level.RESULT, + " Array vars: %s%n", cfa.getVars().stream().filter(v -> v.getType() instanceof ArrayType).count()); logger.write(Logger.Level.RESULT, "Locs: %s%n", cfa.getLocs().size()); logger.write(Logger.Level.RESULT, "Edges: %s%n", cfa.getEdges().size()); - logger.write(Logger.Level.RESULT, " Assignments: %s%n", + logger.write( + Logger.Level.RESULT, + " Assignments: %s%n", cfa.getEdges().stream().filter(e -> e.getStmt() instanceof AssignStmt).count()); - logger.write(Logger.Level.RESULT, " Assumptions: %s%n", + logger.write( + Logger.Level.RESULT, + " Assumptions: %s%n", cfa.getEdges().stream().filter(e -> e.getStmt() instanceof AssumeStmt).count()); - logger.write(Logger.Level.RESULT, " Havocs: %s%n", + logger.write( + Logger.Level.RESULT, + " Havocs: %s%n", cfa.getEdges().stream().filter(e -> e.getStmt() instanceof HavocStmt).count()); - logger.write(Logger.Level.RESULT, "Cyclomatic complexity: %s%n", + logger.write( + Logger.Level.RESULT, + "Cyclomatic complexity: %s%n", cfa.getEdges().size() - cfa.getLocs().size() + 2 * getCfaComponents(cfa)); } diff --git a/subprojects/cfa/cfa/build.gradle.kts b/subprojects/cfa/cfa/build.gradle.kts index 25854d3935..af5dd39f3f 100644 --- a/subprojects/cfa/cfa/build.gradle.kts +++ b/subprojects/cfa/cfa/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFA.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFA.java index ecd5e3fa90..80bdf66c79 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFA.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFA.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -276,7 +276,7 @@ public Edge createEdge(final Loc source, final Loc target, final Stmt stmt) { return edge; } - public void setAcceptingEdge(final Edge acceptingEdge) { + public void addAcceptingEdge(final Edge acceptingEdge) { checkNotBuilt(); checkNotNull(acceptingEdge); checkArgument(edges.contains(acceptingEdge), "Accepting edge not present in CFA."); diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFAVarChanger.kt b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFAVarChanger.kt index 5a58186c9a..e629e8381f 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFAVarChanger.kt +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/CFAVarChanger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaDslManager.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaDslManager.java index 642c6c4daf..e5ddcf289a 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaDslManager.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaDslManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,28 +15,25 @@ */ package hu.bme.mit.theta.cfa.dsl; +import hu.bme.mit.theta.cfa.CFA; +import hu.bme.mit.theta.cfa.dsl.gen.CfaDslLexer; +import hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser; +import hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser.SpecContext; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; - import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; -import hu.bme.mit.theta.cfa.CFA; -import hu.bme.mit.theta.cfa.dsl.gen.CfaDslLexer; -import hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser; -import hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser.SpecContext; - public final class CfaDslManager { - private CfaDslManager() { - } + private CfaDslManager() {} public static CFA createCfa(final String inputString) throws IOException { - final InputStream stream = new ByteArrayInputStream( - inputString.getBytes(StandardCharsets.UTF_8.name())); + final InputStream stream = + new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8.name())); return createCfa(stream); } @@ -52,5 +49,4 @@ public static CFA createCfa(final InputStream inputStream) throws IOException { final CFA cfa = specification.instantiate(); return cfa; } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaEdgeDefinition.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaEdgeDefinition.java index abcea7f237..6e5f2e4dfb 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaEdgeDefinition.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaEdgeDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,10 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.CFA.Edge; import hu.bme.mit.theta.cfa.CFA.Loc; @@ -29,6 +25,9 @@ import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.stmt.Stmts; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; final class CfaEdgeDefinition { @@ -55,8 +54,8 @@ public List instantiate(final CFA.Builder cfa, final Env env) { final Loc sourceLoc = (Loc) env.eval(sourceSymbol); final Loc targetLoc = (Loc) env.eval(targetSymbol); - final List stmts = statements.stream().map(s -> s.instantiate(env)) - .collect(Collectors.toList()); + final List stmts = + statements.stream().map(s -> s.instantiate(env)).collect(Collectors.toList()); if (stmts.isEmpty()) { stmts.add(Stmts.Skip()); } @@ -85,5 +84,4 @@ private List createStatements(final List stmtContexts } return result; } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaExpression.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaExpression.java index 0a9020d62c..cac8b45802 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaExpression.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,63 +15,6 @@ */ package hu.bme.mit.theta.cfa.dsl; -import com.google.common.collect.ImmutableList; -import hu.bme.mit.theta.cfa.dsl.gen.CfaDslBaseVisitor; -import hu.bme.mit.theta.common.Tuple2; -import hu.bme.mit.theta.common.dsl.BasicScope; -import hu.bme.mit.theta.common.dsl.Env; -import hu.bme.mit.theta.common.dsl.Scope; -import hu.bme.mit.theta.common.dsl.Symbol; -import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.decl.ParamDecl; -import hu.bme.mit.theta.core.dsl.DeclSymbol; -import hu.bme.mit.theta.core.dsl.ParseException; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.abstracttype.AddExpr; -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.abstracttype.MulExpr; -import hu.bme.mit.theta.core.type.abstracttype.RemExpr; -import hu.bme.mit.theta.core.type.abstracttype.SubExpr; -import hu.bme.mit.theta.core.type.anytype.RefExpr; -import hu.bme.mit.theta.core.type.arraytype.ArrayType; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.booltype.FalseExpr; -import hu.bme.mit.theta.core.type.booltype.TrueExpr; -import hu.bme.mit.theta.core.type.bvtype.BvAddExpr; -import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr; -import hu.bme.mit.theta.core.type.bvtype.BvExprs; -import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; -import hu.bme.mit.theta.core.type.bvtype.BvMulExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSModExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSubExpr; -import hu.bme.mit.theta.core.type.bvtype.BvType; -import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr; -import hu.bme.mit.theta.core.type.bvtype.BvURemExpr; -import hu.bme.mit.theta.core.type.fptype.FpExprs; -import hu.bme.mit.theta.core.type.fptype.FpLitExpr; -import hu.bme.mit.theta.core.type.fptype.FpRoundingMode; -import hu.bme.mit.theta.core.type.fptype.FpType; -import hu.bme.mit.theta.core.type.functype.FuncExprs; -import hu.bme.mit.theta.core.type.inttype.IntLitExpr; -import hu.bme.mit.theta.core.type.rattype.RatLitExpr; -import org.antlr.v4.runtime.Token; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -131,6 +74,62 @@ import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; import static java.util.stream.Collectors.toList; +import com.google.common.collect.ImmutableList; +import hu.bme.mit.theta.cfa.dsl.gen.CfaDslBaseVisitor; +import hu.bme.mit.theta.common.Tuple2; +import hu.bme.mit.theta.common.dsl.BasicScope; +import hu.bme.mit.theta.common.dsl.Env; +import hu.bme.mit.theta.common.dsl.Scope; +import hu.bme.mit.theta.common.dsl.Symbol; +import hu.bme.mit.theta.core.decl.Decl; +import hu.bme.mit.theta.core.decl.ParamDecl; +import hu.bme.mit.theta.core.dsl.DeclSymbol; +import hu.bme.mit.theta.core.dsl.ParseException; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.abstracttype.AddExpr; +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.abstracttype.MulExpr; +import hu.bme.mit.theta.core.type.abstracttype.RemExpr; +import hu.bme.mit.theta.core.type.abstracttype.SubExpr; +import hu.bme.mit.theta.core.type.anytype.RefExpr; +import hu.bme.mit.theta.core.type.arraytype.ArrayType; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.booltype.FalseExpr; +import hu.bme.mit.theta.core.type.booltype.TrueExpr; +import hu.bme.mit.theta.core.type.bvtype.BvAddExpr; +import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr; +import hu.bme.mit.theta.core.type.bvtype.BvExprs; +import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; +import hu.bme.mit.theta.core.type.bvtype.BvMulExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSModExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSubExpr; +import hu.bme.mit.theta.core.type.bvtype.BvType; +import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr; +import hu.bme.mit.theta.core.type.bvtype.BvURemExpr; +import hu.bme.mit.theta.core.type.fptype.FpExprs; +import hu.bme.mit.theta.core.type.fptype.FpLitExpr; +import hu.bme.mit.theta.core.type.fptype.FpRoundingMode; +import hu.bme.mit.theta.core.type.fptype.FpType; +import hu.bme.mit.theta.core.type.functype.FuncExprs; +import hu.bme.mit.theta.core.type.inttype.IntLitExpr; +import hu.bme.mit.theta.core.type.rattype.RatLitExpr; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import org.antlr.v4.runtime.Token; + final class CfaExpression { private final Scope scope; @@ -175,8 +174,8 @@ private void push(final List> paramDecls) { } private void pop() { - checkState(currentScope.enclosingScope().isPresent(), - "Enclosing scope is not present."); + checkState( + currentScope.enclosingScope().isPresent(), "Enclosing scope is not present."); currentScope = currentScope.enclosingScope().get(); env.pop(); } @@ -189,13 +188,13 @@ public Expr visitFuncLitExpr(final FuncLitExprContext ctx) { final List> params = createParamList(ctx.paramDecls); checkArgument(params.size() == 1); - @SuppressWarnings("unchecked") final ParamDecl param = (ParamDecl) singleElementOf( - params); + @SuppressWarnings("unchecked") + final ParamDecl param = (ParamDecl) singleElementOf(params); push(params); - @SuppressWarnings("unchecked") final Expr result = (Expr) ctx.result.accept( - this); + @SuppressWarnings("unchecked") + final Expr result = (Expr) ctx.result.accept(this); pop(); @@ -210,9 +209,14 @@ private List> createParamList(final DeclListContext ctx) { if (ctx.decls == null) { return Collections.emptyList(); } else { - final List> paramDecls = ctx.decls.stream() - .map(d -> Param(d.name.getText(), new CfaType(d.ttype).instantiate())) - .collect(toList()); + final List> paramDecls = + ctx.decls.stream() + .map( + d -> + Param( + d.name.getText(), + new CfaType(d.ttype).instantiate())) + .collect(toList()); return paramDecls; } } @@ -286,8 +290,8 @@ public Expr visitExistsExpr(final ExistsExprContext ctx) { @Override public Expr visitOrExpr(final OrExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return Or(ops); } else { @@ -309,8 +313,8 @@ public Expr visitXorExpr(final XorExprContext ctx) { @Override public Expr visitAndExpr(final AndExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return And(ops); } else { @@ -508,9 +512,11 @@ public Expr visitAdditiveExpr(final AdditiveExprContext ctx) { } } - private Expr createAdditiveExpr(final Expr opsHead, - final List> opsTail, - final List opers, final AdditiveExprContext ctx) { + private Expr createAdditiveExpr( + final Expr opsHead, + final List> opsTail, + final List opers, + final AdditiveExprContext ctx) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -528,11 +534,12 @@ private Expr createAdditiveExpr(final Expr opsHead, } } - private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper, - final AdditiveExprContext ctx) { + private Expr createAdditiveSubExpr( + final Expr leftOp, + final Expr rightOp, + final Token oper, + final AdditiveExprContext ctx) { switch (oper.getType()) { - case PLUS: return createAddExpr(leftOp, rightOp); @@ -546,12 +553,13 @@ private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightO return createBvSubExpr(castBv(leftOp), castBv(rightOp)); case FPADD: - return FpExprs.Add(getRoundingMode(oper.getText()), + return FpExprs.Add( + getRoundingMode(oper.getText()), List.of(castFp(leftOp), castFp(rightOp))); case FPSUB: - return FpExprs.Sub(getRoundingMode(oper.getText()), castFp(leftOp), - castFp(rightOp)); + return FpExprs.Sub( + getRoundingMode(oper.getText()), castFp(leftOp), castFp(rightOp)); default: throw new ParseException(ctx, "Unknown operator '" + oper.getText() + "'"); @@ -561,9 +569,11 @@ private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightO private AddExpr createAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof AddExpr) { final AddExpr addLeftOp = (AddExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Add(ops); } else { return Add(leftOp, rightOp); @@ -577,9 +587,11 @@ private SubExpr createSubExpr(final Expr leftOp, final Expr rightOp) { private BvAddExpr createBvAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof BvAddExpr) { final BvAddExpr addLeftOp = (BvAddExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return BvExprs.Add(ops); } else { return BvExprs.Add(Arrays.asList(leftOp, rightOp)); @@ -605,12 +617,13 @@ public Expr visitMultiplicativeExpr(final MultiplicativeExprContext ctx) { } else { return visitChildren(ctx); } - } - private Expr createMutliplicativeExpr(final Expr opsHead, - final List> opsTail, - final List opers, final MultiplicativeExprContext ctx) { + private Expr createMutliplicativeExpr( + final Expr opsHead, + final List> opsTail, + final List opers, + final MultiplicativeExprContext ctx) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -622,19 +635,20 @@ private Expr createMutliplicativeExpr(final Expr opsHead, final Token operHead = opers.get(0); final List opersTail = opers.subList(1, opers.size()); - final Expr subExpr = createMultiplicativeSubExpr(opsHead, newOpsHead, operHead, - ctx); + final Expr subExpr = + createMultiplicativeSubExpr(opsHead, newOpsHead, operHead, ctx); return createMutliplicativeExpr(subExpr, newOpsTail, opersTail, ctx); } } @SuppressWarnings("unchecked") - private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper, - final MultiplicativeExprContext ctx) { + private Expr createMultiplicativeSubExpr( + final Expr leftOp, + final Expr rightOp, + final Token oper, + final MultiplicativeExprContext ctx) { switch (oper.getType()) { - case MUL: return createMulExpr(leftOp, rightOp); @@ -669,11 +683,14 @@ private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr return FpExprs.Rem((Expr) leftOp, (Expr) rightOp); case FPMUL: - return FpExprs.Mul(getRoundingMode(oper.getText()), + return FpExprs.Mul( + getRoundingMode(oper.getText()), List.of((Expr) leftOp, (Expr) rightOp)); case FPDIV: - return FpExprs.Div(getRoundingMode(oper.getText()), (Expr) leftOp, + return FpExprs.Div( + getRoundingMode(oper.getText()), + (Expr) leftOp, (Expr) rightOp); default: @@ -684,9 +701,11 @@ private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof MulExpr) { final MulExpr addLeftOp = (MulExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Mul(ops); } else { return Mul(leftOp, rightOp); @@ -696,9 +715,11 @@ private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { private BvMulExpr createBvMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof BvMulExpr) { final BvMulExpr addLeftOp = (BvMulExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return BvExprs.Mul(ops); } else { return BvExprs.Mul(Arrays.asList(leftOp, rightOp)); @@ -754,9 +775,10 @@ public Expr visitBvConcatExpr(final BvConcatExprContext ctx) { } } - private Expr createConcatExpr(final Expr opsHead, - final List> opsTail, - final List opers) { + private Expr createConcatExpr( + final Expr opsHead, + final List> opsTail, + final List opers) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -774,8 +796,8 @@ private Expr createConcatExpr(final Expr opsHead, } } - private Expr createConcatSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper) { + private Expr createConcatSubExpr( + final Expr leftOp, final Expr rightOp, final Token oper) { switch (oper.getType()) { case BV_CONCAT: return createBvConcatExpr(castBv(leftOp), castBv(rightOp)); @@ -785,13 +807,15 @@ private Expr createConcatSubExpr(final Expr leftOp, final Expr rightOp, } } - private BvConcatExpr createBvConcatExpr(final Expr leftOp, - final Expr rightOp) { + private BvConcatExpr createBvConcatExpr( + final Expr leftOp, final Expr rightOp) { if (leftOp instanceof BvConcatExpr) { final BvConcatExpr addLeftOp = (BvConcatExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return BvExprs.Concat(ops); } else { return BvExprs.Concat(Arrays.asList(leftOp, rightOp)); @@ -801,8 +825,8 @@ private BvConcatExpr createBvConcatExpr(final Expr leftOp, @Override public Expr visitBvExtendExpr(final BvExtendExprContext ctx) { if (ctx.rightOp != null) { - final BvType extendType = BvExprs.BvType( - Integer.parseInt(ctx.rightOp.size.getText())); + final BvType extendType = + BvExprs.BvType(Integer.parseInt(ctx.rightOp.size.getText())); switch (ctx.oper.getType()) { case BV_ZERO_EXTEND: @@ -840,23 +864,32 @@ public Expr visitUnaryExpr(final UnaryExprContext ctx) { return IsNan((Expr) op); case FPROUNDTOINT: - return RoundToIntegral(getRoundingMode(ctx.oper.getText()), - (Expr) op); + return RoundToIntegral( + getRoundingMode(ctx.oper.getText()), (Expr) op); case FPSQRT: return Sqrt(getRoundingMode(ctx.oper.getText()), (Expr) op); case FPTOFP: - return ToFp(getRoundingMode(ctx.oper.getText()), (Expr) op, - getExp(ctx.oper.getText()), getSignificand(ctx.oper.getText())); + return ToFp( + getRoundingMode(ctx.oper.getText()), + (Expr) op, + getExp(ctx.oper.getText()), + getSignificand(ctx.oper.getText())); case FPTOBV: - return ToBv(getRoundingMode(ctx.oper.getText()), (Expr) op, - getBvSize(ctx.oper.getText()), isSignedBv(ctx.oper.getText())); + return ToBv( + getRoundingMode(ctx.oper.getText()), + (Expr) op, + getBvSize(ctx.oper.getText()), + isSignedBv(ctx.oper.getText())); case FP_FROM_BV: - return FromBv(getRoundingMode(ctx.oper.getText()), (Expr) op, - FpType.of(getExp(ctx.oper.getText()), + return FromBv( + getRoundingMode(ctx.oper.getText()), + (Expr) op, + FpType.of( + getExp(ctx.oper.getText()), getSignificand(ctx.oper.getText())), isSignedFp(ctx.oper.getText())); @@ -882,7 +915,6 @@ private boolean isSignedFp(String text) { } else { return false; } - } private boolean isSignedBv(String text) { @@ -934,7 +966,6 @@ private FpRoundingMode getRoundingMode(String text) { } else { return FpRoundingMode.getDefaultRoundingMode(); } - } @Override @@ -990,18 +1021,20 @@ private Expr createFuncAppExpr(final Expr op, final FuncAccessContext ctx) throw new UnsupportedOperationException("TODO: auto-generated method stub"); } - private Expr createArrayReadExpr(final Expr op, - final ArrayReadAccessContext ctx) { + private Expr createArrayReadExpr( + final Expr op, final ArrayReadAccessContext ctx) { checkArgument(op.getType() instanceof ArrayType); - @SuppressWarnings("unchecked") final Expr> array = (Expr>) op; + @SuppressWarnings("unchecked") + final Expr> array = (Expr>) op; final Expr index = cast(ctx.index.accept(this), array.getType().getIndexType()); return Read(array, index); } - private Expr createArrayWriteExpr(final Expr op, - final ArrayWriteAccessContext ctx) { + private Expr createArrayWriteExpr( + final Expr op, final ArrayWriteAccessContext ctx) { checkArgument(op.getType() instanceof ArrayType); - @SuppressWarnings("unchecked") final Expr> array = (Expr>) op; + @SuppressWarnings("unchecked") + final Expr> array = (Expr>) op; final Expr index = cast(ctx.index.accept(this), array.getType().getIndexType()); final Expr elem = cast(ctx.elem.accept(this), array.getType().getElemType()); return Write(array, index, elem); @@ -1072,13 +1105,18 @@ private Expr createArrayLitExpr( } valueType = (T2) ctx.elseExpr.accept(this).getType(); - final List, Expr>> elems = IntStream - .range(0, ctx.indexExpr.size()) - .mapToObj(i -> Tuple2.of( - cast(ctx.indexExpr.get(i).accept(this), indexType), - cast(ctx.valueExpr.get(i).accept(this), valueType) - )) - .collect(Collectors.toUnmodifiableList()); + final List, Expr>> elems = + IntStream.range(0, ctx.indexExpr.size()) + .mapToObj( + i -> + Tuple2.of( + cast( + ctx.indexExpr.get(i).accept(this), + indexType), + cast( + ctx.valueExpr.get(i).accept(this), + valueType))) + .collect(Collectors.toUnmodifiableList()); final Expr elseExpr = cast(ctx.elseExpr.accept(this), valueType); return simplify(ArrayInit(elems, elseExpr, ArrayType.of(indexType, valueType))); @@ -1102,7 +1140,8 @@ public Expr visitBvLitExpr(final BvLitExprContext ctx) { throw new ParseException(ctx, "Invalid bitvector literal"); } - checkArgument(value.length <= size, + checkArgument( + value.length <= size, "The value of the literal cannot be represented on the given amount of bits"); final boolean[] bvValue = new boolean[size]; @@ -1134,11 +1173,10 @@ private boolean[] decodeBinaryBvContent(String lit) { private boolean[] decodeDecimalBvContent(String lit, int size) { BigInteger value = new BigInteger(lit); checkArgument( - value.compareTo(BigInteger.TWO.pow(size - 1).multiply(BigInteger.valueOf(-1))) >= 0 - && - value.compareTo(BigInteger.TWO.pow(size)) < 0, - "Decimal literal is not in range" - ); + value.compareTo(BigInteger.TWO.pow(size - 1).multiply(BigInteger.valueOf(-1))) + >= 0 + && value.compareTo(BigInteger.TWO.pow(size)) < 0, + "Decimal literal is not in range"); if (value.compareTo(BigInteger.ZERO) < 0) { value = value.add(BigInteger.TWO.pow(size)); @@ -1210,8 +1248,8 @@ private boolean[] decodeHexadecimalBvContent(String lit) { public RefExpr visitIdExpr(final IdExprContext ctx) { Optional optSymbol = currentScope.resolve(ctx.id.getText()); if (optSymbol.isEmpty()) { - throw new ParseException(ctx, - "Identifier '" + ctx.id.getText() + "' cannot be resolved"); + throw new ParseException( + ctx, "Identifier '" + ctx.id.getText() + "' cannot be resolved"); } final Symbol symbol = optSymbol.get(); final Decl decl = (Decl) env.eval(symbol); @@ -1222,8 +1260,5 @@ public RefExpr visitIdExpr(final IdExprContext ctx) { public Expr visitParenExpr(final ParenExprContext ctx) { return ctx.op.accept(this); } - } - } - diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaLocationSymbol.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaLocationSymbol.java index 254b1657f1..0d70c32d93 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaLocationSymbol.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaLocationSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -67,5 +67,4 @@ public Loc intantiate(final CFA.Builder cfaBuilder) { return loc; } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaProcessSymbol.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaProcessSymbol.java index e861a29b9f..1f00e2ff1d 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaProcessSymbol.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaProcessSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,10 +18,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.CFA.Builder; import hu.bme.mit.theta.cfa.CFA.Loc; @@ -34,6 +30,9 @@ import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.common.dsl.SymbolTable; import hu.bme.mit.theta.core.decl.VarDecl; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; final class CfaProcessSymbol implements Symbol, Scope { @@ -162,5 +161,4 @@ private List createEdges(final List edgeContexts } return result; } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaSpecification.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaSpecification.java index 1174088653..e5030f7d71 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaSpecification.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaSpecification.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,10 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.stream.Collectors.toList; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser.ProcDeclContext; import hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser.SpecContext; @@ -32,6 +28,9 @@ import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.common.dsl.SymbolTable; import hu.bme.mit.theta.core.decl.VarDecl; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; final class CfaSpecification implements Scope { @@ -65,9 +64,8 @@ public CFA instantiate() { env.define(variable, var); } - final List mainProcesses = processes.stream() - .filter(CfaProcessSymbol::isMain) - .collect(toList()); + final List mainProcesses = + processes.stream().filter(CfaProcessSymbol::isMain).collect(toList()); if (mainProcesses.isEmpty()) { throw new IllegalArgumentException("No main process defined"); @@ -115,5 +113,4 @@ private List createProcesses(final List procD } return result; } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaStatement.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaStatement.java index 0b966942c1..28c4f79f31 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaStatement.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaStatement.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -91,15 +91,15 @@ public Stmt visitAssignStmt(final AssignStmtContext ctx) { final Expr expr = expression.instantiate(env); if (expr.getType().equals(var.getType())) { - @SuppressWarnings("unchecked") final VarDecl tVar = (VarDecl) var; - @SuppressWarnings("unchecked") final Expr tExpr = (Expr) expr; + @SuppressWarnings("unchecked") + final VarDecl tVar = (VarDecl) var; + @SuppressWarnings("unchecked") + final Expr tExpr = (Expr) expr; return Assign(tVar, tExpr); } else { throw new IllegalArgumentException( "Type of " + var + " is incompatilbe with " + expr); } } - } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaType.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaType.java index 890277a2f4..ae67a0051b 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaType.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,6 @@ */ package hu.bme.mit.theta.cfa.dsl; -import hu.bme.mit.theta.cfa.dsl.gen.CfaDslBaseVisitor; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.fptype.FpType; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import static com.google.common.base.Preconditions.checkNotNull; import static hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser.ArrayTypeContext; import static hu.bme.mit.theta.cfa.dsl.gen.CfaDslParser.BoolTypeContext; @@ -36,6 +29,12 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import hu.bme.mit.theta.cfa.dsl.gen.CfaDslBaseVisitor; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.fptype.FpType; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + final class CfaType { private final TypeContext context; @@ -57,8 +56,7 @@ private static class TypeCreatorVisitor extends CfaDslBaseVisitor { private static final TypeCreatorVisitor INSTANCE = new TypeCreatorVisitor(); - private TypeCreatorVisitor() { - } + private TypeCreatorVisitor() {} @Override public Type visitBoolType(final BoolTypeContext ctx) { @@ -115,6 +113,4 @@ private int getSignificand(String text) { } } } - } - diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaVariableSymbol.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaVariableSymbol.java index 2e48efb2bd..6c498be6b9 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaVariableSymbol.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaVariableSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -41,5 +41,4 @@ public String getName() { public VarDecl instantiate() { return Var(name, type.instantiate()); } - } diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaWriter.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaWriter.java index 3d3c272768..1193884e1d 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaWriter.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/CfaWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,7 +21,6 @@ import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.dsl.CoreDslManager; import hu.bme.mit.theta.core.stmt.Stmt; - import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStream; @@ -29,8 +28,7 @@ public final class CfaWriter { - private CfaWriter() { - } + private CfaWriter() {} public static void write(final CFA cfa, final OutputStream outStream) throws IOException { final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outStream)); diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/package-info.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/package-info.java index 658ba5b2a3..21bcc7b8bc 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/package-info.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/dsl/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ * * @see hu.bme.mit.theta.cfa.dsl.CfaDslManager */ - -package hu.bme.mit.theta.cfa.dsl; \ No newline at end of file +package hu.bme.mit.theta.cfa.dsl; diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaInterpreter.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaInterpreter.java index 59db24b0c3..bcdbd564e5 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaInterpreter.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaInterpreter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,11 +21,7 @@ import static hu.bme.mit.theta.common.Utils.tail; import static hu.bme.mit.theta.core.decl.Decls.Var; -import java.util.List; -import java.util.function.Function; - import com.google.common.primitives.Ints; - import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.cfa.CFA.Edge; import hu.bme.mit.theta.cfa.CFA.Loc; @@ -37,6 +33,8 @@ import hu.bme.mit.theta.core.parser.Env; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.Type; +import java.util.List; +import java.util.function.Function; final class CfaInterpreter { @@ -98,7 +96,8 @@ private Object evalList(final SList slist) { if (head.isAtom()) { final String symbol = head.asAtom().getAtom(); final Object object = env.eval(symbol); - @SuppressWarnings("unchecked") final Function, ?> interpretation = (Function, ?>) object; + @SuppressWarnings("unchecked") + final Function, ?> interpretation = (Function, ?>) object; final Object value = interpretation.apply(tail); return value; } else if (head.isList()) { @@ -154,7 +153,6 @@ private Loc createLoc(final CFA.Builder builder, final LocContext context) { private Edge createEdge(final CFA.Builder builder, final EdgeContext context) { final Edge edge = builder.createEdge(context.source, context.target, context.stmt); return edge; - } private Function, VarDecl> varCreator() { @@ -199,7 +197,10 @@ private LocContext(final LocKind kind, final String name) { } private enum LocKind { - LOC, INIT, FINAL, ERROR + LOC, + INIT, + FINAL, + ERROR } private static final class EdgeContext { diff --git a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaParser.java b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaParser.java index 80fac05a6a..4ccb4d30bc 100644 --- a/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaParser.java +++ b/subprojects/cfa/cfa/src/main/java/hu/bme/mit/theta/cfa/parser/CfaParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,12 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.io.Reader; - import hu.bme.mit.theta.cfa.CFA; import hu.bme.mit.theta.common.parser.LispLexer; import hu.bme.mit.theta.common.parser.LispParser; import hu.bme.mit.theta.common.parser.SExpr; import hu.bme.mit.theta.core.parser.Env; +import java.io.Reader; public final class CfaParser { @@ -43,5 +42,4 @@ public CFA cfa() { final CFA cfa = interpreter.cfa(sexpr); return cfa; } - } diff --git a/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/CfaTest.java b/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/CfaTest.java index 3796ed9789..41d0937af9 100644 --- a/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/CfaTest.java +++ b/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/CfaTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/dsl/CfaDslManagerTest.java b/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/dsl/CfaDslManagerTest.java index f31668ddf5..b73b1e083f 100644 --- a/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/dsl/CfaDslManagerTest.java +++ b/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/dsl/CfaDslManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,11 @@ */ package hu.bme.mit.theta.cfa.dsl; +import hu.bme.mit.theta.cfa.CFA; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,8 +27,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.cfa.CFA; - @RunWith(Parameterized.class) public final class CfaDslManagerTest { @@ -49,24 +47,17 @@ public final class CfaDslManagerTest { @Parameters() public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"/locking.cfa", 3, 9, 10, 10}, - - {"/counter5_true.cfa", 1, 6, 6, 6}, - - {"/bv.cfa", 1, 6, 6, 6}, - - {"/bv2.cfa", 1, 6, 6, 6}, - - {"/bv3.cfa", 1, 6, 6, 6}, - - {"/bv4.cfa", 2, 7, 8, 8}, - - {"/fp1.cfa", 4, 7, 6, 6}, - - {"/fp2.cfa", 4, 7, 6, 6} - }); + return Arrays.asList( + new Object[][] { + {"/locking.cfa", 3, 9, 10, 10}, + {"/counter5_true.cfa", 1, 6, 6, 6}, + {"/bv.cfa", 1, 6, 6, 6}, + {"/bv2.cfa", 1, 6, 6, 6}, + {"/bv3.cfa", 1, 6, 6, 6}, + {"/bv4.cfa", 2, 7, 8, 8}, + {"/fp1.cfa", 4, 7, 6, 6}, + {"/fp2.cfa", 4, 7, 6, 6} + }); } @Test @@ -78,5 +69,4 @@ public void test() throws IOException { Assert.assertEquals(edgeCount, cfa.getEdges().size()); Assert.assertEquals(stmtCount, cfa.getEdges().stream().map(e -> e.getStmt()).count()); } - } diff --git a/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/parser/CfaParserTest.java b/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/parser/CfaParserTest.java index c320226c7f..63f0494cff 100644 --- a/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/parser/CfaParserTest.java +++ b/subprojects/cfa/cfa/src/test/java/hu/bme/mit/theta/cfa/parser/CfaParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.cfa.parser; +import hu.bme.mit.theta.cfa.CFA; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.util.Arrays; import java.util.Collection; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -31,8 +31,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.cfa.CFA; - @RunWith(Parameterized.class) public final class CfaParserTest { @@ -44,11 +42,10 @@ public final class CfaParserTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"src/test/resources/counter5_true.lisp.cfa"}, - - }); + return Arrays.asList( + new Object[][] { + {"src/test/resources/counter5_true.lisp.cfa"}, + }); } @Before @@ -70,5 +67,4 @@ public void test() { Assert.assertEquals(6, cfa.getLocs().size()); Assert.assertEquals(6, cfa.getEdges().size()); } - } diff --git a/subprojects/cfa/cfa/src/test/kotlin/hu/bme/mit/theta/cfa/CFAVarChangerUnitTest.kt b/subprojects/cfa/cfa/src/test/kotlin/hu/bme/mit/theta/cfa/CFAVarChangerUnitTest.kt index 5bacc3fda3..7ba89089f1 100644 --- a/subprojects/cfa/cfa/src/test/kotlin/hu/bme/mit/theta/cfa/CFAVarChangerUnitTest.kt +++ b/subprojects/cfa/cfa/src/test/kotlin/hu/bme/mit/theta/cfa/CFAVarChangerUnitTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,23 +18,21 @@ package hu.bme.mit.theta.cfa import hu.bme.mit.theta.cfa.dsl.CfaDslManager import hu.bme.mit.theta.core.decl.Decls import hu.bme.mit.theta.core.type.inttype.IntType -import org.junit.jupiter.api.Test import java.io.FileInputStream +import org.junit.jupiter.api.Test class CFAVarChangerUnitTest { - @Test - fun `single variable changing`() { - var origCfa: CFA - FileInputStream("src/test/resources/counter5_true.cfa").use { inputStream -> - origCfa = CfaDslManager.createCfa(inputStream) - } - val newVar = Decls.Var("x", IntType.getInstance()) - val newCfa = origCfa.copyWithReplacingVars(listOf(newVar).associateBy { it.name }) - - assert(!newCfa.vars.any { - origCfa.vars.contains(it) - }) - assert(origCfa.vars.iterator().next() != newCfa.vars.iterator().next()) + @Test + fun `single variable changing`() { + var origCfa: CFA + FileInputStream("src/test/resources/counter5_true.cfa").use { inputStream -> + origCfa = CfaDslManager.createCfa(inputStream) } -} \ No newline at end of file + val newVar = Decls.Var("x", IntType.getInstance()) + val newCfa = origCfa.copyWithReplacingVars(listOf(newVar).associateBy { it.name }) + + assert(!newCfa.vars.any { origCfa.vars.contains(it) }) + assert(origCfa.vars.iterator().next() != newCfa.vars.iterator().next()) + } +} diff --git a/subprojects/common/analysis/build.gradle.kts b/subprojects/common/analysis/build.gradle.kts index 4bb71e0bfe..36fe0aaf99 100644 --- a/subprojects/common/analysis/build.gradle.kts +++ b/subprojects/common/analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Action.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Action.java index 981795f785..63cfa1f0ef 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Action.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Action.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,5 @@ */ package hu.bme.mit.theta.analysis; -/** - * Common interface for actions. - */ -public interface Action { - -} +/** Common interface for actions. */ +public interface Action {} diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Analysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Analysis.java index 86fddecba7..82a07900e4 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Analysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Analysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -44,5 +44,4 @@ public interface Analysis { * @return */ TransFunc getTransFunc(); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Cex.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Cex.java index 0b933821b5..8ea800be3a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Cex.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Cex.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/EmptyCex.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/EmptyCex.java index ddb6c2cb2a..30f88ae14a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/EmptyCex.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/EmptyCex.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,10 +17,9 @@ public class EmptyCex implements Cex { - private final static EmptyCex empty = new EmptyCex(); + private static final EmptyCex empty = new EmptyCex(); - private EmptyCex() { - } + private EmptyCex() {} public static EmptyCex getInstance() { return empty; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InitFunc.java index 264af0dc92..b105b5567c 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,7 @@ import java.util.Collection; -/** - * Common interface for initial functions. - */ +/** Common interface for initial functions. */ @FunctionalInterface public interface InitFunc { @@ -30,5 +28,4 @@ public interface InitFunc { * @return Collection of initial states */ Collection getInitStates(P prec); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InvTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InvTransFunc.java index e6a9afb389..243d35795e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InvTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/InvTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ public interface InvTransFunc { Collection getPreStates(S state, A action, P prec); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/LTS.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/LTS.java index 9d59b77c2a..06d37a611d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/LTS.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/LTS.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,8 +18,8 @@ import java.util.Collection; /** - * Common interface for Labeled Transition Systems (LTS). An LTS can provide - * enabled actions for a given state. + * Common interface for Labeled Transition Systems (LTS). An LTS can provide enabled actions for a + * given state. */ @FunctionalInterface public interface LTS { @@ -35,12 +35,13 @@ public interface LTS { /** * Gets the enabled actions for a given state using the current precision. * - * @param state the state whose enabled actions we would like to know + * @param state the state whose enabled actions we would like to know * @param exploredActions the actions already explored from the given state - * @param prec the current precision + * @param prec the current precision * @return the enabled actions */ - default

Collection getEnabledActionsFor(S state, Collection exploredActions, P prec) { + default

Collection getEnabledActionsFor( + S state, Collection exploredActions, P prec) { return getEnabledActionsFor(state); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Lattice.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Lattice.java index 27603880d9..c8d28df835 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Lattice.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Lattice.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,5 +24,4 @@ public interface Lattice extends PartialOrd { S meet(S state1, S state2); S join(S state1, S state2); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/PartialOrd.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/PartialOrd.java index d5129fa029..8d21787aff 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/PartialOrd.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/PartialOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,7 @@ */ package hu.bme.mit.theta.analysis; -/** - * Common interface for partial orders. - */ +/** Common interface for partial orders. */ @FunctionalInterface public interface PartialOrd { @@ -29,5 +27,4 @@ public interface PartialOrd { * @return */ boolean isLeq(S state1, S state2); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Prec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Prec.java index 0e5800644a..a1c639c65a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Prec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Prec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,14 +16,10 @@ package hu.bme.mit.theta.analysis; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; -/** - * Common interface for precisions. - */ +/** Common interface for precisions. */ public interface Prec { Collection> getUsedVars(); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/State.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/State.java index 56c1b005aa..deab267f5e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/State.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/State.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,7 @@ */ package hu.bme.mit.theta.analysis; -/** - * Common interface for states. - */ +/** Common interface for states. */ public interface State { /** @@ -26,5 +24,4 @@ public interface State { * @return */ boolean isBottom(); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Trace.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Trace.java index e1e32d60eb..27c9152867 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Trace.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/Trace.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.analysis; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkElementIndex; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.LispStringBuilder; import hu.bme.mit.theta.common.Utils; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkElementIndex; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Represents an immutable, alternating trace in the form of a (State, Action, State, ..., State, * Action, State) sequence. A trace always contains at least one state and the number of actions is @@ -48,14 +47,12 @@ private Trace(final List states, final List actions) { * Create a trace. The size of states must be at least one, and the size of the actions must be * one less than the number of states. */ - public static Trace of(final List states, - final List actions) { + public static Trace of( + final List states, final List actions) { return new Trace<>(states, actions); } - /** - * Gets the length of the trace, which is the number of actions. - */ + /** Gets the length of the trace, which is the number of actions. */ @Override public int length() { return actions.size(); @@ -138,5 +135,4 @@ public String toString() { sb.add(states.get(length())); return sb.toString(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/TransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/TransFunc.java index 6e4f8aea83..ac200bdc44 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/TransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/TransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,7 @@ import java.util.Collection; -/** - * Common interface for transfer functions. - */ +/** Common interface for transfer functions. */ @FunctionalInterface public interface TransFunc { @@ -32,5 +30,4 @@ public interface TransFunc { * @return Collection of successor states */ Collection getSuccStates(S state, A action, P prec); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Checker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Checker.java index afed36eab9..c8dc6937e5 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Checker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Checker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/EmptyProof.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/EmptyProof.java index 1c8d976149..50babb3de9 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/EmptyProof.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/EmptyProof.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Proof.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Proof.java index 3668ab6315..bdeb748be1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Proof.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Proof.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Result.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Result.java index 438edde295..e23fe02e1f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Result.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Result.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyChecker.java index c716c1dc24..7ac92ca517 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyResult.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyResult.java index 0862dc3079..1105958170 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyResult.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/SafetyResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Statistics.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Statistics.java index e7fcc7f9fe..67ff6534e1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Statistics.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/Statistics.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -35,23 +35,17 @@ protected Statistics() { stats = new LinkedHashMap<>(); } - /** - * Add a new statistic. - */ + /** Add a new statistic. */ protected void addStat(final String key, final Supplier value) { stats.put(key, value); } - /** - * Gets the set of keys. - */ + /** Gets the set of keys. */ public final Set keySet() { return Collections.unmodifiableSet(stats.keySet()); } - /** - * Gets the value for a given key. The key must exist. - */ + /** Gets the value for a given key. The key must exist. */ public final Object get(final String key) { checkArgument(stats.containsKey(key), "Key not found"); return stats.get(key).get(); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ARG.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ARG.java index 9f2b3c3ae0..baf9994d5a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ARG.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ARG.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgBuilder.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgBuilder.java index a261489c38..a21c550fc1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgBuilder.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,15 @@ */ package hu.bme.mit.theta.analysis.algorithm.arg; -import hu.bme.mit.theta.analysis.*; +import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.analysis.*; import java.util.ArrayList; import java.util.Collection; -import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Helper class for building the ARG with a given analysis and precision. - */ +/** Helper class for building the ARG with a given analysis and precision. */ public final class ArgBuilder { private final LTS lts; @@ -35,8 +31,11 @@ public final class ArgBuilder private final Predicate target; private final boolean excludeBottom; - private ArgBuilder(final LTS lts, final Analysis analysis, - final Predicate target, final boolean excludeBottom) { + private ArgBuilder( + final LTS lts, + final Analysis analysis, + final Predicate target, + final boolean excludeBottom) { this.lts = checkNotNull(lts); this.analysis = checkNotNull(analysis); this.target = checkNotNull(target); @@ -44,13 +43,16 @@ private ArgBuilder(final LTS lts, final Analysis ArgBuilder create( - final LTS lts, final Analysis analysis, - final Predicate target, final boolean excludeBottom) { + final LTS lts, + final Analysis analysis, + final Predicate target, + final boolean excludeBottom) { return new ArgBuilder<>(lts, analysis, target, excludeBottom); } public static ArgBuilder create( - final LTS lts, final Analysis analysis, + final LTS lts, + final Analysis analysis, final Predicate target) { return create(lts, analysis, target, false); } @@ -86,8 +88,10 @@ public Collection> expand(final ArgNode node, final P prec) checkNotNull(prec); final Collection> newSuccNodes = new ArrayList<>(); final S state = node.getState(); - final Collection exploredActions = node.getOutEdges().map(ArgEdge::getAction).collect(Collectors.toSet()); - final Collection actions = lts.getEnabledActionsFor(state, exploredActions, prec); + final Collection exploredActions = + node.getOutEdges().map(ArgEdge::getAction).collect(Collectors.toSet()); + final Collection actions = + lts.getEnabledActionsFor(state, exploredActions, prec); final TransFunc transFunc = analysis.getTransFunc(); for (final A action : actions) { final Collection succStates = transFunc.getSuccStates(state, action, prec); @@ -96,10 +100,15 @@ public Collection> expand(final ArgNode node, final P prec) continue; } // Only add state if there is no covering sibling (with the same action) - if (node.getSuccNodes().noneMatch(n -> n.getInEdge().get().getAction().equals(action) && - analysis.getPartialOrd().isLeq(succState, n.getState()))) { + if (node.getSuccNodes() + .noneMatch( + n -> + n.getInEdge().get().getAction().equals(action) + && analysis.getPartialOrd() + .isLeq(succState, n.getState()))) { final boolean isTarget = target.test(succState); - final ArgNode newNode = node.arg.createSuccNode(node, action, succState, isTarget); + final ArgNode newNode = + node.arg.createSuccNode(node, action, succState, isTarget); newSuccNodes.add(newNode); } } @@ -108,5 +117,4 @@ public Collection> expand(final ArgNode node, final P prec) return newSuccNodes; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgChecker.java index 5cbe09c120..d1de140c8a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,10 +19,6 @@ import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; -import java.util.Collection; -import java.util.Optional; -import java.util.Set; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.State; @@ -31,6 +27,9 @@ import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.analysis.expr.ExprStateUtils; import hu.bme.mit.theta.solver.Solver; +import java.util.Collection; +import java.util.Optional; +import java.util.Set; public final class ArgChecker { @@ -76,18 +75,19 @@ private boolean nodeIsWellLabeled( //// private boolean nodeIsWellLabeledForCoverage(final ArgNode node) { - final Optional> optCoveringNode = node.getCoveringNode(); + final Optional> optCoveringNode = + node.getCoveringNode(); if (optCoveringNode.isPresent()) { final ArgNode coveringNode = optCoveringNode.get(); return isCoveredBy(node, coveringNode) && !coveringNode.isExcluded(); } else { return true; } - } - private boolean isCoveredBy(final ArgNode node, - final ArgNode coveringNode) { + private boolean isCoveredBy( + final ArgNode node, + final ArgNode coveringNode) { return partialOrd.isLeq(node.getState(), coveringNode.getState()); } @@ -107,8 +107,10 @@ private boolean nodeIsWellLabeledForAction( return hasSuccStates(state, action, succStates); } - private boolean hasSuccStates(final ExprState state, final ExprAction action, - final Collection succStates) { + private boolean hasSuccStates( + final ExprState state, + final ExprAction action, + final Collection succStates) { return !ExprStateUtils.anyUncoveredSuccessor(state, action, succStates, solver).isPresent(); } @@ -121,9 +123,9 @@ private static Set getActionsForNode( private static Collection getSuccStatesOfNodeForAction( final ArgNode node, final A action) { - return node.outEdges.stream().filter(e -> e.getAction().equals(action)) + return node.outEdges.stream() + .filter(e -> e.getAction().equals(action)) .map(e -> e.getTarget().getState()) .collect(toList()); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgEdge.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgEdge.java index e2609303ae..215b1e8b52 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgEdge.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgEdge.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -40,5 +40,4 @@ public ArgNode getTarget() { public A getAction() { return action; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNode.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNode.java index 435193fa23..9c248a76d1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNode.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.analysis.algorithm.arg; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; - import java.util.ArrayList; import java.util.Collection; import java.util.Optional; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - public final class ArgNode { final ARG arg; @@ -47,7 +46,12 @@ public final class ArgNode { public boolean expanded; // Set by ArgBuilder - ArgNode(final ARG arg, final S state, final int id, final int depth, final boolean target) { + ArgNode( + final ARG arg, + final S state, + final int id, + final int depth, + final boolean target) { this.arg = arg; this.state = state; this.id = id; @@ -67,8 +71,8 @@ public int getId() { } /** - * Gets the depth of the node, which is 0 if the node has no parent, and - * depth(parent) + 1 otherwise. + * Gets the depth of the node, which is 0 if the node has no parent, and depth(parent) + 1 + * otherwise. */ public int getDepth() { return depth; @@ -162,69 +166,49 @@ public Stream getSuccStates() { //// - /** - * Checks if the node is covered, i.e., there is a covering edge for the - * node. - */ + /** Checks if the node is covered, i.e., there is a covering edge for the node. */ public boolean isCovered() { return coveringNode.isPresent(); } - /** - * Checks if the node is not a bottom state. - */ + /** Checks if the node is not a bottom state. */ public boolean isFeasible() { return !state.isBottom(); } - /** - * Checks if the node is subsumed, i.e., the node is covered or not - * feasible. - */ + /** Checks if the node is subsumed, i.e., the node is covered or not feasible. */ public boolean isSubsumed() { return isCovered() || !isFeasible(); } - /** - * Checks if the node is excluded, i.e., the node is subsumed or has an - * excluded parent. - */ + /** Checks if the node is excluded, i.e., the node is subsumed or has an excluded parent. */ public boolean isExcluded() { return ancestors().anyMatch(ArgNode::isSubsumed); } /** - * Checks if the node is target, i.e., the target predicate holds (e.g., it - * is an error state). + * Checks if the node is target, i.e., the target predicate holds (e.g., it is an error state). */ public boolean isTarget() { return target; } - /** - * Checks if the node is expanded, i.e., all of its successors are present. - */ + /** Checks if the node is expanded, i.e., all of its successors are present. */ public boolean isExpanded() { return expanded; } - /** - * Checks if the node is leaf, i.e., it has no successors. - */ + /** Checks if the node is leaf, i.e., it has no successors. */ public boolean isLeaf() { return outEdges.isEmpty(); } - /** - * Checks if the node is safe, i.e., not target or excluded. - */ + /** Checks if the node is safe, i.e., not target or excluded. */ public boolean isSafe() { return !isTarget() || isExcluded(); } - /** - * Checks if the node is complete, i.e., expanded or excluded. - */ + /** Checks if the node is complete, i.e., expanded or excluded. */ public boolean isComplete() { return isExpanded() || isExcluded(); } @@ -232,7 +216,9 @@ public boolean isComplete() { //// public Stream> properAncestors() { - return getParent().map(p -> Stream.concat(Stream.of(p), p.properAncestors())).orElse(Stream.empty()); + return getParent() + .map(p -> Stream.concat(Stream.of(p), p.properAncestors())) + .orElse(Stream.empty()); } public Stream> ancestors() { @@ -263,7 +249,8 @@ private Stream> unexcludedDescendantsOfNode() { if (this.isSubsumed()) { return Stream.empty(); } else { - return Stream.concat(Stream.of(this), this.children().flatMap(ArgNode::unexcludedDescendantsOfNode)); + return Stream.concat( + Stream.of(this), this.children().flatMap(ArgNode::unexcludedDescendantsOfNode)); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparators.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparators.java index d9ab01928c..3943a87a2f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparators.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparators.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,19 @@ */ package hu.bme.mit.theta.analysis.algorithm.arg; -import java.io.Serializable; -import java.util.Comparator; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.common.Utils; +import java.io.Serializable; +import java.util.Comparator; -/** - * A collection of comparators for ArgNodes. - */ +/** A collection of comparators for ArgNodes. */ public class ArgNodeComparators { - private ArgNodeComparators() { - } - - public interface ArgNodeComparator extends - Comparator>, Serializable { + private ArgNodeComparators() {} - } + public interface ArgNodeComparator + extends Comparator>, Serializable {} //// @@ -49,8 +43,8 @@ public static ArgNodeComparator invert(final ArgNodeComparator comparator) { return new Inverter(comparator); } - public static ArgNodeComparator combine(final ArgNodeComparator first, - final ArgNodeComparator then) { + public static ArgNodeComparator combine( + final ArgNodeComparator first, final ArgNodeComparator then) { return new Combinator(first, then); } @@ -73,8 +67,9 @@ private static final class DepthOrder implements ArgNodeComparator { private static final long serialVersionUID = 6538293612674961734L; @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { return Integer.compare(n1.getDepth(), n2.getDepth()); } @@ -89,8 +84,9 @@ private static final class CreationOrder implements ArgNodeComparator { private static final long serialVersionUID = -8221009565128954827L; @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { return Integer.compare(n1.getId(), n2.getId()); } @@ -105,8 +101,9 @@ private static final class TargetFirst implements ArgNodeComparator { private static final long serialVersionUID = 4913094714715832187L; @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { return Boolean.compare(n1.isTarget(), n2.isTarget()) * -1; } @@ -126,8 +123,9 @@ private Inverter(final ArgNodeComparator comparator) { } @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { return comparator.compare(n1, n2) * -1; } @@ -148,8 +146,9 @@ private Combinator(final ArgNodeComparator first, final ArgNodeComparator then) } @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { final int compareFirst = first.compare(n1, n2); if (compareFirst == 0) { return then.compare(n1, n2); @@ -160,7 +159,9 @@ public int compare(final ArgNode n1, @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).add(first).add(then) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .add(first) + .add(then) .toString(); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEquality.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEquality.java index b8249aa378..67b83ca19a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEquality.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEquality.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,38 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm.arg; +import static com.google.common.base.Objects.equal; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; - import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Objects.equal; - /** - * Structural comparisons using equal() and hashCode() for ARG-related classes. - * Each node is uniquely identifiable using its incoming edge (or its absence), and wrapped state. - * Each edge is uniquely identifiable using its source node, and wrapped action. - * An ARG is uniquely identifiable using its leaf nodes. - * An ArgTrace is uniquely identifiable using its last node. - *

- * We perform caching for the hash codes, but equals() checks will always traverse the ancestors of - * a node (and edge). However, this traversal only goes towards the root, rather than in all + * Structural comparisons using equal() and hashCode() for ARG-related classes. Each node is + * uniquely identifiable using its incoming edge (or its absence), and wrapped state. Each edge is + * uniquely identifiable using its source node, and wrapped action. An ARG is uniquely identifiable + * using its leaf nodes. An ArgTrace is uniquely identifiable using its last node. + * + *

(val innerPrec: P, val set: Set = emptySet(), val smth: Int = 0) : Prec { +data class PtrPrec

(val innerPrec: P, val set: Set = emptySet(), val smth: Int = 0) : + Prec { - override fun getUsedVars(): Collection> = innerPrec.usedVars -} \ No newline at end of file + override fun getUsedVars(): Collection> = innerPrec.usedVars +} diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrState.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrState.kt index 85652e3f1c..fcd0f2c7df 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrState.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrState.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,16 +19,15 @@ import hu.bme.mit.theta.analysis.expr.ExprState import hu.bme.mit.theta.core.type.Expr import hu.bme.mit.theta.core.type.booltype.BoolType -data class PtrState @JvmOverloads constructor( - val innerState: S, - val nextCnt: Int = 0, -) : ExprState { +data class PtrState +@JvmOverloads +constructor(val innerState: S, val nextCnt: Int = 0) : ExprState { - override fun isBottom(): Boolean { - return innerState.isBottom() - } + override fun isBottom(): Boolean { + return innerState.isBottom() + } - override fun toExpr(): Expr { - return innerState.toExpr() - } + override fun toExpr(): Expr { + return innerState.toExpr() + } } 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 8656387c39..a674f4e389 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/Partition.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/Partition.java index 8a425c22b6..272f35d971 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/Partition.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/Partition.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,9 @@ */ package hu.bme.mit.theta.analysis.reachedset; -import hu.bme.mit.theta.common.container.Containers; - import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.common.container.Containers; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -62,5 +61,4 @@ public List get(final T elem) { final List partition = classes.getOrDefault(key, Collections.emptyList()); return partition; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/ReachedSet.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/ReachedSet.java index 54272de4a4..2859710db0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/ReachedSet.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/reachedset/ReachedSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,10 @@ */ package hu.bme.mit.theta.analysis.reachedset; -import java.util.stream.Stream; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; +import java.util.stream.Stream; public interface ReachedSet { @@ -34,5 +33,4 @@ default void addAll(final Stream> nodes) { } void tryToCover(ArgNode node); - } 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 94875a8124..66386d94ed 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/Monitor.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/Monitor.kt index c7ce94441a..5c2370b21a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/Monitor.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/Monitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,5 +17,5 @@ package hu.bme.mit.theta.analysis.runtimemonitor interface Monitor { - fun execute(checkpointName: String) -} \ No newline at end of file + fun execute(checkpointName: String) +} 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 bf4b89832d..3964024b10 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/CexHashStorage.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/CexHashStorage.kt index d199287c94..1d233c3839 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/CexHashStorage.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/CexHashStorage.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,15 +20,15 @@ import hu.bme.mit.theta.analysis.State import hu.bme.mit.theta.analysis.algorithm.arg.ArgStructuralEquality import hu.bme.mit.theta.analysis.algorithm.arg.ArgTrace -class CexHashStorage : - RuntimeDataCollection?> { +class CexHashStorage : RuntimeDataCollection?> { - private val counterexamples: MutableSet = LinkedHashSet() - override fun addData(newData: ArgTrace?) { - counterexamples.add(ArgStructuralEquality.hashCode(newData)) - } + private val counterexamples: MutableSet = LinkedHashSet() - override operator fun contains(data: ArgTrace?): Boolean { - return counterexamples.contains(ArgStructuralEquality.hashCode(data)) - } -} \ No newline at end of file + override fun addData(newData: ArgTrace?) { + counterexamples.add(ArgStructuralEquality.hashCode(newData)) + } + + override operator fun contains(data: ArgTrace?): Boolean { + return counterexamples.contains(ArgStructuralEquality.hashCode(data)) + } +} diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/RuntimeDataCollection.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/RuntimeDataCollection.kt index 809c5a5cc6..a3dacadcd3 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/RuntimeDataCollection.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/runtimemonitor/container/RuntimeDataCollection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,6 +17,7 @@ package hu.bme.mit.theta.analysis.runtimemonitor.container interface RuntimeDataCollection { - fun addData(newData: T) - fun contains(data: T): Boolean? + fun addData(newData: T) + + fun contains(data: T): Boolean? } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/DefaultStmtOptimizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/DefaultStmtOptimizer.java index ca5fdda9ac..00d1e983f0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/DefaultStmtOptimizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/DefaultStmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,5 +28,4 @@ public static DefaultStmtOptimizer create() { public Stmt optimizeStmt(S state, Stmt stmt) { return stmt; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/StmtOptimizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/StmtOptimizer.java index 1a41959242..33d3e9f6cd 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/StmtOptimizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/stmtoptimizer/StmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,5 +21,4 @@ public interface StmtOptimizer { Stmt optimizeStmt(final S state, final Stmt stmt); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitAnalysis.java index c6edcd3b41..eea15428de 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,16 +17,15 @@ import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.TransFunc; public final class UnitAnalysis implements Analysis { private static final UnitAnalysis INSTANCE = new UnitAnalysis(); - private UnitAnalysis() { - } + private UnitAnalysis() {} public static UnitAnalysis getInstance() { return INSTANCE; @@ -46,5 +45,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return UnitTransFunc.getInstance(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitInitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitInitFunc.java index 78289cc1e0..1b80213c37 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitInitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitOrd.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitOrd.java index 7b0c1a6e9a..51e804d580 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitOrd.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,8 +23,7 @@ final class UnitOrd implements PartialOrd { private static final UnitOrd INSTANCE = new UnitOrd(); - private UnitOrd() { - } + private UnitOrd() {} public static UnitOrd getInstance() { return INSTANCE; @@ -36,5 +35,4 @@ public boolean isLeq(final UnitState state1, final UnitState state2) { checkNotNull(state2); return true; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitPrec.java index 66e3bf48ab..62cfeec6da 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; import java.util.Set; @@ -25,8 +24,7 @@ public final class UnitPrec implements Prec { private static final UnitPrec INSTANCE = new UnitPrec(); - private UnitPrec() { - } + private UnitPrec() {} public static UnitPrec getInstance() { return INSTANCE; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitState.java index a43a04f35b..d1b47c2402 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,8 +25,7 @@ public final class UnitState implements ExprState { private static final UnitState INSTANCE = new UnitState(); - private UnitState() { - } + private UnitState() {} public static UnitState getInstance() { return INSTANCE; @@ -46,5 +45,4 @@ public Expr toExpr() { public String toString() { return getClass().getSimpleName(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitTransFunc.java index 7ca8f3d5e4..367fbf62dc 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/unit/UnitTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,32 +17,28 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.TransFunc; +import java.util.Collection; final class UnitTransFunc implements TransFunc { private static final UnitTransFunc INSTANCE = new UnitTransFunc(); private static final Collection RESULT = ImmutableList.of(UnitState.getInstance()); - private UnitTransFunc() { - } + private UnitTransFunc() {} public static UnitTransFunc getInstance() { return INSTANCE; } @Override - public Collection getSuccStates(final UnitState state, final Action action, - final UnitPrec prec) { + public Collection getSuccStates( + final UnitState state, final Action action, final UnitPrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); return RESULT; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ArgVisualizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ArgVisualizer.java index 89efd988a5..33666ddbf6 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ArgVisualizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ArgVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/LDGVisualizer.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/LDGVisualizer.kt index 4ee2553a90..09329248b7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/LDGVisualizer.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/LDGVisualizer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeCacheVisualizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeCacheVisualizer.java index b3fe19d596..e7b780806a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeCacheVisualizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeCacheVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.analysis.utils; +import static hu.bme.mit.theta.common.visualization.Alignment.LEFT; +import static hu.bme.mit.theta.common.visualization.Shape.RECTANGLE; + import com.google.common.base.Preconditions; import hu.bme.mit.delta.java.mdd.MddNode; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.MddExpressionRepresentation; @@ -23,16 +26,12 @@ import hu.bme.mit.theta.common.visualization.Graph; import hu.bme.mit.theta.common.visualization.LineStyle; import hu.bme.mit.theta.common.visualization.NodeAttributes; - import java.awt.*; import java.util.IdentityHashMap; import java.util.Map; import java.util.Set; import java.util.function.Function; -import static hu.bme.mit.theta.common.visualization.Alignment.LEFT; -import static hu.bme.mit.theta.common.visualization.Shape.RECTANGLE; - public class MddNodeCacheVisualizer { private static final LineStyle CHILD_EDGE_STYLE = LineStyle.NORMAL; @@ -51,13 +50,13 @@ public class MddNodeCacheVisualizer { public static long idFor(MddNode n) { Long l = registry.get(n); - if (l == null) - registry.put(n, l = nextId++); + if (l == null) registry.put(n, l = nextId++); return l; } private static class LazyHolderDefault { - static final MddNodeCacheVisualizer INSTANCE = new MddNodeCacheVisualizer(n -> n.toString()); + static final MddNodeCacheVisualizer INSTANCE = + new MddNodeCacheVisualizer(n -> n.toString()); } private static class LazyHolderStructureOnly { @@ -68,8 +67,7 @@ public MddNodeCacheVisualizer(final Function nodeToString) { this.nodeToString = nodeToString; } - public static MddNodeCacheVisualizer create( - final Function nodeToString) { + public static MddNodeCacheVisualizer create(final Function nodeToString) { return new MddNodeCacheVisualizer(nodeToString); } @@ -91,8 +89,7 @@ public Graph visualize(final MddNode rootNode) { return graph; } - private void traverse(final Graph graph, final MddNode node, - final Set traversed) { + private void traverse(final Graph graph, final MddNode node, final Set traversed) { if (traversed.contains(node)) { return; } else { @@ -102,11 +99,19 @@ private void traverse(final Graph graph, final MddNode node, final LineStyle lineStyle = CHILD_EDGE_STYLE; final int peripheries = 1; -// final int peripheries = node.isComplete()?2:1; - - final NodeAttributes nAttributes = NodeAttributes.builder().label(nodeToString.apply(node)) - .alignment(LEFT).shape(RECTANGLE).font(FONT).fillColor(FILL_COLOR).lineColor(LINE_COLOR) - .peripheries(peripheries).lineStyle(lineStyle).build(); + // final int peripheries = node.isComplete()?2:1; + + final NodeAttributes nAttributes = + NodeAttributes.builder() + .label(nodeToString.apply(node)) + .alignment(LEFT) + .shape(RECTANGLE) + .font(FONT) + .fillColor(FILL_COLOR) + .lineColor(LINE_COLOR) + .peripheries(peripheries) + .lineStyle(lineStyle) + .build(); graph.addNode(nodeId, nAttributes); @@ -116,29 +121,42 @@ private void traverse(final Graph graph, final MddNode node, final String sourceId = NODE_ID_PREFIX + idFor(node); final String targetId = NODE_ID_PREFIX + idFor(defaultValue); - final EdgeAttributes eAttributes = EdgeAttributes.builder() - .alignment(LEFT).font(FONT).color(LINE_COLOR).lineStyle(DEFAULT_EDGE_STYLE).build(); + final EdgeAttributes eAttributes = + EdgeAttributes.builder() + .alignment(LEFT) + .font(FONT) + .color(LINE_COLOR) + .lineStyle(DEFAULT_EDGE_STYLE) + .build(); graph.addEdge(sourceId, targetId, eAttributes); } else { if (!(node.isTerminal())) { var representation = node.getRepresentation(); Preconditions.checkState(representation instanceof MddExpressionRepresentation); var expressionRepresentation = (MddExpressionRepresentation) representation; - for (var cursor = expressionRepresentation.getExplicitRepresentation().getCacheView().cursor(); cursor.moveNext(); ) { + for (var cursor = + expressionRepresentation + .getExplicitRepresentation() + .getCacheView() + .cursor(); + cursor.moveNext(); ) { if (cursor.value() != null) { traverse(graph, cursor.value(), traversed); final String sourceId = NODE_ID_PREFIX + idFor(node); final String targetId = NODE_ID_PREFIX + idFor(cursor.value()); - final EdgeAttributes eAttributes = EdgeAttributes.builder().label(cursor.key() + "") - .alignment(LEFT).font(FONT).color(LINE_COLOR).lineStyle(CHILD_EDGE_STYLE).build(); + final EdgeAttributes eAttributes = + EdgeAttributes.builder() + .label(cursor.key() + "") + .alignment(LEFT) + .font(FONT) + .color(LINE_COLOR) + .lineStyle(CHILD_EDGE_STYLE) + .build(); graph.addEdge(sourceId, targetId, eAttributes); } - } } } - } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeVisualizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeVisualizer.java index bf348b1e32..9e53946463 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeVisualizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/MddNodeVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ProofVisualizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ProofVisualizer.java index 954604871d..a3056ab208 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ProofVisualizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/ProofVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/TraceVisualizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/TraceVisualizer.java index f23ebdf8c4..62d63f9a83 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/TraceVisualizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/utils/TraceVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,6 @@ */ package hu.bme.mit.theta.analysis.utils; -import java.awt.Color; -import java.util.Collection; -import java.util.Map; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.Trace; @@ -28,6 +23,10 @@ import hu.bme.mit.theta.common.visualization.Graph; import hu.bme.mit.theta.common.visualization.LineStyle; import hu.bme.mit.theta.common.visualization.NodeAttributes; +import java.awt.Color; +import java.util.Collection; +import java.util.Map; +import java.util.function.Function; public final class TraceVisualizer { @@ -43,13 +42,12 @@ public final class TraceVisualizer { private static class LazyHolder { - static final TraceVisualizer DEFAULT = new TraceVisualizer<>( - s -> s.toString(), - a -> a.toString()); + static final TraceVisualizer DEFAULT = + new TraceVisualizer<>(s -> s.toString(), a -> a.toString()); } - public TraceVisualizer(final Function stateToString, - final Function actionToString) { + public TraceVisualizer( + final Function stateToString, final Function actionToString) { this.stateToString = stateToString; this.actionToString = actionToString; } @@ -62,16 +60,23 @@ public Graph visualize(final Trace trace) { final Graph graph = new Graph(TRACE_ID, TRACE_LABEL); for (int i = 0; i < trace.getStates().size(); ++i) { - final NodeAttributes nAttributes = NodeAttributes.builder() - .label(stateToString.apply(trace.getState(i))) - .fillColor(FILL_COLOR).lineColor(LINE_COLOR).lineStyle(LINE_STYLE).build(); + final NodeAttributes nAttributes = + NodeAttributes.builder() + .label(stateToString.apply(trace.getState(i))) + .fillColor(FILL_COLOR) + .lineColor(LINE_COLOR) + .lineStyle(LINE_STYLE) + .build(); graph.addNode(STATE_ID_PREFIX + i, nAttributes); } for (int i = 0; i < trace.getActions().size(); ++i) { - final EdgeAttributes eAttributes = EdgeAttributes.builder() - .label(actionToString.apply(trace.getAction(i))) - .color(LINE_COLOR).lineStyle(LINE_STYLE).build(); + final EdgeAttributes eAttributes = + EdgeAttributes.builder() + .label(actionToString.apply(trace.getAction(i))) + .color(LINE_COLOR) + .lineStyle(LINE_STYLE) + .build(); graph.addEdge(STATE_ID_PREFIX + i, STATE_ID_PREFIX + (i + 1), eAttributes); } @@ -88,9 +93,13 @@ public Graph visualizeMerged( for (final S state : trace.getStates()) { if (!stateIds.containsKey(state)) { stateIds.put(state, STATE_ID_PREFIX + stateIds.size()); - final NodeAttributes nAttributes = NodeAttributes.builder() - .label(stateToString.apply(state)) - .fillColor(FILL_COLOR).lineColor(LINE_COLOR).lineStyle(LINE_STYLE).build(); + final NodeAttributes nAttributes = + NodeAttributes.builder() + .label(stateToString.apply(state)) + .fillColor(FILL_COLOR) + .lineColor(LINE_COLOR) + .lineStyle(LINE_STYLE) + .build(); graph.addNode(stateIds.get(state), nAttributes); } } @@ -104,9 +113,12 @@ public Graph visualizeMerged( final S source = trace.getState(i); final S target = trace.getState(i + 1); final Color color = Color.getHSBColor(traceNo / (float) traces.size(), 1, 1); - final EdgeAttributes eAttributes = EdgeAttributes.builder() - .label(actionToString.apply(action)) - .color(color).lineStyle(LINE_STYLE).build(); + final EdgeAttributes eAttributes = + EdgeAttributes.builder() + .label(actionToString.apply(action)) + .color(color) + .lineStyle(LINE_STYLE) + .build(); graph.addEdge(stateIds.get(source), stateIds.get(target), eAttributes); } ++traceNo; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/FifoWaitlist.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/FifoWaitlist.java index 0788365128..12a4ae2ff7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/FifoWaitlist.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/FifoWaitlist.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,17 +17,14 @@ import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.common.Utils; import java.util.ArrayDeque; import java.util.Collection; import java.util.Collections; import java.util.Queue; import java.util.stream.Stream; -import hu.bme.mit.theta.common.Utils; - -/** - * FIFO (First In First Out) waitlist. Items are removed in the same order as they were added. - */ +/** FIFO (First In First Out) waitlist. Items are removed in the same order as they were added. */ public final class FifoWaitlist implements Waitlist { private final Queue items; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/LifoWaitlist.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/LifoWaitlist.java index daa09a34f5..61674399e7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/LifoWaitlist.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/LifoWaitlist.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,17 +17,14 @@ import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.common.Utils; import java.util.ArrayDeque; import java.util.Collection; import java.util.Collections; import java.util.Deque; import java.util.stream.Stream; -import hu.bme.mit.theta.common.Utils; - -/** - * LIFO (Last In First Out) waitlist. Items are removed in the reverse order as they were added. - */ +/** LIFO (Last In First Out) waitlist. Items are removed in the reverse order as they were added. */ public final class LifoWaitlist implements Waitlist { private final Deque items; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/PriorityWaitlist.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/PriorityWaitlist.java index 183ea2f19a..4288ff71d4 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/PriorityWaitlist.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/PriorityWaitlist.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators; +import hu.bme.mit.theta.common.Utils; import java.util.Collection; import java.util.Comparator; import java.util.PriorityQueue; import java.util.stream.Stream; -import hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators; -import hu.bme.mit.theta.common.Utils; - /** * Priority waitlist. The least item is always removed based on a comparator or on the natural * ordering (if no comparator is given). @@ -90,7 +89,9 @@ public void clear() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).add(items.comparator()) - .addAll(items).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .add(items.comparator()) + .addAll(items) + .toString(); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/RandomWaitlist.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/RandomWaitlist.java index df0784f043..5bc1682761 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/RandomWaitlist.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/RandomWaitlist.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,6 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.common.Utils; import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -24,11 +25,7 @@ import java.util.Random; import java.util.stream.Stream; -import hu.bme.mit.theta.common.Utils; - -/** - * A waitlist where items are removed in a random order. - */ +/** A waitlist where items are removed in a random order. */ public final class RandomWaitlist implements Waitlist { private final List items; @@ -89,5 +86,4 @@ public void clear() { public String toString() { return Utils.lispStringBuilder(getClass().getSimpleName()).addAll(items).toString(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/Waitlist.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/Waitlist.java index ee1eaf21e5..333ae71d04 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/Waitlist.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/Waitlist.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/package-info.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/package-info.java index e5fde585ca..e6d0cd063e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/package-info.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/waitlist/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ * * @see hu.bme.mit.theta.analysis.waitlist.Waitlist */ - -package hu.bme.mit.theta.analysis.waitlist; \ No newline at end of file +package hu.bme.mit.theta.analysis.waitlist; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BasicDbm.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BasicDbm.java index 5feab9733c..eab98e6392 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BasicDbm.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BasicDbm.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,11 +24,10 @@ import static hu.bme.mit.theta.analysis.zone.DiffBounds.asString; import static java.lang.Math.min; +import hu.bme.mit.theta.common.IntMatrix; import java.util.Arrays; import java.util.function.IntBinaryOperator; -import hu.bme.mit.theta.common.IntMatrix; - final class BasicDbm { private final int nClocks; @@ -269,8 +268,8 @@ void close() { for (int k = 0; k <= nClocks; k++) { for (int i = 0; i <= nClocks; i++) { for (int j = 0; j <= nClocks; j++) { - final int newBound = min(matrix.get(i, j), - add(matrix.get(i, k), matrix.get(k, j))); + final int newBound = + min(matrix.get(i, j), add(matrix.get(i, k), matrix.get(k, j))); if (i == j && newBound < Leq(0)) { matrix.set(0, 0, Leq(-1)); return; @@ -369,5 +368,4 @@ private boolean isClock(final int x) { private boolean isNonZeroClock(final int x) { return x >= 1 && x <= nClocks; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BoundFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BoundFunc.java index f9f0a6af1e..eefa5ce5c0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BoundFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/BoundFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.analysis.zone; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static java.util.stream.Collectors.toList; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.clock.constr.AndConstr; @@ -27,16 +31,11 @@ import hu.bme.mit.theta.core.clock.constr.UnitLtConstr; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static java.util.stream.Collectors.toList; - public final class BoundFunc { private static final int HASH_SEED = 2903; @@ -52,8 +51,9 @@ private BoundFunc(final Builder builder) { varToUpper = builder.varToUpper; } - private BoundFunc(final Map, Integer> varToLower, - final Map, Integer> varToUpper) { + private BoundFunc( + final Map, Integer> varToLower, + final Map, Integer> varToUpper) { this.varToLower = varToLower; this.varToUpper = varToUpper; } @@ -112,11 +112,13 @@ public boolean isLeq(final BoundFunc that) { return isLeq(this.varToLower, that.varToLower) && isLeq(this.varToUpper, that.varToUpper); } - private static boolean isLeq(final Map, Integer> map1, - final Map, Integer> map2) { + private static boolean isLeq( + final Map, Integer> map1, final Map, Integer> map2) { return map1.entrySet().stream() .allMatch( - e1 -> map2.containsKey(e1.getKey()) && e1.getValue() <= map2.get(e1.getKey())); + e1 -> + map2.containsKey(e1.getKey()) + && e1.getValue() <= map2.get(e1.getKey())); } @Override @@ -137,8 +139,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BoundFunc that = (BoundFunc) obj; - return this.varToLower.equals(that.varToLower) && this.varToUpper.equals( - that.varToUpper); + return this.varToLower.equals(that.varToLower) + && this.varToUpper.equals(that.varToUpper); } else { return false; } @@ -146,18 +148,26 @@ public boolean equals(final Object obj) { @Override public String toString() { - final String lowerToString = Utils.lispStringBuilder("L").addAll( - varToLower.entrySet().stream().map(e -> e.getKey().getName() + " <- " + e.getValue()) - .collect(toList())) - .toString(); - - final String UpperToString = Utils.lispStringBuilder("U").addAll( - varToUpper.entrySet().stream().map(e -> e.getKey().getName() + " <- " + e.getValue()) - .collect(toList())) + final String lowerToString = + Utils.lispStringBuilder("L") + .addAll( + varToLower.entrySet().stream() + .map(e -> e.getKey().getName() + " <- " + e.getValue()) + .collect(toList())) + .toString(); + + final String UpperToString = + Utils.lispStringBuilder("U") + .addAll( + varToUpper.entrySet().stream() + .map(e -> e.getKey().getName() + " <- " + e.getValue()) + .collect(toList())) + .toString(); + + return Utils.lispStringBuilder(this.getClass().getSimpleName()) + .add(lowerToString) + .add(UpperToString) .toString(); - - return Utils.lispStringBuilder(this.getClass().getSimpleName()).add(lowerToString) - .add(UpperToString).toString(); } public static final class Builder { @@ -205,13 +215,13 @@ private boolean isBuilt() { } } - private static final class BoundFunctionVarConstrVisitor extends - FailClockConstrVisitor { + private static final class BoundFunctionVarConstrVisitor + extends FailClockConstrVisitor { - private static final BoundFunctionVarConstrVisitor INSTANCE = new BoundFunctionVarConstrVisitor(); + private static final BoundFunctionVarConstrVisitor INSTANCE = + new BoundFunctionVarConstrVisitor(); - private BoundFunctionVarConstrVisitor() { - } + private BoundFunctionVarConstrVisitor() {} @Override public Void visit(final UnitLtConstr constr, final Builder builder) { @@ -260,5 +270,4 @@ public Void visit(final AndConstr constr, final Builder builder) { return null; } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DBM.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DBM.java index bdc7289f3e..b4a01ed643 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DBM.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DBM.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,24 @@ */ package hu.bme.mit.theta.analysis.zone; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.analysis.zone.DiffBounds.*; +import static java.lang.Math.max; +import static java.lang.Math.min; + import com.google.common.collect.Sets; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.clock.constr.*; import hu.bme.mit.theta.core.clock.op.*; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.*; import java.util.function.BiFunction; import java.util.function.IntBinaryOperator; import java.util.function.IntConsumer; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.analysis.zone.DiffBounds.*; -import static java.lang.Math.max; -import static java.lang.Math.min; - final class DBM { private static final IntBinaryOperator ZERO_DBM_VALUES = (x, y) -> Leq(0); @@ -57,11 +56,15 @@ private DBM(final DbmSignature signature, final BasicDbm dbm) { } // TODO replace BiFunction by IntBiFunction - private DBM(final DbmSignature signature, - final BiFunction, ? super VarDecl, ? extends Integer> values) { - this(signature, (final int x, final int y) -> { - return values.apply(signature.getVar(x), signature.getVar(y)); - }); + private DBM( + final DbmSignature signature, + final BiFunction, ? super VarDecl, ? extends Integer> + values) { + this( + signature, + (final int x, final int y) -> { + return values.apply(signature.getVar(x), signature.getVar(y)); + }); } private DBM(final DBM dbm) { @@ -82,8 +85,8 @@ public Collection complement() { if (bound != defaultBound(x, y)) { final int newBound = negate(bound); final DbmSignature newSignature = DbmSignature.over(Arrays.asList(x, y)); - final BiFunction, VarDecl, Integer> newValues = (c1, - c2) -> (c1 == y && c2 == x) ? newBound : defaultBound(c1, c2); + final BiFunction, VarDecl, Integer> newValues = + (c1, c2) -> (c1 == y && c2 == x) ? newBound : defaultBound(c1, c2); final DBM newDBM = new DBM(newSignature, newValues); result.add(newDBM); } @@ -127,11 +130,12 @@ public static DBM intersection(final DBM dbm1, final DBM dbm2) { checkNotNull(dbm2); final DbmSignature signature = DbmSignature.union(dbm1.signature, dbm2.signature); - final BiFunction, VarDecl, Integer> values = (x, y) -> { - final int bound1 = dbm1.getOrDefault(x, y); - final int bound2 = dbm2.getOrDefault(x, y); - return min(bound1, bound2); - }; + final BiFunction, VarDecl, Integer> values = + (x, y) -> { + final int bound1 = dbm1.getOrDefault(x, y); + final int bound2 = dbm2.getOrDefault(x, y); + return min(bound1, bound2); + }; final DBM result = new DBM(signature, values); result.close(); @@ -144,11 +148,12 @@ public static DBM enclosure(final DBM dbm1, final DBM dbm2) { checkNotNull(dbm2); final DbmSignature signature = DbmSignature.union(dbm1.signature, dbm2.signature); - final BiFunction, VarDecl, Integer> values = (x, y) -> { - final int bound1 = dbm1.getOrDefault(x, y); - final int bound2 = dbm2.getOrDefault(x, y); - return max(bound1, bound2); - }; + final BiFunction, VarDecl, Integer> values = + (x, y) -> { + final int bound1 = dbm1.getOrDefault(x, y); + final int bound2 = dbm2.getOrDefault(x, y); + return max(bound1, bound2); + }; final DBM result = new DBM(signature, values); return result; @@ -174,11 +179,12 @@ public static DBM weakInterpolant(final DBM dbmA, final DBM dbmB) { assert dbmB.isClosed(); final DbmSignature interpolantSignature = interpolantSignature(dbmA, dbmB); - final BiFunction, VarDecl, Integer> values = (x, y) -> { - final int bound1 = dbmA.get(x, y); - final int bound2 = dbmB.get(x, y); - return min(bound1, bound2); - }; + final BiFunction, VarDecl, Integer> values = + (x, y) -> { + final int bound1 = dbmA.get(x, y); + final int bound2 = dbmB.get(x, y); + return min(bound1, bound2); + }; final DBM interpolant = new DBM(interpolantSignature, values); final int[] cycle = interpolant.dbm.closeItp(); @@ -243,11 +249,12 @@ public static DBM interpolant(final DBM dbmA, final DBM dbmB) { assert dbmB.isClosed(); final DbmSignature interpolantSignature = interpolantSignature(dbmA, dbmB); - final BiFunction, VarDecl, Integer> values = (x, y) -> { - final int bound1 = dbmA.get(x, y); - final int bound2 = dbmB.get(x, y); - return min(bound1, bound2); - }; + final BiFunction, VarDecl, Integer> values = + (x, y) -> { + final int bound1 = dbmA.get(x, y); + final int bound2 = dbmB.get(x, y); + return min(bound1, bound2); + }; final DBM interpolant = new DBM(interpolantSignature, values); final int[] cycle = interpolant.dbm.closeItp(); @@ -275,7 +282,8 @@ public static DBM interpolant(final DBM dbmA, final DBM dbmB) { return result; } - private static DbmSignature signatureFrom(final DbmSignature interpolantSignature, final int[] cycle) { + private static DbmSignature signatureFrom( + final DbmSignature interpolantSignature, final int[] cycle) { final Collection> vars = new ArrayList<>(); for (int i = 0; i + 1 < cycle.length; i++) { final VarDecl varDecl = interpolantSignature.getVar(cycle[i]); @@ -285,9 +293,10 @@ private static DbmSignature signatureFrom(final DbmSignature interpolantSignatur } private static DbmSignature interpolantSignature(final DBM dbmA, final DBM dbmB) { - final Set> varsConstrainedByBothDBMS = Sets - .intersection(dbmA.signature.toSet(), dbmB.signature.toSet()).stream() - .filter(c -> dbmA.constrains(c) && dbmB.constrains(c)).collect(Collectors.toSet()); + final Set> varsConstrainedByBothDBMS = + Sets.intersection(dbmA.signature.toSet(), dbmB.signature.toSet()).stream() + .filter(c -> dbmA.constrains(c) && dbmB.constrains(c)) + .collect(Collectors.toSet()); return DbmSignature.over(varsConstrainedByBothDBMS); } @@ -346,7 +355,8 @@ public boolean isSatisfied(final ClockConstr constr) { } public DbmRelation getRelation(final DBM that) { - final Set> vars = Sets.union(this.signature.toSet(), that.signature.toSet()); + final Set> vars = + Sets.union(this.signature.toSet(), that.signature.toSet()); boolean leq = true; boolean geq = true; @@ -361,21 +371,22 @@ public DbmRelation getRelation(final DBM that) { } public boolean isLeq(final DBM that) { - final Set> vars = Sets.union(this.signature.toSet(), that.signature.toSet()); + final Set> vars = + Sets.union(this.signature.toSet(), that.signature.toSet()); for (final VarDecl x : vars) { for (final VarDecl y : vars) { if (this.getOrDefault(x, y) > that.getOrDefault(x, y)) { return false; } - } } return true; } public boolean isLeq(final DBM that, final Collection> activeVars) { - final Set> vars = Sets.union(this.signature.toSet(), that.signature.toSet()); + final Set> vars = + Sets.union(this.signature.toSet(), that.signature.toSet()); for (final VarDecl x : vars) { if (!activeVars.contains(x)) { @@ -390,14 +401,14 @@ public boolean isLeq(final DBM that, final Collection if (this.getOrDefault(x, y) > that.getOrDefault(x, y)) { return false; } - } } return true; } public boolean isLeq(final DBM that, final BoundFunc bound) { - final Set> vars = Sets.union(this.signature.toSet(), that.signature.toSet()); + final Set> vars = + Sets.union(this.signature.toSet(), that.signature.toSet()); if (!this.isConsistent()) { return true; @@ -575,7 +586,8 @@ private void ifTracks(final VarDecl varDecl, final IntConsumer consumer } } - private void ifTracksElse(final VarDecl varDecl, final IntConsumer consumer, final Procedure procedure) { + private void ifTracksElse( + final VarDecl varDecl, final IntConsumer consumer, final Procedure procedure) { if (tracks(varDecl)) { final int x = signature.indexOf(varDecl); consumer.accept(x); @@ -599,8 +611,7 @@ private static final class ExecuteVisitor implements ClockOpVisitor { private static final ExecuteVisitor INSTANCE = new ExecuteVisitor(); - private ExecuteVisitor() { - } + private ExecuteVisitor() {} @Override public Void visit(final CopyOp op, final DBM dbm) { @@ -631,7 +642,6 @@ public Void visit(final ShiftOp op, final DBM dbm) { dbm.shift(op.getVar(), op.getOffset()); return null; } - } //// @@ -640,8 +650,7 @@ private static final class AndOperationVisitor implements ClockConstrVisitor> { @@ -43,7 +40,8 @@ private DbmSignature(final Iterable> varDecls) { checkNotNull(varDecls); final ImmutableList.Builder> indexToVarBuilder = ImmutableList.builder(); - final ImmutableMap.Builder, Integer> varToIndexBuilder = ImmutableMap.builder(); + final ImmutableMap.Builder, Integer> varToIndexBuilder = + ImmutableMap.builder(); final Set> addedVars = Containers.createSet(); @@ -76,12 +74,12 @@ public static DbmSignature union(final DbmSignature signature1, final DbmSignatu return new DbmSignature(vars); } - public static DbmSignature intersection(final DbmSignature signature1, - final DbmSignature signature2) { + public static DbmSignature intersection( + final DbmSignature signature1, final DbmSignature signature2) { checkNotNull(signature1); checkNotNull(signature2); - final Set> vars = Sets.intersection(signature1.toSet(), - signature2.toSet()); + final Set> vars = + Sets.intersection(signature1.toSet(), signature2.toSet()); return new DbmSignature(vars); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DiffBounds.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DiffBounds.java index 6d3f72e96a..1f8fb18d79 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DiffBounds.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/DiffBounds.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,8 +29,7 @@ final class DiffBounds { private static final String INF_STRING = "inf"; - private DiffBounds() { - } + private DiffBounds() {} public static int Inf() { return INF; @@ -50,8 +49,8 @@ public static int Leq(final int m) { //// - public static ClockConstr toConstr(final VarDecl leftVar, - final VarDecl rightVar, final int b) { + public static ClockConstr toConstr( + final VarDecl leftVar, final VarDecl rightVar, final int b) { checkNotNull(leftVar); checkNotNull(rightVar); @@ -95,7 +94,6 @@ public static ClockConstr toConstr(final VarDecl leftVar, } } } - } //// @@ -142,5 +140,4 @@ private static String finiteBoundAsString(final int b) { sb.append(')'); return sb.toString(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZeroVar.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZeroVar.java index 19a60daf8d..43e46c707e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZeroVar.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZeroVar.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,11 +25,9 @@ final class ZeroVar { private static final VarDecl ZERO_VAR = Var("_zero", Rat()); - private ZeroVar() { - } + private ZeroVar() {} static VarDecl getInstance() { return ZERO_VAR; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneLattice.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneLattice.java index 3fec5d26ba..5f3272134b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneLattice.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneLattice.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneOrd.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneOrd.java index d2135790f2..e7c5e8b845 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneOrd.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,8 +21,7 @@ public final class ZoneOrd implements PartialOrd { private static final ZoneOrd INSTANCE = new ZoneOrd(); - private ZoneOrd() { - } + private ZoneOrd() {} public static ZoneOrd getInstance() { return INSTANCE; @@ -32,5 +31,4 @@ public static ZoneOrd getInstance() { public boolean isLeq(final ZoneState state1, final ZoneState state2) { return state1.isLeq(state2); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZonePrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZonePrec.java index 97a92902fd..0a2ffa3ba2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZonePrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZonePrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.analysis.zone; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - public final class ZonePrec implements Prec { private final Set> clocks; @@ -68,7 +67,8 @@ public int hashCode() { @Override public Collection> getUsedVars() { // This could be way more elegant - return clocks.stream().map(ratTypeVarDecl -> (VarDecl) ratTypeVarDecl) + return clocks.stream() + .map(ratTypeVarDecl -> (VarDecl) ratTypeVarDecl) .collect(Collectors.toSet()); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneState.java index 67ef7dc716..9b1d3154d6 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/zone/ZoneState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,13 @@ */ package hu.bme.mit.theta.analysis.zone; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Eq; +import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Gt; +import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Lt; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.Iterables; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; @@ -26,19 +33,11 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.rattype.RatLitExpr; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.math.BigInteger; import java.util.Collection; import java.util.Collections; import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Eq; -import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Gt; -import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Lt; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; -import static java.util.stream.Collectors.toList; - public final class ZoneState implements ExprState { private static final ZoneState TOP = new ZoneState(DBM.top(Collections.emptySet())); @@ -61,11 +60,11 @@ private ZoneState(final Builder ops) { //// - public static ZoneState region(final Valuation valuation, - final Collection> vars) { + public static ZoneState region( + final Valuation valuation, final Collection> vars) { checkNotNull(valuation); - final Iterable> constrainedVars = Iterables.filter(vars, - v -> valuation.eval(v).isPresent()); + final Iterable> constrainedVars = + Iterables.filter(vars, v -> valuation.eval(v).isPresent()); final DBM dbm = DBM.top(constrainedVars); @@ -167,8 +166,8 @@ public boolean isLeq(final ZoneState that) { return this.dbm.isLeq(that.dbm); } - public boolean isLeq(final ZoneState that, - final Collection> activeVars) { + public boolean isLeq( + final ZoneState that, final Collection> activeVars) { return this.dbm.isLeq(that.dbm, activeVars); } @@ -186,9 +185,8 @@ public boolean isConsistentWith(final ZoneState that) { public Expr toExpr() { Expr result = expr; if (result == null) { - final Collection> exprs = dbm.getConstrs().stream() - .map(ClockConstr::toExpr) - .collect(toList()); + final Collection> exprs = + dbm.getConstrs().stream().map(ClockConstr::toExpr).collect(toList()); result = And(exprs); expr = result; } @@ -223,7 +221,9 @@ public boolean equals(final Object obj) { @Override public String toString() { final Collection constrs = dbm.getConstrs(); - return Utils.lispStringBuilder(getClass().getSimpleName()).aligned().addAll(constrs) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .aligned() + .addAll(constrs) .toString(); } @@ -243,8 +243,8 @@ private static Builder transform(final ZoneState state) { return new Builder(DBM.copyOf(state.dbm)); } - private static Builder project(final ZoneState state, - final Collection> clocks) { + private static Builder project( + final ZoneState state, final Collection> clocks) { return new Builder(DBM.project(state.dbm, clocks)); } @@ -306,5 +306,4 @@ public Builder norm(final Map, ? extends Integer> cei return this; } } - } diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisSide.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisSide.kt index a3ae64e966..862bfe6a7d 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisSide.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisSide.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.multi import hu.bme.mit.theta.analysis.* -data class MultiAnalysisSide( - val analysis: Analysis, - val controlInitFunc: InitFunc, - val combineStates: (ControlS, DataS) -> S, - val extractControlState: (S) -> ControlS, - val extractDataState: (S) -> DataS, - val extractControlPrec: (P) -> ControlP +data class MultiAnalysisSide< + S : State, + DataS : State, + ControlS : State, + A : Action, + P : Prec, + ControlP : Prec, +>( + val analysis: Analysis, + val controlInitFunc: InitFunc, + val combineStates: (ControlS, DataS) -> S, + val extractControlState: (S) -> ControlS, + val extractDataState: (S) -> DataS, + val extractControlPrec: (P) -> ControlP, ) 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 24aac111a1..506b2e6628 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 56d469471d..7142d974fb 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 6da7f84e06..ada29e08fa 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 3b4ec4b3f0..23b224ae2e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 63284de417..a0b789b4b9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilder.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilder.kt index 361e3f2182..26a81de9ca 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilder.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.multi.builder.stmt import hu.bme.mit.theta.analysis.LTS @@ -22,13 +21,26 @@ import hu.bme.mit.theta.analysis.expr.ExprState import hu.bme.mit.theta.analysis.expr.StmtAction import hu.bme.mit.theta.analysis.multi.MultiAnalysisSide -class StmtMultiBuilder( - private val side: MultiAnalysisSide, - private val lts: LTS +class StmtMultiBuilder< + LState : ExprState, + LControl : ExprState, + LAction : StmtAction, + DataState : ExprState, + LPrec : Prec, + LControlPrec : Prec, +>( + private val side: MultiAnalysisSide, + private val lts: LTS, ) { - fun addRightSide( - side: MultiAnalysisSide, - lts: LTS - ) = StmtMultiBuilderPair(this.side, this.lts, side, lts) + fun < + RState : ExprState, + RControl : ExprState, + RAction : StmtAction, + RPrec : Prec, + RControlPrec : Prec, + > addRightSide( + side: MultiAnalysisSide, + lts: LTS, + ) = StmtMultiBuilderPair(this.side, this.lts, side, lts) } diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/MultiConfig.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/MultiConfig.kt index 74ce991c0a..fadc7e8e01 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/MultiConfig.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/MultiConfig.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.multi.config import hu.bme.mit.theta.analysis.Action @@ -28,14 +27,21 @@ import hu.bme.mit.theta.analysis.multi.MultiPrec import hu.bme.mit.theta.analysis.multi.MultiState class MultiConfig< - DataState : State, LControl : State, RControl : State, - LAction : Action, RAction : Action, - LPrec : Prec, RPrec : Prec, DataPrec : Prec, - MState : MultiState, - MAction : MultiAction>( - val checker: SafetyChecker, Trace, MultiPrec>, - val initPrec: MultiPrec + DataState : State, + LControl : State, + RControl : State, + LAction : Action, + RAction : Action, + LPrec : Prec, + RPrec : Prec, + DataPrec : Prec, + MState : MultiState, + MAction : MultiAction, +>( + val checker: + SafetyChecker, Trace, MultiPrec>, + val initPrec: MultiPrec, ) { - fun check(): SafetyResult, Trace> = checker.check(initPrec) -} \ No newline at end of file + fun check(): SafetyResult, Trace> = checker.check(initPrec) +} diff --git a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/StmtMultiConfigBuilder.kt b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/StmtMultiConfigBuilder.kt index e0d8173455..9fad2364d2 100644 --- a/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/StmtMultiConfigBuilder.kt +++ b/subprojects/common/analysis/src/main/kotlin/hu/bme/mit/theta/analysis/multi/config/StmtMultiConfigBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/TraceTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/TraceTest.java index 2534fb1a13..f226d3f100 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/TraceTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/TraceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,11 +17,10 @@ import static com.google.common.collect.ImmutableList.of; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.analysis.stubs.ActionStub; import hu.bme.mit.theta.analysis.stubs.StateStub; +import org.junit.Assert; +import org.junit.Test; public class TraceTest { 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 c02a0756a7..4820edd81a 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprActionStub.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprActionStub.java index e08077c705..39e059a9e8 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprActionStub.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprActionStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm; import hu.bme.mit.theta.analysis.expr.StmtAction; import hu.bme.mit.theta.core.stmt.Stmt; - import java.util.List; class ExprActionStub extends StmtAction { diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprStateStub.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprStateStub.java index 8b9bc7eb5c..cad1420725 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprStateStub.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/ExprStateStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm; import hu.bme.mit.theta.analysis.expr.ExprState; diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/HornTest.kt b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/HornTest.kt index c0eee6f1f3..376bb714d4 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/HornTest.kt +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/HornTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm import hu.bme.mit.theta.analysis.algorithm.chc.HornChecker @@ -30,33 +29,33 @@ import org.junit.jupiter.api.Test class HornTest { - @Test - fun testHornUnsafe() { - Assumptions.assumeTrue(OsHelper.getOs().equals(OsHelper.OperatingSystem.LINUX)); - - val inv = Relation("inv", Int()) - val p0 = Param("P0", Int()) - val p1 = Param("P1", Int()) - inv(p0.ref) += Eq(p0.ref, Int(0)) - inv(p1.ref) += inv(p0.ref).expr + Eq(p1.ref, Add(p0.ref, Int(1))) - !(inv(p0.ref) with Eq(p0.ref, Int(5))) - - val checker = HornChecker(listOf(inv), Z3SolverFactory.getInstance(), NullLogger.getInstance()) - Assertions.assertTrue(checker.check().isUnsafe) - } - - @Test - fun testHornSafe() { - Assumptions.assumeTrue(OsHelper.getOs().equals(OsHelper.OperatingSystem.LINUX)); - - val inv = Relation("inv", Int()) - val p0 = Param("P0", Int()) - val p1 = Param("P1", Int()) - inv(p0.ref) += Eq(p0.ref, Int(0)) - inv(p1.ref) += inv(p0.ref).expr + Eq(p1.ref, Add(p0.ref, Int(2))) - !(inv(p0.ref) with Eq(p0.ref, Int(5))) - - val checker = HornChecker(listOf(inv), Z3SolverFactory.getInstance(), NullLogger.getInstance()) - Assertions.assertTrue(checker.check().isSafe) - } -} \ No newline at end of file + @Test + fun testHornUnsafe() { + Assumptions.assumeTrue(OsHelper.getOs().equals(OsHelper.OperatingSystem.LINUX)) + + val inv = Relation("inv", Int()) + val p0 = Param("P0", Int()) + val p1 = Param("P1", Int()) + inv(p0.ref) += Eq(p0.ref, Int(0)) + inv(p1.ref) += inv(p0.ref).expr + Eq(p1.ref, Add(p0.ref, Int(1))) + !(inv(p0.ref) with Eq(p0.ref, Int(5))) + + val checker = HornChecker(listOf(inv), Z3SolverFactory.getInstance(), NullLogger.getInstance()) + Assertions.assertTrue(checker.check().isUnsafe) + } + + @Test + fun testHornSafe() { + Assumptions.assumeTrue(OsHelper.getOs().equals(OsHelper.OperatingSystem.LINUX)) + + val inv = Relation("inv", Int()) + val p0 = Param("P0", Int()) + val p1 = Param("P1", Int()) + inv(p0.ref) += Eq(p0.ref, Int(0)) + inv(p1.ref) += inv(p0.ref).expr + Eq(p1.ref, Add(p0.ref, Int(2))) + !(inv(p0.ref) with Eq(p0.ref, Int(5))) + + val checker = HornChecker(listOf(inv), Z3SolverFactory.getInstance(), NullLogger.getInstance()) + Assertions.assertTrue(checker.check().isSafe) + } +} diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgCexTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgCexTest.java index 63c3c25212..febb0ba0f5 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgCexTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgCexTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,6 @@ */ package hu.bme.mit.theta.analysis.algorithm.arg; -import java.util.List; -import java.util.stream.Collectors; - -import hu.bme.mit.theta.analysis.algorithm.arg.ARG; -import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; @@ -30,11 +22,10 @@ import hu.bme.mit.theta.analysis.stubs.ActionStub; import hu.bme.mit.theta.analysis.stubs.PartialOrdStub; import hu.bme.mit.theta.analysis.stubs.StateStub; -import org.junit.Assert; -import org.junit.Test; - import java.util.List; import java.util.stream.Collectors; +import org.junit.Assert; +import org.junit.Test; public class ArgCexTest { @@ -59,8 +50,8 @@ public void test() { final ArgNode n4 = arg.createSuccNode(n2, act, s4, true); final ArgNode n5 = arg.createSuccNode(n2, act, s5, false); final ArgNode n6 = arg.createSuccNode(n3, act, s6, false); - @SuppressWarnings("unused") final ArgNode n7 = arg.createSuccNode(n3, act, - s7, true); + @SuppressWarnings("unused") + final ArgNode n7 = arg.createSuccNode(n3, act, s7, true); final ArgNode n8 = arg.createSuccNode(n5, act, s8, true); n6.setCoveringNode(n2); @@ -69,14 +60,13 @@ public void test() { Assert.assertEquals(8, arg.getNodes().count()); Assert.assertEquals(2, arg.getUnsafeNodes().count()); - final List> cexs = arg.getCexs().map(e -> e.toTrace()) - .collect(Collectors.toList()); + final List> cexs = + arg.getCexs().map(e -> e.toTrace()).collect(Collectors.toList()); Assert.assertEquals(2, cexs.size()); Assert.assertTrue( cexs.contains(Trace.of(ImmutableList.of(s1, s2, s4), ImmutableList.of(act, act)))); Assert.assertTrue( cexs.contains(Trace.of(ImmutableList.of(s1, s3, s7), ImmutableList.of(act, act)))); - } } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparatorsTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparatorsTest.java index fc575df02b..d4e3f8a660 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparatorsTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgNodeComparatorsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,7 @@ */ package hu.bme.mit.theta.analysis.algorithm.arg; +import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.*; import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.bfs; import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.combine; import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.creationAsc; @@ -22,26 +23,15 @@ import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.dfs; import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.targetFirst; -import java.util.List; -import java.util.stream.Collectors; - -import hu.bme.mit.theta.analysis.algorithm.arg.ARG; -import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.stubs.ActionStub; import hu.bme.mit.theta.analysis.stubs.PartialOrdStub; import hu.bme.mit.theta.analysis.stubs.StateStub; -import org.junit.Assert; -import org.junit.Test; - import java.util.List; import java.util.stream.Collectors; - -import static hu.bme.mit.theta.analysis.algorithm.arg.ArgNodeComparators.*; +import org.junit.Assert; +import org.junit.Test; public class ArgNodeComparatorsTest { @@ -49,45 +39,45 @@ public class ArgNodeComparatorsTest { private final Action act = new ActionStub("A"); private final ArgNode s0 = arg.createInitNode(new StateStub("s0"), false); - private final ArgNode s10 = arg.createSuccNode(s0, act, new StateStub("s10"), - false); - private final ArgNode s20 = arg.createSuccNode(s10, act, new StateStub("s20"), - true); - private final ArgNode s21 = arg.createSuccNode(s10, act, new StateStub("s21"), - false); - private final ArgNode s11 = arg.createSuccNode(s0, act, new StateStub("s11"), - true); - private final ArgNode s12 = arg.createSuccNode(s0, act, new StateStub("s12"), - false); + private final ArgNode s10 = + arg.createSuccNode(s0, act, new StateStub("s10"), false); + private final ArgNode s20 = + arg.createSuccNode(s10, act, new StateStub("s20"), true); + private final ArgNode s21 = + arg.createSuccNode(s10, act, new StateStub("s21"), false); + private final ArgNode s11 = + arg.createSuccNode(s0, act, new StateStub("s11"), true); + private final ArgNode s12 = + arg.createSuccNode(s0, act, new StateStub("s12"), false); private final List> nodes = arg.getNodes().collect(Collectors.toList()); @Test public void testBfs() { nodes.sort(bfs()); - Assert.assertArrayEquals(new ArgNode[]{s0, s10, s11, s12, s20, s21}, nodes.toArray()); + Assert.assertArrayEquals(new ArgNode[] {s0, s10, s11, s12, s20, s21}, nodes.toArray()); } @Test public void testDfs() { nodes.sort(dfs()); - Assert.assertArrayEquals(new ArgNode[]{s20, s21, s10, s11, s12, s0}, nodes.toArray()); + Assert.assertArrayEquals(new ArgNode[] {s20, s21, s10, s11, s12, s0}, nodes.toArray()); } @Test public void testCreationAsc() { nodes.sort(creationAsc()); - Assert.assertArrayEquals(new ArgNode[]{s0, s10, s20, s21, s11, s12}, nodes.toArray()); + Assert.assertArrayEquals(new ArgNode[] {s0, s10, s20, s21, s11, s12}, nodes.toArray()); } @Test public void testCreationDesc() { nodes.sort(creationDesc()); - Assert.assertArrayEquals(new ArgNode[]{s12, s11, s21, s20, s10, s0}, nodes.toArray()); + Assert.assertArrayEquals(new ArgNode[] {s12, s11, s21, s20, s10, s0}, nodes.toArray()); } @Test public void testTargetFirst() { nodes.sort(combine(targetFirst(), creationAsc())); - Assert.assertArrayEquals(new ArgNode[]{s20, s11, s0, s10, s21, s12}, nodes.toArray()); + Assert.assertArrayEquals(new ArgNode[] {s20, s11, s0, s10, s21, s12}, nodes.toArray()); } } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgPruningTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgPruningTest.java index 2f119ffdc9..36a92387ac 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgPruningTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgPruningTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,10 +18,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import hu.bme.mit.theta.analysis.algorithm.arg.ARG; -import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; -import org.junit.Test; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.stubs.ActionStub; @@ -31,9 +27,6 @@ import hu.bme.mit.theta.common.visualization.writer.GraphvizWriter; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - public class ArgPruningTest { @Test @@ -69,7 +62,8 @@ public void test() { assertEquals(2, n0.getCoveredNodes().count()); System.out.println( - GraphvizWriter.getInstance().writeString(ArgVisualizer.getDefault().visualize(arg))); + GraphvizWriter.getInstance() + .writeString(ArgVisualizer.getDefault().visualize(arg))); System.out.println("========================="); arg.prune(n00); @@ -83,6 +77,7 @@ public void test() { assertFalse(n02.getCoveringNode().isPresent()); System.out.println( - GraphvizWriter.getInstance().writeString(ArgVisualizer.getDefault().visualize(arg))); + GraphvizWriter.getInstance() + .writeString(ArgVisualizer.getDefault().visualize(arg))); } } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEqualityTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEqualityTest.java index 6a4f2990f4..ef94f8647b 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEqualityTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgStructuralEqualityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -30,20 +30,14 @@ private static ARG createArg(boolean variant) { Action act = new ActionStub("A"); ArgNode s0 = arg.createInitNode(new StateStub("s0"), false); - ArgNode s10 = arg.createSuccNode(s0, act, new StateStub("s10"), - false); - ArgNode s20 = arg.createSuccNode(s10, act, new StateStub("s20"), - true); - ArgNode s21 = arg.createSuccNode(s10, act, new StateStub("s21"), - false); - ArgNode s11 = arg.createSuccNode(s0, act, new StateStub("s11"), - true); + ArgNode s10 = arg.createSuccNode(s0, act, new StateStub("s10"), false); + ArgNode s20 = arg.createSuccNode(s10, act, new StateStub("s20"), true); + ArgNode s21 = arg.createSuccNode(s10, act, new StateStub("s21"), false); + ArgNode s11 = arg.createSuccNode(s0, act, new StateStub("s11"), true); if (variant) { - ArgNode s12a = arg.createSuccNode(s0, act, new StateStub("s12a"), - false); + ArgNode s12a = arg.createSuccNode(s0, act, new StateStub("s12a"), false); } else { - ArgNode s12b = arg.createSuccNode(s0, act, new StateStub("s12b"), - false); + ArgNode s12b = arg.createSuccNode(s0, act, new StateStub("s12b"), false); } return arg; } @@ -66,8 +60,13 @@ public void testARGHashCode() { var arg3 = createArg(false); Assert.assertNotEquals("Reference-based hashcode", arg1.hashCode(), arg2.hashCode()); - Assert.assertEquals("Structural hashcode (true)", ArgStructuralEquality.hashCode(arg1), ArgStructuralEquality.hashCode(arg2)); - Assert.assertNotEquals("Structural hashcode (false)", ArgStructuralEquality.hashCode(arg1), ArgStructuralEquality.hashCode(arg3)); + Assert.assertEquals( + "Structural hashcode (true)", + ArgStructuralEquality.hashCode(arg1), + ArgStructuralEquality.hashCode(arg2)); + Assert.assertNotEquals( + "Structural hashcode (false)", + ArgStructuralEquality.hashCode(arg1), + ArgStructuralEquality.hashCode(arg3)); } - } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGAbstractorCheckingTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGAbstractorCheckingTest.java index 1877a54da8..48fb642ad6 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGAbstractorCheckingTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGAbstractorCheckingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,7 +22,7 @@ import hu.bme.mit.theta.analysis.algorithm.asg.ASG; import hu.bme.mit.theta.analysis.algorithm.cegar.AbstractorResult; import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.ASGAbstractor; -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy; +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy; import hu.bme.mit.theta.analysis.expl.ExplPrec; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.expl.ExplStatePredicate; @@ -119,7 +119,7 @@ private void testWithXsts() throws IOException { analysis, lts, target, - LoopcheckerSearchStrategy.Companion.getDefault(), + LoopCheckerSearchStrategy.Companion.getDefault(), new ConsoleLogger(Logger.Level.DETAIL)); ASG, XstsAction> ASG = new ASG<>(target); AbstractorResult result = abstractor.check(ASG, precision); @@ -146,7 +146,7 @@ private void testWithCfa() throws IOException { analysis, lts, target, - LoopcheckerSearchStrategy.Companion.getDefault(), + LoopCheckerSearchStrategy.Companion.getDefault(), new ConsoleLogger(Logger.Level.DETAIL)); ASG, CfaAction> ASG = new ASG<>(target); AbstractorResult result = abstractor.check(ASG, precision); diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGCegarVerifierTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGCegarVerifierTest.java index 394737ca4a..231a3634be 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGCegarVerifierTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGCegarVerifierTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,7 +24,7 @@ import hu.bme.mit.theta.analysis.algorithm.cegar.CegarChecker; import hu.bme.mit.theta.analysis.algorithm.cegar.Refiner; import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.ASGAbstractor; -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy; +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy; import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy; import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.SingleASGTraceRefiner; import hu.bme.mit.theta.analysis.expr.ExprStatePredicate; @@ -140,7 +140,7 @@ private void testWithXsts() throws IOException { final AcceptancePredicate, XstsAction> target = new AcceptancePredicate<>(statePredicate::test, Unit.INSTANCE); logger.write(Logger.Level.MAINSTEP, "Verifying %s%n", xsts.getProp()); - LoopcheckerSearchStrategy.getEntries() + LoopCheckerSearchStrategy.getEntries() .forEach( lStrat -> { ASGTraceCheckerStrategy.getEntries() @@ -212,7 +212,7 @@ private void testWithCfa() throws IOException { new ItpRefToPredPrec(ExprSplitters.atoms()); final RefutationToGlobalCfaPrec cfaRefToPrec = new RefutationToGlobalCfaPrec<>(refToPrec, cfa.getInitLoc()); - LoopcheckerSearchStrategy.getEntries() + LoopCheckerSearchStrategy.getEntries() .forEach( lStrat -> { ASGTraceCheckerStrategy.getEntries() diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGTraceCheckerTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGTraceCheckerTest.java index b985a309f2..83ca1afaf7 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGTraceCheckerTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ASGTraceCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,7 @@ import hu.bme.mit.theta.analysis.algorithm.asg.ASG; import hu.bme.mit.theta.analysis.algorithm.asg.ASGTrace; import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.ASGAbstractor; -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy; +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy; import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy; import hu.bme.mit.theta.analysis.expr.ExprStatePredicate; import hu.bme.mit.theta.analysis.expr.refinement.ExprTraceStatus; @@ -78,7 +78,7 @@ public void testWithCounter3() throws IOException { analysis, lts, target, - LoopcheckerSearchStrategy.Companion.getDefault(), + LoopCheckerSearchStrategy.Companion.getDefault(), logger); ASG, XstsAction> ASG = new ASG<>(target); abstractor.check(ASG, precision); diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ldg/ASGTraceTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ldg/ASGTraceTest.java index 0abf99ff82..b813c44658 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ldg/ASGTraceTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/ldg/ASGTraceTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/utils/VarCollectorStmtVisitorTest.kt b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/utils/VarCollectorStmtVisitorTest.kt index fa7a141799..86105b2f93 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/utils/VarCollectorStmtVisitorTest.kt +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/utils/VarCollectorStmtVisitorTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCheckerTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCheckerTest.java index d4f5f02b8d..d0f44cb143 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCheckerTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddConstrainedCursorTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddConstrainedCursorTest.java index 26070d5dd4..fb608fc48a 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddConstrainedCursorTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddConstrainedCursorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddExpressionTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddExpressionTest.java index feae90917b..213445528b 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddExpressionTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddExpressionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,17 @@ */ package hu.bme.mit.theta.analysis.algorithm.mdd; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.delta.java.mdd.*; import hu.bme.mit.delta.mdd.MddVariableDescriptor; -import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.ExprLatticeDefinition; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.MddExpressionTemplate; -import hu.bme.mit.theta.analysis.utils.MddNodeVisualizer; -import hu.bme.mit.theta.common.visualization.Graph; -import hu.bme.mit.theta.common.visualization.writer.GraphvizWriter; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.Decls; @@ -30,25 +33,18 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; -import org.junit.Test; - -import java.io.FileNotFoundException; import java.util.Set; - -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.junit.Assert.assertEquals; +import org.junit.Test; public class MddExpressionTest { @Test public void exprNodeTest1() { - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); ConstDecl declX = Decls.Const("x", Int()); @@ -60,7 +56,11 @@ public void exprNodeTest1() { MddVariable x = varOrder.createOnTop(MddVariableDescriptor.create(declX, 0)); // x >= 2 && y = x + 1 && x <= 6 - Expr expr = And(Geq(declX.getRef(), Int(2)), Eq(declY.getRef(), Add(declX.getRef(), Int(1))), Leq(declX.getRef(), Int(6))); + Expr expr = + And( + Geq(declX.getRef(), Int(2)), + Eq(declY.getRef(), Add(declX.getRef(), Int(1))), + Leq(declX.getRef(), Int(6))); SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); MddNode rootNode = x.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); @@ -95,7 +95,8 @@ public void exprNodeTest1() { @Test public void exprNodeTest2() { - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); ConstDecl declA = Decls.Const("a", Bool()); @@ -106,28 +107,25 @@ public void exprNodeTest2() { MddVariable b = varOrder.createOnTop(MddVariableDescriptor.create(declB, 2)); MddVariable a = varOrder.createOnTop(MddVariableDescriptor.create(declA, 2)); - Expr expr = And(Or(declA.getRef(), Not(declB.getRef())), Eq(declX.getRef(), Int(2))); + Expr expr = + And(Or(declA.getRef(), Not(declB.getRef())), Eq(declX.getRef(), Int(2))); SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); MddNode rootNode = a.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); - for (var c = rootNode.cursor(); c.moveNext(); ) { - } + for (var c = rootNode.cursor(); c.moveNext(); ) {} var node2 = rootNode.get(0); - for (var c = node2.cursor(); c.moveNext(); ) { - } + for (var c = node2.cursor(); c.moveNext(); ) {} var node3 = node2.get(0); - for (var c = node3.cursor(); c.moveNext(); ) { - } + for (var c = node3.cursor(); c.moveNext(); ) {} var node4 = rootNode.get(1); - for (var c = node4.cursor(); c.moveNext(); ) { - } + for (var c = node4.cursor(); c.moveNext(); ) {} final Set valuations = MddValuationCollector.collect(rootNode); @@ -140,7 +138,8 @@ public void exprNodeTest3() { // TODO need to fix nodeinterpreters and cursors - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); ConstDecl declX = Decls.Const("x", Int()); @@ -152,7 +151,11 @@ public void exprNodeTest3() { MddVariable x = varOrder.createOnTop(MddVariableDescriptor.create(declX, 0)); // y >= 2 && z = y + 1 && y <= 6 - Expr expr = And(Geq(declY.getRef(), Int(2)), Eq(declZ.getRef(), Add(declY.getRef(), Int(1))), Leq(declY.getRef(), Int(6))); + Expr expr = + And( + Geq(declY.getRef(), Int(2)), + Eq(declZ.getRef(), Add(declY.getRef(), Int(1))), + Leq(declY.getRef(), Int(6))); SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); MddNode rootNode = x.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); @@ -172,13 +175,13 @@ public void exprNodeTest3() { final Set valuations = MddValuationCollector.collect(rootNode); assertEquals(valuations.size(), 5); - } @Test public void exprNodeTest4() { - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); ConstDecl declX = Decls.Const("x", Int()); @@ -189,7 +192,12 @@ public void exprNodeTest4() { MddVariable x = varOrder.createOnTop(MddVariableDescriptor.create(declX, 0)); // x >= 2 && y = x + 1 && x <= 6 && z = y + 2 - Expr expr = And(Geq(declX.getRef(), Int(2)), Eq(declY.getRef(), Add(declX.getRef(), Int(1))), Leq(declX.getRef(), Int(6)), Eq(declZ.getRef(), Add(declY.getRef(), Int(2)))); + Expr expr = + And( + Geq(declX.getRef(), Int(2)), + Eq(declY.getRef(), Add(declX.getRef(), Int(1))), + Leq(declX.getRef(), Int(6)), + Eq(declZ.getRef(), Add(declY.getRef(), Int(2)))); SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); MddNode rootNode = x.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); @@ -219,13 +227,13 @@ public void exprNodeTest4() { final Set valuations = MddValuationCollector.collect(rootNode); assertEquals(valuations.size(), 5); - } @Test public void exprNodeTest5() { - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); ConstDecl declX = Decls.Const("x", Int()); @@ -237,7 +245,10 @@ public void exprNodeTest5() { MddVariable x = varOrder.createOnTop(MddVariableDescriptor.create(declX, 0)); // x = y && y = z && z = 2 - Expr expr = And(Eq(declX.getRef(), declY.getRef()), And(Eq(declY.getRef(), declZ.getRef()), Eq(declZ.getRef(), Int(2)))); + Expr expr = + And( + Eq(declX.getRef(), declY.getRef()), + And(Eq(declY.getRef(), declZ.getRef()), Eq(declZ.getRef(), Int(2)))); SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); MddNode rootNode = x.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); @@ -252,13 +263,13 @@ public void exprNodeTest5() { final Set valuations = MddValuationCollector.collect(rootNode); assertEquals(valuations.size(), 1); - } @Test public void exprNodeTest6() { - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); ConstDecl declX = Decls.Const("x", Int()); @@ -270,7 +281,15 @@ public void exprNodeTest6() { MddVariable x = varOrder.createOnTop(MddVariableDescriptor.create(declX, 0)); // x >= 0 && x <= 2 && y >= x && y <= x + 2 && z >= y && z <= y + 2 - Expr expr = And(And(Geq(declX.getRef(), Int(0)), Leq(declX.getRef(), Int(2))), And(Geq(declY.getRef(), declX.getRef()), Leq(declY.getRef(), Add(declX.getRef(), Int(2)))), And(Geq(declZ.getRef(), declY.getRef()), Leq(declZ.getRef(), Add(declY.getRef(), Int(2))))); + Expr expr = + And( + And(Geq(declX.getRef(), Int(0)), Leq(declX.getRef(), Int(2))), + And( + Geq(declY.getRef(), declX.getRef()), + Leq(declY.getRef(), Add(declX.getRef(), Int(2)))), + And( + Geq(declZ.getRef(), declY.getRef()), + Leq(declZ.getRef(), Add(declY.getRef(), Int(2))))); SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); MddNode rootNode = x.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); @@ -298,7 +317,5 @@ public void exprNodeTest6() { final Set valuations = MddValuationCollector.collect(rootNode); assertEquals(27, valuations.size()); - } - } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddRelProdTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddRelProdTest.java index ffa47d709d..0139033a45 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddRelProdTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddRelProdTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddStateSpaceInfoTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddStateSpaceInfoTest.java index c8086fecd4..692847f652 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddStateSpaceInfoTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddStateSpaceInfoTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplInitFuncTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplInitFuncTest.java index 2852d80cb7..3158def354 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplInitFuncTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplInitFuncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,18 +21,15 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Leq; -import java.util.Collection; - -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.Collection; +import org.junit.Assert; +import org.junit.Test; public class ExplInitFuncTest { @@ -50,24 +47,34 @@ public void test1() { @Test public void test2() { final ExplPrec prec = ExplPrec.of(ImmutableList.of(x, y)); - final ExplInitFunc initFunc = ExplInitFunc.create(solver, - And(Leq(Int(0), x.getRef()), Leq(x.getRef(), Int(5)))); + final ExplInitFunc initFunc = + ExplInitFunc.create(solver, And(Leq(Int(0), x.getRef()), Leq(x.getRef(), Int(5)))); Assert.assertEquals(6, initFunc.getInitStates(prec).size()); } @Test public void test3() { final ExplPrec prec = ExplPrec.of(ImmutableList.of(x, y)); - final ExplInitFunc initFunc = ExplInitFunc.create(solver, - And(Leq(Int(0), x.getRef()), Leq(x.getRef(), y.getRef()), Leq(y.getRef(), Int(3)))); + final ExplInitFunc initFunc = + ExplInitFunc.create( + solver, + And( + Leq(Int(0), x.getRef()), + Leq(x.getRef(), y.getRef()), + Leq(y.getRef(), Int(3)))); Assert.assertEquals(10, initFunc.getInitStates(prec).size()); } @Test public void testBottom() { final ExplPrec prec = ExplPrec.of(ImmutableList.of(x, y)); - final ExplInitFunc initFunc = ExplInitFunc.create(solver, - And(Leq(Int(5), x.getRef()), Leq(x.getRef(), y.getRef()), Leq(y.getRef(), Int(3)))); + final ExplInitFunc initFunc = + ExplInitFunc.create( + solver, + And( + Leq(Int(5), x.getRef()), + Leq(x.getRef(), y.getRef()), + Leq(y.getRef(), Int(3)))); final Collection initStates = initFunc.getInitStates(prec); Assert.assertEquals(1, initStates.size()); Assert.assertEquals(ExplState.bottom(), Utils.singleElementOf(initStates)); diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplOrdTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplOrdTest.java index d98f595dcb..4d98dea917 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplOrdTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplOrdTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,12 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.type.inttype.IntType; +import org.junit.Assert; +import org.junit.Test; public class ExplOrdTest { @@ -36,8 +35,8 @@ public class ExplOrdTest { private final ExplState s1 = ExplState.of(ImmutableValuation.builder().put(X, Int(1)).build()); private final ExplState s2 = ExplState.of(ImmutableValuation.builder().put(X, Int(2)).build()); private final ExplState s3 = ExplState.of(ImmutableValuation.builder().put(Y, Int(1)).build()); - private final ExplState s4 = ExplState.of( - ImmutableValuation.builder().put(X, Int(1)).put(Y, Int(1)).build()); + private final ExplState s4 = + ExplState.of(ImmutableValuation.builder().put(X, Int(1)).put(Y, Int(1)).build()); private final ExplState sb = ExplState.bottom(); @Test diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplPrecTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplPrecTest.java index fa0f2b1c7b..e0cee3e42d 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplPrecTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplPrecTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,16 +18,13 @@ import static hu.bme.mit.theta.core.decl.Decls.Var; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import java.util.Collections; - -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; public class ExplPrecTest { @@ -52,8 +49,9 @@ public void testInstances() { @Test public void testMapping() { final ExplPrec prec = ExplPrec.of(Collections.singleton(x)); - final ExplState s1 = prec.createState( - ImmutableValuation.builder().put(x, Int(1)).put(y, Int(2)).build()); + final ExplState s1 = + prec.createState( + ImmutableValuation.builder().put(x, Int(1)).put(y, Int(2)).build()); final ExplState s2 = prec.createState(ImmutableValuation.builder().put(y, Int(2)).build()); Assert.assertEquals(1, s1.getDecls().size()); diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicateTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicateTest.java index 424f955aee..f17d0c844e 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicateTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,15 +23,6 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; import static org.junit.Assert.assertEquals; -import java.util.Arrays; -import java.util.Collection; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.type.Expr; @@ -39,6 +30,13 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class ExplStatePredicateTest { @@ -57,19 +55,25 @@ public class ExplStatePredicateTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {True(), ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()), true}, - - {Leq(x.getRef(), Int(5)), - ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()), true}, - - {Leq(x.getRef(), Int(5)), - ExplState.of(ImmutableValuation.builder().put(x, Int(7)).build()), false}, - - {Geq(Mul(x.getRef(), x.getRef()), Int(0)), ExplState.top(), true}, - - }); + return Arrays.asList( + new Object[][] { + { + True(), + ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()), + true + }, + { + Leq(x.getRef(), Int(5)), + ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()), + true + }, + { + Leq(x.getRef(), Int(5)), + ExplState.of(ImmutableValuation.builder().put(x, Int(7)).build()), + false + }, + {Geq(Mul(x.getRef(), x.getRef()), Int(0)), ExplState.top(), true}, + }); } @Test diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStateTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStateTest.java index b793a601f7..8863965a13 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStateTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,14 +22,12 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import java.util.Optional; - -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.Optional; +import org.junit.Assert; +import org.junit.Test; public class ExplStateTest { @@ -68,7 +66,8 @@ public void testEval() { public void testToExpr() { Assert.assertEquals(True(), ExplState.top().toExpr()); Assert.assertEquals(False(), ExplState.bottom().toExpr()); - Assert.assertEquals(And(Eq(x.getRef(), Int(1)), Eq(y.getRef(), Int(2))), + Assert.assertEquals( + And(Eq(x.getRef(), Int(1)), Eq(y.getRef(), Int(2))), ExplState.of(ImmutableValuation.builder().put(x, Int(1)).put(y, Int(2)).build()) .toExpr()); } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFuncTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFuncTest.java index a6f39887d8..ad498dab71 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFuncTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFuncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,22 +26,9 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Lt; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - -import hu.bme.mit.theta.common.container.Containers; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.common.Utils; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.stmt.Stmt; @@ -49,6 +36,14 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.junit.Assert; +import org.junit.Test; public class ExplStmtTransFuncTest { @@ -68,12 +63,12 @@ public void testSimple() { stmts.add(Assign(x, Add(x.getRef(), Int(1)))); stmts.add(Assume(Leq(x.getRef(), Int(100)))); - final Collection succStates = transFunc.getSuccStates(sourceState, - stmts, prec); + final Collection succStates = + transFunc.getSuccStates(sourceState, stmts, prec); Assert.assertEquals(1, succStates.size()); - final ExplState expectedState = ExplState.of( - ImmutableValuation.builder().put(x, Int(2)).build()); + final ExplState expectedState = + ExplState.of(ImmutableValuation.builder().put(x, Int(2)).build()); Assert.assertEquals(expectedState, Utils.singleElementOf(succStates)); } @@ -86,8 +81,8 @@ public void testBottom() { stmts.add(Havoc(x)); stmts.add(Assume(Lt(Mul(x.getRef(), x.getRef()), Int(0)))); - final Collection succStates = transFunc.getSuccStates(sourceState, - stmts, prec); + final Collection succStates = + transFunc.getSuccStates(sourceState, stmts, prec); Assert.assertEquals(1, succStates.size()); final ExplState expectedState = ExplState.bottom(); @@ -103,12 +98,12 @@ public void testComplex1() { stmts.add(Assign(x, Int(5))); stmts.add(Assume(Eq(x.getRef(), y.getRef()))); - final Collection succStates = transFunc.getSuccStates(sourceState, - stmts, prec); + final Collection succStates = + transFunc.getSuccStates(sourceState, stmts, prec); Assert.assertEquals(1, succStates.size()); - final ExplState expectedState = ExplState - .of(ImmutableValuation.builder().put(x, Int(5)).put(y, Int(5)).build()); + final ExplState expectedState = + ExplState.of(ImmutableValuation.builder().put(x, Int(5)).put(y, Int(5)).build()); Assert.assertEquals(expectedState, Utils.singleElementOf(succStates)); } @@ -121,12 +116,12 @@ public void testComplex2() { stmts.add(Assign(x, Int(5))); stmts.add(Assume(Eq(x.getRef(), y.getRef()))); - final Collection succStates = transFunc.getSuccStates(sourceState, - stmts, prec); + final Collection succStates = + transFunc.getSuccStates(sourceState, stmts, prec); Assert.assertEquals(1, succStates.size()); - final ExplState expectedState = ExplState - .of(ImmutableValuation.builder().put(x, Int(5)).put(y, Int(5)).build()); + final ExplState expectedState = + ExplState.of(ImmutableValuation.builder().put(x, Int(5)).put(y, Int(5)).build()); Assert.assertEquals(expectedState, Utils.singleElementOf(succStates)); } @@ -146,11 +141,10 @@ public void testComplex3() { for (final Entry entry : solverCallsToExpectedStates.entrySet()) { final ExplStmtTransFunc transFunc = ExplStmtTransFunc.create(solver, entry.getKey()); - final Collection succStates = transFunc.getSuccStates(sourceState, - stmts, prec); + final Collection succStates = + transFunc.getSuccStates(sourceState, stmts, prec); Assert.assertEquals(entry.getValue().intValue(), succStates.size()); } - } } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplTransFuncTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplTransFuncTest.java index 7cf96f5da4..e9f91dea3a 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplTransFuncTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/ExplTransFuncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,15 @@ */ package hu.bme.mit.theta.analysis.expl; +import static hu.bme.mit.theta.core.decl.Decls.Var; +import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.common.Utils; @@ -23,28 +32,19 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.Collection; import org.junit.Assert; import org.junit.Test; -import java.util.Collection; - -import static hu.bme.mit.theta.core.decl.Decls.Var; -import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - public class ExplTransFuncTest { private final VarDecl x = Var("x", Int()); private final ExplPrec prec = ExplPrec.of(ImmutableList.of(x)); - private final ExplState state = ExplState.of( - ImmutableValuation.builder().put(x, Int(1)).build()); + private final ExplState state = + ExplState.of(ImmutableValuation.builder().put(x, Int(1)).build()); - ExplTransFunc transFunc = ExplTransFunc.create(Z3LegacySolverFactory.getInstance().createSolver()); + ExplTransFunc transFunc = + ExplTransFunc.create(Z3LegacySolverFactory.getInstance().createSolver()); @Test public void testNormal() { @@ -52,10 +52,11 @@ public void testNormal() { doReturn(Eq(Prime(x.getRef()), Add(x.getRef(), Int(1)))).when(action).toExpr(); when(action.nextIndexing()).thenReturn(VarIndexingFactory.indexing(1)); - final Collection succStates = transFunc.getSuccStates(state, action, - prec); + final Collection succStates = + transFunc.getSuccStates(state, action, prec); Assert.assertEquals(1, succStates.size()); - Assert.assertEquals(ExplState.of(ImmutableValuation.builder().put(x, Int(2)).build()), + Assert.assertEquals( + ExplState.of(ImmutableValuation.builder().put(x, Int(2)).build()), succStates.iterator().next()); } @@ -65,8 +66,8 @@ public void testBottom() { doReturn(Eq(x.getRef(), Int(2))).when(action).toExpr(); when(action.nextIndexing()).thenReturn(VarIndexingFactory.indexing(1)); - final Collection succStates = transFunc.getSuccStates(state, action, - prec); + final Collection succStates = + transFunc.getSuccStates(state, action, prec); Assert.assertEquals(1, succStates.size()); Assert.assertEquals(ExplState.bottom(), Utils.singleElementOf(succStates)); } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/StmtApplierTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/StmtApplierTest.java index d9d94de41b..787042b657 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/StmtApplierTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expl/StmtApplierTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,24 +15,6 @@ */ package hu.bme.mit.theta.analysis.expl; -import hu.bme.mit.theta.analysis.expl.StmtApplier.ApplyResult; -import hu.bme.mit.theta.common.Tuple2; -import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.model.MutableValuation; -import hu.bme.mit.theta.core.stmt.Stmt; -import hu.bme.mit.theta.core.type.LitExpr; -import hu.bme.mit.theta.core.type.inttype.IntType; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Set; - import static com.google.common.collect.ImmutableSet.of; import static hu.bme.mit.theta.analysis.expl.StmtApplier.ApplyResult.BOTTOM; import static hu.bme.mit.theta.analysis.expl.StmtApplier.ApplyResult.FAILURE; @@ -48,6 +30,23 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Leq; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.analysis.expl.StmtApplier.ApplyResult; +import hu.bme.mit.theta.common.Tuple2; +import hu.bme.mit.theta.core.decl.Decl; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.model.MutableValuation; +import hu.bme.mit.theta.core.stmt.Stmt; +import hu.bme.mit.theta.core.type.LitExpr; +import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.Arrays; +import java.util.Collection; +import java.util.Set; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + @RunWith(Parameterized.class) public final class StmtApplierTest { @@ -85,63 +84,36 @@ public final class StmtApplierTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {HAVOC_X, of(X_IS_1), false, SUCCESS, of()}, - - {HAVOC_X, of(Y_IS_2), false, SUCCESS, of(Y_IS_2)}, - - {HAVOC_X, of(X_IS_1, Y_IS_2), false, SUCCESS, of(Y_IS_2)}, - - {HAVOC_X, of(), false, SUCCESS, of()}, - - {ASSUME_GT_X_0, of(X_IS_1), false, SUCCESS, of(X_IS_1)}, - - {ASSUME_GT_X_0, of(Y_IS_2), false, FAILURE, of(Y_IS_2)}, - - {ASSUME_GT_X_0, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, - - {ASSUME_GT_X_0, of(), false, FAILURE, of()}, - - {ASSUME_LEQ_X_0, of(X_IS_1), false, BOTTOM, of(X_IS_1)}, - - {ASSUME_LEQ_X_0, of(Y_IS_2), false, FAILURE, of(Y_IS_2)}, - - {ASSUME_LEQ_X_0, of(X_IS_1, Y_IS_2), false, BOTTOM, of(X_IS_1, Y_IS_2)}, - - {ASSUME_LEQ_X_Y, of(X_IS_1), false, FAILURE, of(X_IS_1)}, - - {ASSUME_LEQ_X_Y, of(Y_IS_2), false, FAILURE, of(Y_IS_2)}, - - {ASSUME_LEQ_X_Y, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, - - {ASSUME_LEQ_X_Y, of(), false, FAILURE, of()}, - - {ASSIGN_X_1, of(), false, SUCCESS, of(X_IS_1)}, - - {ASSIGN_X_1, of(Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, - - {ASSIGN_X_1, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, - - {ASSIGN_X_2, of(), false, SUCCESS, of(X_IS_2)}, - - {ASSIGN_X_2, of(X_IS_1), false, SUCCESS, of(X_IS_2)}, - - {ASSIGN_X_Y, of(), false, FAILURE, of()}, - - {ASSIGN_X_Y, of(X_IS_1), false, FAILURE, of(X_IS_1)}, - - {ASSIGN_X_Y, of(X_IS_1), true, SUCCESS, of()}, - - {ASSIGN_X_Y, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_2, Y_IS_2)}, - - {ASSIGN_X_Y, of(Y_IS_2), false, SUCCESS, of(X_IS_2, Y_IS_2)}, - - {SKIP, of(X_IS_1), false, SUCCESS, of(X_IS_1)}, - - {ASSUME_EQ_X_1, of(), false, SUCCESS, of(X_IS_1)}, - - }); + return Arrays.asList( + new Object[][] { + {HAVOC_X, of(X_IS_1), false, SUCCESS, of()}, + {HAVOC_X, of(Y_IS_2), false, SUCCESS, of(Y_IS_2)}, + {HAVOC_X, of(X_IS_1, Y_IS_2), false, SUCCESS, of(Y_IS_2)}, + {HAVOC_X, of(), false, SUCCESS, of()}, + {ASSUME_GT_X_0, of(X_IS_1), false, SUCCESS, of(X_IS_1)}, + {ASSUME_GT_X_0, of(Y_IS_2), false, FAILURE, of(Y_IS_2)}, + {ASSUME_GT_X_0, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, + {ASSUME_GT_X_0, of(), false, FAILURE, of()}, + {ASSUME_LEQ_X_0, of(X_IS_1), false, BOTTOM, of(X_IS_1)}, + {ASSUME_LEQ_X_0, of(Y_IS_2), false, FAILURE, of(Y_IS_2)}, + {ASSUME_LEQ_X_0, of(X_IS_1, Y_IS_2), false, BOTTOM, of(X_IS_1, Y_IS_2)}, + {ASSUME_LEQ_X_Y, of(X_IS_1), false, FAILURE, of(X_IS_1)}, + {ASSUME_LEQ_X_Y, of(Y_IS_2), false, FAILURE, of(Y_IS_2)}, + {ASSUME_LEQ_X_Y, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, + {ASSUME_LEQ_X_Y, of(), false, FAILURE, of()}, + {ASSIGN_X_1, of(), false, SUCCESS, of(X_IS_1)}, + {ASSIGN_X_1, of(Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, + {ASSIGN_X_1, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_1, Y_IS_2)}, + {ASSIGN_X_2, of(), false, SUCCESS, of(X_IS_2)}, + {ASSIGN_X_2, of(X_IS_1), false, SUCCESS, of(X_IS_2)}, + {ASSIGN_X_Y, of(), false, FAILURE, of()}, + {ASSIGN_X_Y, of(X_IS_1), false, FAILURE, of(X_IS_1)}, + {ASSIGN_X_Y, of(X_IS_1), true, SUCCESS, of()}, + {ASSIGN_X_Y, of(X_IS_1, Y_IS_2), false, SUCCESS, of(X_IS_2, Y_IS_2)}, + {ASSIGN_X_Y, of(Y_IS_2), false, SUCCESS, of(X_IS_2, Y_IS_2)}, + {SKIP, of(X_IS_1), false, SUCCESS, of(X_IS_1)}, + {ASSUME_EQ_X_1, of(), false, SUCCESS, of(X_IS_1)}, + }); } @Test @@ -163,5 +135,4 @@ public void test() { assertEquals(lit, entry.get2()); } } - } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprOrdLeqTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprOrdLeqTest.java index b9cb0ba1b5..ed1679e14f 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprOrdLeqTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprOrdLeqTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,22 +23,20 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Leq; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.analysis.PartialOrd; +import hu.bme.mit.theta.analysis.pred.PredState; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.solver.Solver; +import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; import java.util.Arrays; import java.util.Collection; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.analysis.PartialOrd; -import hu.bme.mit.theta.analysis.pred.PredState; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.inttype.IntType; -import hu.bme.mit.theta.solver.Solver; -import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; - @RunWith(Parameterized.class) public final class ExprOrdLeqTest { @@ -55,19 +53,14 @@ public final class ExprOrdLeqTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {PredState.of(), PredState.of(), true}, - - {PredState.of(Geq(X, Int(0))), PredState.of(True()), true}, - - {PredState.of(False()), PredState.of(Leq(X, Int(1))), true}, - - {PredState.of(True()), PredState.of(Geq(X, Int(0))), false}, - - {PredState.of(Geq(X, Int(0))), PredState.of(False()), false} - - }); + return Arrays.asList( + new Object[][] { + {PredState.of(), PredState.of(), true}, + {PredState.of(Geq(X, Int(0))), PredState.of(True()), true}, + {PredState.of(False()), PredState.of(Leq(X, Int(1))), true}, + {PredState.of(True()), PredState.of(Geq(X, Int(0))), false}, + {PredState.of(Geq(X, Int(0))), PredState.of(False()), false} + }); } @Test @@ -76,5 +69,4 @@ public void testIsTop() { final PartialOrd ord = ExprOrd.create(solver); assertEquals(ord.isLeq(state1, state2), leq); } - } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprStatesTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprStatesTest.java index 30b82223d5..a5cf502252 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprStatesTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprStatesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.decl.Decls.Var; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Geq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.analysis.expl.ExplPrec; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; @@ -25,15 +29,10 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; -import java.util.Collections; - -import static hu.bme.mit.theta.core.decl.Decls.Var; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Geq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class ExprStatesTest { private final VarDecl vx = Var("x", Int()); @@ -45,29 +44,36 @@ public void test1() { final Expr expr = Geq(vx.getRef(), Int(0)); final VarIndexing idx = VarIndexingFactory.indexing(0); - Assert.assertEquals(1, + Assert.assertEquals( + 1, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 1).size()); - Assert.assertEquals(5, + Assert.assertEquals( + 5, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 5).size()); - Assert.assertEquals(10, + Assert.assertEquals( + 10, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 10).size()); } @Test public void test2() { - final Expr expr = BoolExprs.And(Geq(vx.getRef(), Int(0)), - Geq(Int(3), vx.getRef())); + final Expr expr = + BoolExprs.And(Geq(vx.getRef(), Int(0)), Geq(Int(3), vx.getRef())); final VarIndexing idx = VarIndexingFactory.indexing(0); - Assert.assertEquals(2, + Assert.assertEquals( + 2, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 2).size()); - Assert.assertEquals(4, + Assert.assertEquals( + 4, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 4).size()); - Assert.assertEquals(4, + Assert.assertEquals( + 4, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 10).size()); - Assert.assertEquals(4, + Assert.assertEquals( + 4, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx, 0).size()); - Assert.assertEquals(4, - ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx).size()); + Assert.assertEquals( + 4, ExprStates.createStatesForExpr(solver, expr, 0, prec::createState, idx).size()); } } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprTraceCheckersTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprTraceCheckersTest.java index 507fd394c2..35fffdc721 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprTraceCheckersTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/expr/ExprTraceCheckersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,19 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.decl.Decls.Var; +import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Geq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.refinement.ExprTraceBwBinItpChecker; import hu.bme.mit.theta.analysis.expr.refinement.ExprTraceChecker; @@ -29,26 +42,12 @@ import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; -import org.junit.Before; -import org.junit.Test; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; - -import static hu.bme.mit.theta.core.decl.Decls.Var; -import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Geq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.junit.Before; +import org.junit.Test; public final class ExprTraceCheckersTest { @@ -113,5 +112,4 @@ public void testInfeasable() { assertFalse(status.isFeasible()); } } - } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/ExplSplittersTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/ExplSplittersTest.java index a5297db6f1..2085f4cd46 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/ExplSplittersTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/ExplSplittersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,14 +20,12 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import java.util.Collection; - -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; +import java.util.Collection; +import org.junit.Assert; +import org.junit.Test; public class ExplSplittersTest { diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredInitFuncTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredInitFuncTest.java index 09fc03e5f0..28c59f4461 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredInitFuncTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredInitFuncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,19 +23,16 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Lt; -import java.util.Collection; - -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.analysis.pred.PredAbstractors.PredAbstractor; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.Collection; +import org.junit.Assert; +import org.junit.Test; public class PredInitFuncTest { @@ -47,8 +44,8 @@ public class PredInitFuncTest { @Test public void test1() { // true -> (x>=0, y>=0)? - final PredPrec prec = PredPrec.of( - ImmutableList.of(Geq(x.getRef(), Int(0)), Geq(y.getRef(), Int(0)))); + final PredPrec prec = + PredPrec.of(ImmutableList.of(Geq(x.getRef(), Int(0)), Geq(y.getRef(), Int(0)))); final PredInitFunc initFunc = PredInitFunc.create(predAbstractor, True()); Assert.assertEquals(4, initFunc.getInitStates(prec).size()); } @@ -56,8 +53,8 @@ public void test1() { @Test public void test2() { // (x>=0) -> (x>=0, y>=0)? - final PredPrec prec = PredPrec.of( - ImmutableList.of(Geq(x.getRef(), Int(0)), Geq(y.getRef(), Int(0)))); + final PredPrec prec = + PredPrec.of(ImmutableList.of(Geq(x.getRef(), Int(0)), Geq(y.getRef(), Int(0)))); final PredInitFunc initFunc = PredInitFunc.create(predAbstractor, Geq(x.getRef(), Int(0))); Assert.assertEquals(2, initFunc.getInitStates(prec).size()); } @@ -65,8 +62,8 @@ public void test2() { @Test public void test3() { // (x>=1) -> (x>=0, y>=0)? - final PredPrec prec = PredPrec.of( - ImmutableList.of(Geq(x.getRef(), Int(0)), Geq(y.getRef(), Int(0)))); + final PredPrec prec = + PredPrec.of(ImmutableList.of(Geq(x.getRef(), Int(0)), Geq(y.getRef(), Int(0)))); final PredInitFunc initFunc = PredInitFunc.create(predAbstractor, Geq(x.getRef(), Int(1))); Assert.assertEquals(2, initFunc.getInitStates(prec).size()); } @@ -74,8 +71,8 @@ public void test3() { @Test public void test4() { // true -> (x>0, x<0)? - final PredPrec prec = PredPrec.of( - ImmutableList.of(Gt(x.getRef(), Int(0)), Lt(x.getRef(), Int(0)))); + final PredPrec prec = + PredPrec.of(ImmutableList.of(Gt(x.getRef(), Int(0)), Lt(x.getRef(), Int(0)))); final PredInitFunc initFunc = PredInitFunc.create(predAbstractor, True()); Assert.assertEquals(3, initFunc.getInitStates(prec).size()); } @@ -84,8 +81,9 @@ public void test4() { public void testBottom() { // (x<0) and (x>0) -> (x>0)? final PredPrec prec = PredPrec.of(ImmutableList.of(Gt(x.getRef(), Int(0)))); - final PredInitFunc initFunc = PredInitFunc.create(predAbstractor, - And(Gt(x.getRef(), Int(0)), Lt(x.getRef(), Int(0)))); + final PredInitFunc initFunc = + PredInitFunc.create( + predAbstractor, And(Gt(x.getRef(), Int(0)), Lt(x.getRef(), Int(0)))); final Collection initStates = initFunc.getInitStates(prec); Assert.assertEquals(1, initStates.size()); Assert.assertEquals(PredState.bottom(), Utils.singleElementOf(initStates)); diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredOrdTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredOrdTest.java index ab643eb50a..aa991addd9 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredOrdTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredOrdTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,13 +20,12 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Lt; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import org.junit.Assert; +import org.junit.Test; public class PredOrdTest { diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredPrecTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredPrecTest.java index 4161b2c5b4..ddc6488d20 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredPrecTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredPrecTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,15 +20,13 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Lt; -import java.util.Collections; - -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; public class PredPrecTest { @@ -50,7 +48,6 @@ public void testRefinement() { Assert.assertSame(p1, r1); Assert.assertNotSame(p1, r2); Assert.assertSame(r2, r3); - } @Test diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredTransFuncTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredTransFuncTest.java index 5a00b2b485..5c03c97c79 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredTransFuncTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/pred/PredTransFuncTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,15 +22,7 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Lt; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.analysis.expr.StmtAction; import hu.bme.mit.theta.common.Utils; @@ -40,14 +32,19 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; public class PredTransFuncTest { private final VarDecl x = Var("x", Int()); private final VarDecl y = Var("y", Int()); private final Solver solver = Z3LegacySolverFactory.getInstance().createSolver(); - private final PredTransFunc transFunc = PredTransFunc.create( - PredAbstractors.booleanSplitAbstractor(solver)); + private final PredTransFunc transFunc = + PredTransFunc.create(PredAbstractors.booleanSplitAbstractor(solver)); @Test public void test1() { @@ -70,8 +67,8 @@ public void test2() { @Test public void test3() { // (x>0) ---[x := x+y]--> (x>0, y>0)? - final PredPrec prec = PredPrec.of( - ImmutableList.of(Gt(x.getRef(), Int(0)), Gt(y.getRef(), Int(0)))); + final PredPrec prec = + PredPrec.of(ImmutableList.of(Gt(x.getRef(), Int(0)), Gt(y.getRef(), Int(0)))); final PredState state = PredState.of(Gt(x.getRef(), Int(0))); final ExprAction action = new BasicStmtAction(Stmts.Assign(x, Add(x.getRef(), y.getRef()))); Assert.assertEquals(3, transFunc.getSuccStates(state, action, prec).size()); @@ -83,8 +80,8 @@ public void testBottom() { final PredPrec prec = PredPrec.of(ImmutableList.of(Gt(x.getRef(), Int(0)))); final PredState state = PredState.of(Gt(x.getRef(), Int(0))); final ExprAction action = new BasicStmtAction(Stmts.Assume(Eq(Int(0), x.getRef()))); - final Collection succStates = transFunc.getSuccStates(state, action, - prec); + final Collection succStates = + transFunc.getSuccStates(state, action, prec); Assert.assertEquals(1, succStates.size()); Assert.assertEquals(PredState.bottom(), Utils.singleElementOf(succStates)); } 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 7d51fc7de8..afe144bb1f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/ActionStub.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/ActionStub.java index c3b403b012..280bb648c7 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/ActionStub.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/ActionStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,7 +16,6 @@ package hu.bme.mit.theta.analysis.stubs; import hu.bme.mit.theta.analysis.Action; - import java.util.Objects; public class ActionStub implements Action { diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PartialOrdStub.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PartialOrdStub.java index 8d9718ccc7..513b268232 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PartialOrdStub.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PartialOrdStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,5 +24,4 @@ public class PartialOrdStub implements PartialOrd { public boolean isLeq(final State state1, final State state2) { return state1.equals(state2); } - } diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PrecStub.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PrecStub.java index 2dc50e7a02..970e0b6c54 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PrecStub.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/PrecStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; import java.util.Set; diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/StateStub.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/StateStub.java index 79c5de7690..ca56e4aca0 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/StateStub.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/stubs/StateStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,7 +16,6 @@ package hu.bme.mit.theta.analysis.stubs; import hu.bme.mit.theta.analysis.State; - import java.util.Objects; public class StateStub implements State { diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/waitlist/WaitlistTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/waitlist/WaitlistTest.java index e5403f1eb2..38b09e1e7b 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/waitlist/WaitlistTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/waitlist/WaitlistTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,12 @@ */ package hu.bme.mit.theta.analysis.waitlist; -import java.util.NoSuchElementException; - -import org.junit.Test; - import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import java.util.NoSuchElementException; +import org.junit.Test; public class WaitlistTest { diff --git a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/zone/DiffBoundTest.java b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/zone/DiffBoundTest.java index 546d63f829..80ae5ecddc 100644 --- a/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/zone/DiffBoundTest.java +++ b/subprojects/common/analysis/src/test/java/hu/bme/mit/theta/analysis/zone/DiffBoundTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -133,5 +133,4 @@ public void testToString() { assertEquals("(10, <=)", asString(Leq(10))); assertEquals("(-10, <=)", asString(Leq(-10))); } - } diff --git a/subprojects/common/analysis/src/test/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisTest.kt b/subprojects/common/analysis/src/test/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisTest.kt index 18e5f6697a..556a043b73 100644 --- a/subprojects/common/analysis/src/test/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisTest.kt +++ b/subprojects/common/analysis/src/test/kotlin/hu/bme/mit/theta/analysis/multi/MultiAnalysisTest.kt @@ -1,17 +1,18 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. + * 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.analysis.multi import hu.bme.mit.theta.analysis.Analysis @@ -32,117 +33,116 @@ import hu.bme.mit.theta.core.type.booltype.BoolExprs.True import hu.bme.mit.theta.core.type.booltype.BoolType import org.junit.jupiter.api.Test - class MultiAnalysisTest { - val multiUnitPrec = MultiPrec(UnitPrec.getInstance(), UnitPrec.getInstance(), UnitPrec.getInstance()) + val multiUnitPrec = + MultiPrec(UnitPrec.getInstance(), UnitPrec.getInstance(), UnitPrec.getInstance()) - class NumberedState(val num: Int) : ExprState { + class NumberedState(val num: Int) : ExprState { - override fun toExpr(): Expr? = True() - - override fun isBottom(): Boolean = false - - } + override fun toExpr(): Expr? = True() - class NumberedAction() : StmtAction() { + override fun isBottom(): Boolean = false + } - override fun getStmts(): List? { - return listOf(SkipStmt.getInstance()) - } + class NumberedAction() : StmtAction() { + override fun getStmts(): List? { + return listOf(SkipStmt.getInstance()) } - - class NumberedAnalysis : Analysis { - - override fun getPartialOrd(): PartialOrd? = - object : PartialOrd { - override fun isLeq( - state1: NumberedState?, - state2: NumberedState? - ): Boolean = state1!!.num <= state2!!.num - - } - - override fun getInitFunc(): InitFunc? = - object : InitFunc { - override fun getInitStates( - prec: UnitPrec? - ): Collection? = listOf(NumberedState(0)) - - } - - override fun getTransFunc(): TransFunc? = - object : TransFunc { - override fun getSuccStates( - state: NumberedState?, - action: NumberedAction?, - prec: UnitPrec? - ): Collection? = listOf(NumberedState(state!!.num + 1)) - - } - - } - - class NumberedLTS : LTS { - - override fun getEnabledActionsFor( - state: NumberedState? - ): Collection? = listOf(NumberedAction()) - - } - - @Test - fun test() { - - val side: MultiAnalysisSide = - MultiAnalysisSide( - NumberedAnalysis(), - object : InitFunc { - override fun getInitStates( - prec: UnitPrec? - ): Collection? = listOf(NumberedState(0)) - }, - { c: NumberedState, _: UnitState -> c }, - { c: NumberedState -> c }, - { c: NumberedState -> UnitState.getInstance() }, - { p: UnitPrec -> p } - ) - - val builderResult = StmtMultiBuilder(side, NumberedLTS()) - .addRightSide(side, NumberedLTS()) - .build( - { ms: ExprMultiState -> if (ms.sourceSide == MultiSide.RIGHT || ms.leftState.num % 2 == 1) MultiSide.LEFT else MultiSide.RIGHT }, - object : InitFunc { - override fun getInitStates( - prec: UnitPrec? - ): Collection? = listOf(UnitState.getInstance()) - } - ) - - val multiAnalysis = builderResult.side.analysis - val initStates = multiAnalysis.initFunc.getInitStates(multiUnitPrec) - val initState = initStates.single() - - assert(initStates.size == 1) - assert(initState.leftState.num == 0 && initState.rightState.num == 0) - - var action = builderResult.lts.getEnabledActionsFor(initState).single() - - val succ1State = multiAnalysis.transFunc.getSuccStates(initState, action, multiUnitPrec).single() - assert(succ1State.leftState.num == 0 && succ1State.rightState.num == 1) - action = builderResult.lts.getEnabledActionsFor(succ1State).single() - - val succ2State = multiAnalysis.transFunc.getSuccStates(succ1State, action, multiUnitPrec).single() - assert(succ2State.leftState.num == 1 && succ2State.rightState.num == 1) - action = builderResult.lts.getEnabledActionsFor(succ2State).single() - - val succ3State = multiAnalysis.transFunc.getSuccStates(succ2State, action, multiUnitPrec).single() - assert(succ3State.leftState.num == 2 && succ3State.rightState.num == 1) - - assert(multiAnalysis.partialOrd.isLeq(succ2State, succ3State)) - - } - - -} \ No newline at end of file + } + + class NumberedAnalysis : Analysis { + + override fun getPartialOrd(): PartialOrd? = + object : PartialOrd { + override fun isLeq(state1: NumberedState?, state2: NumberedState?): Boolean = + state1!!.num <= state2!!.num + } + + override fun getInitFunc(): InitFunc? = + object : InitFunc { + override fun getInitStates(prec: UnitPrec?): Collection? = + listOf(NumberedState(0)) + } + + override fun getTransFunc(): TransFunc? = + object : TransFunc { + override fun getSuccStates( + state: NumberedState?, + action: NumberedAction?, + prec: UnitPrec?, + ): Collection? = listOf(NumberedState(state!!.num + 1)) + } + } + + class NumberedLTS : LTS { + + override fun getEnabledActionsFor(state: NumberedState?): Collection? = + listOf(NumberedAction()) + } + + @Test + fun test() { + + val side: + MultiAnalysisSide< + NumberedState, + UnitState, + NumberedState, + NumberedAction, + UnitPrec, + UnitPrec, + > = + MultiAnalysisSide( + NumberedAnalysis(), + object : InitFunc { + override fun getInitStates(prec: UnitPrec?): Collection? = + listOf(NumberedState(0)) + }, + { c: NumberedState, _: UnitState -> c }, + { c: NumberedState -> c }, + { c: NumberedState -> UnitState.getInstance() }, + { p: UnitPrec -> p }, + ) + + val builderResult = + StmtMultiBuilder(side, NumberedLTS()) + .addRightSide(side, NumberedLTS()) + .build( + { ms: ExprMultiState -> + if (ms.sourceSide == MultiSide.RIGHT || ms.leftState.num % 2 == 1) MultiSide.LEFT + else MultiSide.RIGHT + }, + object : InitFunc { + override fun getInitStates(prec: UnitPrec?): Collection? = + listOf(UnitState.getInstance()) + }, + ) + + val multiAnalysis = builderResult.side.analysis + val initStates = multiAnalysis.initFunc.getInitStates(multiUnitPrec) + val initState = initStates.single() + + assert(initStates.size == 1) + assert(initState.leftState.num == 0 && initState.rightState.num == 0) + + var action = builderResult.lts.getEnabledActionsFor(initState).single() + + val succ1State = + multiAnalysis.transFunc.getSuccStates(initState, action, multiUnitPrec).single() + assert(succ1State.leftState.num == 0 && succ1State.rightState.num == 1) + action = builderResult.lts.getEnabledActionsFor(succ1State).single() + + val succ2State = + multiAnalysis.transFunc.getSuccStates(succ1State, action, multiUnitPrec).single() + assert(succ2State.leftState.num == 1 && succ2State.rightState.num == 1) + action = builderResult.lts.getEnabledActionsFor(succ2State).single() + + val succ3State = + multiAnalysis.transFunc.getSuccStates(succ2State, action, multiUnitPrec).single() + assert(succ3State.leftState.num == 2 && succ3State.rightState.num == 1) + + assert(multiAnalysis.partialOrd.isLeq(succ2State, succ3State)) + } +} diff --git a/subprojects/common/common/build.gradle.kts b/subprojects/common/common/build.gradle.kts index 971b6106d4..5a8fbfd7b9 100644 --- a/subprojects/common/common/build.gradle.kts +++ b/subprojects/common/common/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/CliUtils.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/CliUtils.java index a3eeac1811..b50f85f2b0 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/CliUtils.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/CliUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,7 @@ public class CliUtils { - private CliUtils() { - } + private CliUtils() {} public static void printVersion(PrintStream ps) { String ver = new CliUtils().getClass().getPackage().getImplementationVersion(); diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable.java index 6f72c2e6c9..295a1dd746 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkState; import hu.bme.mit.theta.common.container.Containers; - import java.util.Map; import java.util.function.Function; @@ -35,8 +34,9 @@ private DispatchTable(final Builder builder) { public R dispatch(final T param) { final Class clazz = param.getClass(); - @SuppressWarnings("unchecked") final Function function = (Function) cases.get( - clazz); + @SuppressWarnings("unchecked") + final Function function = + (Function) cases.get(clazz); if (function == null) { return defaultCase.apply(param); } else { @@ -61,8 +61,8 @@ private Builder() { built = false; } - public Builder addCase(final Class clazz, - final Function function) { + public Builder addCase( + final Class clazz, final Function function) { checkState(!built, "Already built."); checkNotNull(clazz); checkNotNull(function); @@ -83,13 +83,12 @@ public DispatchTable build() { checkState(!built, "Already built."); built = true; if (defaultCase == null) { - defaultCase = o -> { - throw new AssertionError("Undefined default case executed for: " + o); - }; + defaultCase = + o -> { + throw new AssertionError("Undefined default case executed for: " + o); + }; } return new DispatchTable<>(this); } - } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable2.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable2.java index a69779d2a1..f0014f272d 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable2.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/DispatchTable2.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,10 @@ */ package hu.bme.mit.theta.common; -import hu.bme.mit.theta.common.container.Containers; - import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import hu.bme.mit.theta.common.container.Containers; import java.util.Map; import java.util.function.BiFunction; @@ -35,8 +34,9 @@ private DispatchTable2(final Builder builder) { public R dispatch(final T type, final P param) { final Class clazz = type.getClass(); - @SuppressWarnings("unchecked") final BiFunction function = (BiFunction) cases - .get(clazz); + @SuppressWarnings("unchecked") + final BiFunction function = + (BiFunction) cases.get(clazz); if (function == null) { return defaultCase.apply(type, param); } else { @@ -61,8 +61,9 @@ private Builder() { built = false; } - public Builder addCase(final Class clazz, - final BiFunction function) { + public Builder addCase( + final Class clazz, + final BiFunction function) { checkState(!built, "Already built."); checkNotNull(clazz); checkNotNull(function); @@ -83,9 +84,10 @@ public DispatchTable2 build() { checkState(!built, "Already built."); built = true; if (defaultCase == null) { - defaultCase = (o, p) -> { - throw new AssertionError("Undefined default case executed"); - }; + defaultCase = + (o, p) -> { + throw new AssertionError("Undefined default case executed"); + }; } return new DispatchTable2<>(this); } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Either.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Either.java index da92fd5250..1f587ffed6 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Either.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Either.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.common; -import java.util.NoSuchElementException; - import static com.google.common.base.Preconditions.checkNotNull; +import java.util.NoSuchElementException; + public abstract class Either { - private Either() { - } + private Either() {} public static Left Left(final L left) { return new Left<>(left); @@ -100,7 +99,6 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder("left").add(left).toString(); } - } public static final class Right extends Either { @@ -161,7 +159,5 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder("right").add(right).toString(); } - } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/GrowingIntArray.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/GrowingIntArray.java index c896a29971..9f421a7dd7 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/GrowingIntArray.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/GrowingIntArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -56,5 +56,4 @@ private void grow() { System.arraycopy(array, 0, newArray, 0, array.length); array = newArray; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/IntMatrix.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/IntMatrix.java index 70445128cf..7ea0138b89 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/IntMatrix.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/IntMatrix.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -182,5 +182,4 @@ private static int nDigits(final int n) { } } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/LispStringBuilder.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/LispStringBuilder.java index a0d3f7aa99..4ad43bd12c 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/LispStringBuilder.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/LispStringBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,16 @@ */ package hu.bme.mit.theta.common; -import com.google.common.base.Strings; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import com.google.common.base.Strings; import java.util.ArrayList; import java.util.List; import java.util.StringJoiner; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -/** - * Utility class for printing Lisp style strings, e.g., (A (B 1 2) (C 3)). - */ +/** Utility class for printing Lisp style strings, e.g., (A (B 1 2) (C 3)). */ public final class LispStringBuilder { private static final String LPAREN = "("; @@ -44,7 +41,10 @@ public final class LispStringBuilder { private int minLengthForMultiline = 75; private static enum State { - HEAD, ALIGNED, BODY, BUILT; + HEAD, + ALIGNED, + BODY, + BUILT; } LispStringBuilder(final String prefix) { @@ -168,5 +168,4 @@ private String createBody() { private static String[] lines(final String string) { return string.split("\\r\\n|\\n|\\r"); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/OsHelper.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/OsHelper.java index b372dd50ab..53e72b30e5 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/OsHelper.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/OsHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,12 +19,12 @@ public final class OsHelper { - private OsHelper() { - - } + private OsHelper() {} public enum OperatingSystem { - WINDOWS, LINUX, MAC + WINDOWS, + LINUX, + MAC } public static OperatingSystem getOs() { @@ -44,7 +44,8 @@ public static OperatingSystem getOs() { } public enum Architecture { - X86, X64 + X86, + X64 } public static Architecture getArch() { diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuadFunction.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuadFunction.java index 162a0060de..5fcd34799f 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuadFunction.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuadFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,10 @@ */ package hu.bme.mit.theta.common; -import java.util.function.Function; - import static com.google.common.base.Preconditions.checkNotNull; +import java.util.function.Function; + @FunctionalInterface public interface QuadFunction { diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuintFunction.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuintFunction.java index 2015ab3c7d..32d46ade93 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuintFunction.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/QuintFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,10 @@ */ package hu.bme.mit.theta.common; -import java.util.function.Function; - import static com.google.common.base.Preconditions.checkNotNull; +import java.util.function.Function; + @FunctionalInterface public interface QuintFunction { @@ -27,7 +27,7 @@ public interface QuintFunction { default QuintFunction andThen( final Function after) { checkNotNull(after); - return (final T t, final U u, final V v, final W w, final X x) -> after.apply( - apply(t, u, v, w, x)); + return (final T t, final U u, final V v, final W w, final X x) -> + after.apply(apply(t, u, v, w, x)); } } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TernaryOperator.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TernaryOperator.java index 5e279be894..6b5050208a 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TernaryOperator.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TernaryOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,14 +23,17 @@ public interface TernaryOperator extends TriFunction { public static TernaryOperator minBy(final Comparator comparator) { Objects.requireNonNull(comparator); - return (a, b, c) -> comparator.compare(a, b) <= 0 ? (comparator.compare(a, c) <= 0 ? a : c) - : (comparator.compare(b, c) <= 0 ? b : c); + return (a, b, c) -> + comparator.compare(a, b) <= 0 + ? (comparator.compare(a, c) <= 0 ? a : c) + : (comparator.compare(b, c) <= 0 ? b : c); } public static TernaryOperator maxBy(final Comparator comparator) { Objects.requireNonNull(comparator); - return (a, b, c) -> comparator.compare(a, b) >= 0 ? (comparator.compare(a, c) >= 0 ? a : c) - : (comparator.compare(b, c) >= 0 ? b : c); + return (a, b, c) -> + comparator.compare(a, b) >= 0 + ? (comparator.compare(a, c) >= 0 ? a : c) + : (comparator.compare(b, c) >= 0 ? b : c); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TriFunction.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TriFunction.java index e266968ff9..9eea7af4e0 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TriFunction.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TriFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Try.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Try.java index c92d128fa3..c153741937 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Try.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Try.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.common; -import java.util.function.Supplier; - import static com.google.common.base.Preconditions.checkNotNull; +import java.util.function.Supplier; + public abstract class Try { - private Try() { - } + private Try() {} public static Try attempt(final Supplier supplier) { try { @@ -184,5 +183,4 @@ public String toString() { return Utils.lispStringBuilder("Faliure").add(exception).toString(); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple.java index 8c19e91a1c..912f536c46 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.common; -import com.google.common.collect.ImmutableList; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkPositionIndex; +import com.google.common.collect.ImmutableList; import java.util.Iterator; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkPositionIndex; - public abstract class Tuple implements Iterable { private volatile int hashCode = 0; @@ -82,5 +81,4 @@ public final boolean equals(final Object obj) { public final String toString() { return Utils.lispStringBuilder(getClass().getSimpleName()).addAll(elems).toString(); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple1.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple1.java index ae2ae8e4d5..dacc3de575 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple1.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple1.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,11 @@ */ package hu.bme.mit.theta.common; -import com.google.common.collect.ImmutableList; +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ImmutableList; import java.util.function.Function; -import static com.google.common.base.Preconditions.checkNotNull; - public final class Tuple1 extends Tuple { private Tuple1(final T1 e1) { @@ -32,7 +31,8 @@ public static Tuple1 of(final T1 e1) { } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } @@ -40,5 +40,4 @@ public R unpackTo(final Function function) { checkNotNull(function); return function.apply(get1()); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple2.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple2.java index 94210a7170..6b5b8f1a02 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple2.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple2.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,8 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.function.BiFunction; - import com.google.common.collect.ImmutableList; +import java.util.function.BiFunction; public final class Tuple2 extends Tuple { @@ -32,12 +31,14 @@ public static Tuple2 of(final T1 e1, final T2 e2) { } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } public T2 get2() { - @SuppressWarnings("unchecked") final T2 result = (T2) elem(1); + @SuppressWarnings("unchecked") + final T2 result = (T2) elem(1); return result; } @@ -45,5 +46,4 @@ public R unpackTo(final BiFunction function) { checkNotNull(function); return function.apply(get1(), get2()); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple3.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple3.java index 0a894094a5..fd41f22d10 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple3.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple3.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -30,17 +30,20 @@ public static Tuple3 of(final T1 e1, final T2 e2, final } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } public T2 get2() { - @SuppressWarnings("unchecked") final T2 result = (T2) elem(1); + @SuppressWarnings("unchecked") + final T2 result = (T2) elem(1); return result; } public T3 get3() { - @SuppressWarnings("unchecked") final T3 result = (T3) elem(2); + @SuppressWarnings("unchecked") + final T3 result = (T3) elem(2); return result; } @@ -49,5 +52,4 @@ public R unpackTo( checkNotNull(function); return function.apply(get1(), get2(), get3()); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple4.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple4.java index f168bc7492..4026b7ce26 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple4.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple4.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,29 +23,32 @@ private Tuple4(final T1 e1, final T2 e2, final T3 e3, final T4 e4) { super(ImmutableList.of(e1, e2, e3, e4)); } - public static Tuple4 of(final T1 e1, final T2 e2, final T3 e3, - final T4 e4) { + public static Tuple4 of( + final T1 e1, final T2 e2, final T3 e3, final T4 e4) { return new Tuple4<>(e1, e2, e3, e4); } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } public T2 get2() { - @SuppressWarnings("unchecked") final T2 result = (T2) elem(1); + @SuppressWarnings("unchecked") + final T2 result = (T2) elem(1); return result; } public T3 get3() { - @SuppressWarnings("unchecked") final T3 result = (T3) elem(2); + @SuppressWarnings("unchecked") + final T3 result = (T3) elem(2); return result; } public T4 get4() { - @SuppressWarnings("unchecked") final T4 result = (T4) elem(3); + @SuppressWarnings("unchecked") + final T4 result = (T4) elem(3); return result; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple5.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple5.java index 3a9cc69bee..ffda908803 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple5.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple5.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,35 +23,38 @@ private Tuple5(final T1 e1, final T2 e2, final T3 e3, final T4 e4, final T5 e5) super(ImmutableList.of(e1, e2, e3, e4, e5)); } - public static Tuple5 of(final T1 e1, final T2 e2, - final T3 e3, final T4 e4, - final T5 e5) { + public static Tuple5 of( + final T1 e1, final T2 e2, final T3 e3, final T4 e4, final T5 e5) { return new Tuple5<>(e1, e2, e3, e4, e5); } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } public T2 get2() { - @SuppressWarnings("unchecked") final T2 result = (T2) elem(1); + @SuppressWarnings("unchecked") + final T2 result = (T2) elem(1); return result; } public T3 get3() { - @SuppressWarnings("unchecked") final T3 result = (T3) elem(2); + @SuppressWarnings("unchecked") + final T3 result = (T3) elem(2); return result; } public T4 get4() { - @SuppressWarnings("unchecked") final T4 result = (T4) elem(3); + @SuppressWarnings("unchecked") + final T4 result = (T4) elem(3); return result; } public T5 get5() { - @SuppressWarnings("unchecked") final T5 result = (T5) elem(4); + @SuppressWarnings("unchecked") + final T5 result = (T5) elem(4); return result; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple6.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple6.java index 98f76e01ba..9f01f1b4e9 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple6.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple6.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,40 +23,44 @@ private Tuple6(final T1 e1, final T2 e2, final T3 e3, final T4 e4, final T5 e5, super(ImmutableList.of(e1, e2, e3, e4, e5, e6)); } - public static Tuple6 of(final T1 e1, - final T2 e2, final T3 e3, - final T4 e4, final T5 e5, final T6 e6) { + public static Tuple6 of( + final T1 e1, final T2 e2, final T3 e3, final T4 e4, final T5 e5, final T6 e6) { return new Tuple6<>(e1, e2, e3, e4, e5, e6); } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } public T2 get2() { - @SuppressWarnings("unchecked") final T2 result = (T2) elem(1); + @SuppressWarnings("unchecked") + final T2 result = (T2) elem(1); return result; } public T3 get3() { - @SuppressWarnings("unchecked") final T3 result = (T3) elem(2); + @SuppressWarnings("unchecked") + final T3 result = (T3) elem(2); return result; } public T4 get4() { - @SuppressWarnings("unchecked") final T4 result = (T4) elem(3); + @SuppressWarnings("unchecked") + final T4 result = (T4) elem(3); return result; } public T5 get5() { - @SuppressWarnings("unchecked") final T5 result = (T5) elem(4); + @SuppressWarnings("unchecked") + final T5 result = (T5) elem(4); return result; } public T6 get6() { - @SuppressWarnings("unchecked") final T6 result = (T6) elem(5); + @SuppressWarnings("unchecked") + final T6 result = (T6) elem(5); return result; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple7.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple7.java index ff63a0f200..e80f1024be 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple7.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Tuple7.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,50 +19,67 @@ public final class Tuple7 extends Tuple { - private Tuple7(final T1 e1, final T2 e2, final T3 e3, final T4 e4, final T5 e5, final T6 e6, - final T7 e7) { + private Tuple7( + final T1 e1, + final T2 e2, + final T3 e3, + final T4 e4, + final T5 e5, + final T6 e6, + final T7 e7) { super(ImmutableList.of(e1, e2, e3, e4, e5, e6, e7)); } - public static Tuple7 of(final T1 e1, - final T2 e2, - final T3 e3, final T4 e4, final T5 e5, final T6 e6, final T7 e7) { + public static Tuple7 of( + final T1 e1, + final T2 e2, + final T3 e3, + final T4 e4, + final T5 e5, + final T6 e6, + final T7 e7) { return new Tuple7<>(e1, e2, e3, e4, e5, e6, e7); } public T1 get1() { - @SuppressWarnings("unchecked") final T1 result = (T1) elem(0); + @SuppressWarnings("unchecked") + final T1 result = (T1) elem(0); return result; } public T2 get2() { - @SuppressWarnings("unchecked") final T2 result = (T2) elem(1); + @SuppressWarnings("unchecked") + final T2 result = (T2) elem(1); return result; } public T3 get3() { - @SuppressWarnings("unchecked") final T3 result = (T3) elem(2); + @SuppressWarnings("unchecked") + final T3 result = (T3) elem(2); return result; } public T4 get4() { - @SuppressWarnings("unchecked") final T4 result = (T4) elem(3); + @SuppressWarnings("unchecked") + final T4 result = (T4) elem(3); return result; } public T5 get5() { - @SuppressWarnings("unchecked") final T5 result = (T5) elem(4); + @SuppressWarnings("unchecked") + final T5 result = (T5) elem(4); return result; } public T6 get6() { - @SuppressWarnings("unchecked") final T6 result = (T6) elem(5); + @SuppressWarnings("unchecked") + final T6 result = (T6) elem(5); return result; } public T7 get7() { - @SuppressWarnings("unchecked") final T7 result = (T7) elem(6); + @SuppressWarnings("unchecked") + final T7 result = (T7) elem(6); return result; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TupleN.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TupleN.java index 70e424309e..8345d0fff7 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TupleN.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/TupleN.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,7 +16,6 @@ package hu.bme.mit.theta.common; import com.google.common.collect.ImmutableList; - import java.util.List; public final class TupleN extends Tuple { @@ -35,38 +34,44 @@ public static TupleN of(final List l) { } public static TupleN of(final Tuple2 tuple) { - @SuppressWarnings("unchecked") TupleN ret = new TupleN<>((List) tuple.toList()); + @SuppressWarnings("unchecked") + TupleN ret = new TupleN<>((List) tuple.toList()); return ret; } public static TupleN of(final Tuple3 tuple) { - @SuppressWarnings("unchecked") TupleN ret = new TupleN<>((List) tuple.toList()); + @SuppressWarnings("unchecked") + TupleN ret = new TupleN<>((List) tuple.toList()); return ret; } public static TupleN of(final Tuple4 tuple) { - @SuppressWarnings("unchecked") TupleN ret = new TupleN<>((List) tuple.toList()); + @SuppressWarnings("unchecked") + TupleN ret = new TupleN<>((List) tuple.toList()); return ret; } public static TupleN of(final Tuple5 tuple) { - @SuppressWarnings("unchecked") TupleN ret = new TupleN<>((List) tuple.toList()); + @SuppressWarnings("unchecked") + TupleN ret = new TupleN<>((List) tuple.toList()); return ret; } public static TupleN of(final Tuple6 tuple) { - @SuppressWarnings("unchecked") TupleN ret = new TupleN<>((List) tuple.toList()); + @SuppressWarnings("unchecked") + TupleN ret = new TupleN<>((List) tuple.toList()); return ret; } public static TupleN of(final Tuple7 tuple) { - @SuppressWarnings("unchecked") TupleN ret = new TupleN<>((List) tuple.toList()); + @SuppressWarnings("unchecked") + TupleN ret = new TupleN<>((List) tuple.toList()); return ret; } public T get(int i) { - @SuppressWarnings("unchecked") final T result = (T) elem(i); + @SuppressWarnings("unchecked") + final T result = (T) elem(i); return result; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Unit.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Unit.java index 522e278e8a..2dfa3b3cfd 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Unit.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Unit.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,8 +22,7 @@ public final class Unit { private static final Unit UNIT = new Unit(); - private Unit() { - } + private Unit() {} public static Unit unit() { return UNIT; @@ -43,5 +42,4 @@ public boolean equals(final Object obj) { public String toString() { return TO_STRING; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Utils.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Utils.java index afa892000a..2d3494643a 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Utils.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.common; +import static com.google.common.base.Preconditions.checkArgument; + import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.function.Predicate; -import static com.google.common.base.Preconditions.checkArgument; - public final class Utils { - private Utils() { - } + private Utils() {} public static T singleElementOf(final Iterable collection) { final Iterator iterator = collection.iterator(); @@ -55,8 +54,8 @@ public static List tail(final List list) { //// - public static boolean anyMatch(final Optional optional, - final Predicate predicate) { + public static boolean anyMatch( + final Optional optional, final Predicate predicate) { if (optional.isPresent()) { return predicate.test(optional.get()); } else { @@ -64,8 +63,8 @@ public static boolean anyMatch(final Optional optional, } } - public static boolean allMatch(final Optional optional, - final Predicate predicate) { + public static boolean allMatch( + final Optional optional, final Predicate predicate) { if (optional.isPresent()) { return predicate.test(optional.get()); } else { @@ -80,5 +79,4 @@ public static LispStringBuilder lispStringBuilder() { public static LispStringBuilder lispStringBuilder(final String prefix) { return new LispStringBuilder(prefix); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/Containers.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/Containers.java index ddfb9b3f24..ccb8a21870 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/Containers.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/Containers.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.common.container; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.container.factory.ContainerFactory; import hu.bme.mit.theta.common.container.factory.LinkedHashContainerFactory; - import java.util.Collection; import java.util.Map; import java.util.Set; -import static com.google.common.base.Preconditions.checkNotNull; - public class Containers { private static ContainerFactory containerFactory = new LinkedHashContainerFactory(); @@ -64,5 +63,4 @@ public static Set createSet(int initialCapacity, float loadFactor) { public static Set createSet(Collection c) { return containerFactory.createSet(c); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/ContainerFactory.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/ContainerFactory.java index 9defc04981..dda2c8be19 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/ContainerFactory.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/ContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -36,5 +36,4 @@ public interface ContainerFactory { Set createSet(int initialCapacity, float loadFactor); Set createSet(Collection c); - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/HashContainerFactory.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/HashContainerFactory.java index c4966b0b35..50e9686294 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/HashContainerFactory.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/HashContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/LinkedHashContainerFactory.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/LinkedHashContainerFactory.java index ea54236c6c..2e7b18b1a4 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/LinkedHashContainerFactory.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/container/factory/LinkedHashContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/Datalog.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/Datalog.java index a5caa4c8f5..82e9b86c04 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/Datalog.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/Datalog.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.common.datalog; /* @@ -24,11 +23,12 @@ * http://pages.cs.wisc.edu/~paris/cs838-s16/lecture-notes/lecture8.pdf */ +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Tuple3; import hu.bme.mit.theta.common.TupleN; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -41,8 +41,6 @@ import java.util.StringJoiner; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkState; - public class Datalog { private final Map relations; private boolean debug = false; @@ -82,50 +80,78 @@ public static String runProgram(String relations) { Map relationMap = new LinkedHashMap<>(); for (String expression : relations.split("\\.")) { String nospace = expression.replaceAll("[ \t\n]", ""); - if (nospace.matches("([a-z_][a-zA-Z0-9_]*)\\(([a-z_0-9][a-zA-Z0-9_]*)(,[a-z_0-9][a-zA-Z_0-9]*)*\\)")) { //fact assertion + if (nospace.matches( + "([a-z_][a-zA-Z0-9_]*)\\(([a-z_0-9][a-zA-Z0-9_]*)(,[a-z_0-9][a-zA-Z_0-9]*)*\\)")) { // fact assertion String[] splitString = nospace.split("\\("); String[] arguments = splitString[1].replaceAll("\\)", "").split(","); - relationMap.putIfAbsent(splitString[0], datalog.createRelation("rel" + counter++, arguments.length)); - TupleN argumentTuple = TupleN.of(Arrays.stream(arguments).map(StringDatalogArgument::new).collect(Collectors.toList())); + relationMap.putIfAbsent( + splitString[0], + datalog.createRelation("rel" + counter++, arguments.length)); + TupleN argumentTuple = + TupleN.of( + Arrays.stream(arguments) + .map(StringDatalogArgument::new) + .collect(Collectors.toList())); relationMap.get(splitString[0]).addFact(argumentTuple); - } else if (nospace.matches("([a-z_][a-zA-Z_0-9]*)\\(([a-zA-Z_][a-zA-Z0-9_]*)(,[a-zA-Z_][a-zA-Z0-9_]*)*\\):-([a-z_][a-zA-Z_]*)\\(([a-zA-Z_][a-zA-Z0-9_]*)(,[a-zA-Z_][a-zA-Z0-9_]*)*\\)(,([a-z_][a-zA-Z_]*)\\(([a-zA-Z_][a-zA-Z0-9_]*)(,[a-zA-Z_][a-zA-Z0-9_]*)*\\))*")) { //deduction rule + } else if (nospace.matches( + "([a-z_][a-zA-Z_0-9]*)\\(([a-zA-Z_][a-zA-Z0-9_]*)(,[a-zA-Z_][a-zA-Z0-9_]*)*\\):-([a-z_][a-zA-Z_]*)\\(([a-zA-Z_][a-zA-Z0-9_]*)(,[a-zA-Z_][a-zA-Z0-9_]*)*\\)(,([a-z_][a-zA-Z_]*)\\(([a-zA-Z_][a-zA-Z0-9_]*)(,[a-zA-Z_][a-zA-Z0-9_]*)*\\))*")) { // deduction rule String[] splitExpression = nospace.split(":-"); Map variableMap = new LinkedHashMap<>(); String[] splitString = splitExpression[0].split("\\("); String[] arguments = splitString[1].replaceAll("\\)", "").split(","); - relationMap.putIfAbsent(splitString[0], datalog.createRelation("rel" + counter++, arguments.length)); - TupleN argumentTuple = TupleN.of(Arrays.stream(arguments).map(s -> { - variableMap.putIfAbsent(s, datalog.getVariable()); - return variableMap.get(s); - }).collect(Collectors.toList())); + relationMap.putIfAbsent( + splitString[0], + datalog.createRelation("rel" + counter++, arguments.length)); + TupleN argumentTuple = + TupleN.of( + Arrays.stream(arguments) + .map( + s -> { + variableMap.putIfAbsent( + s, datalog.getVariable()); + return variableMap.get(s); + }) + .collect(Collectors.toList())); Set>> dependencies = new LinkedHashSet<>(); for (String dependency : splitExpression[1].split("\\),")) { String[] dsplitString = dependency.split("\\("); String[] darguments = dsplitString[1].replaceAll("\\)", "").split(","); - relationMap.putIfAbsent(dsplitString[0], datalog.createRelation("rel" + counter++, darguments.length)); - TupleN dargumentTuple = TupleN.of(Arrays.stream(darguments).map(s -> { - variableMap.putIfAbsent(s, datalog.getVariable()); - return variableMap.get(s); - }).collect(Collectors.toList())); + relationMap.putIfAbsent( + dsplitString[0], + datalog.createRelation("rel" + counter++, darguments.length)); + TupleN dargumentTuple = + TupleN.of( + Arrays.stream(darguments) + .map( + s -> { + variableMap.putIfAbsent( + s, datalog.getVariable()); + return variableMap.get(s); + }) + .collect(Collectors.toList())); dependencies.add(Tuple2.of(relationMap.get(dsplitString[0]), dargumentTuple)); } relationMap.get(splitString[0]).addRule(argumentTuple, dependencies); - } else if (nospace.matches("([a-z_][a-zA-Z_]*)\\?")) { //query + } else if (nospace.matches("([a-z_][a-zA-Z_]*)\\?")) { // query String noquestion = nospace.replaceAll("\\?", ""); if (!relationMap.containsKey(noquestion)) - throw new RuntimeException("Query " + nospace + " does not query an existing relation!"); + throw new RuntimeException( + "Query " + nospace + " does not query an existing relation!"); for (TupleN element : relationMap.get(noquestion).getElements()) { StringBuilder stringBuilder = new StringBuilder(noquestion + "("); for (Object o : element) { stringBuilder.append(o.toString()).append(","); } - ret.append(stringBuilder.substring(0, stringBuilder.length() - 1)).append(").").append("\r\n"); + ret.append(stringBuilder.substring(0, stringBuilder.length() - 1)) + .append(").") + .append("\r\n"); } } else { - throw new RuntimeException("Input " + nospace + " does not match any type of expression!"); + throw new RuntimeException( + "Input " + nospace + " does not match any type of expression!"); } } return ret.toString(); @@ -137,12 +163,10 @@ private void refresh() { cnt = 0; for (Relation relation : relations.values()) { int i = relation.calc(); - if (debug) - System.out.println(i + " new facts"); + if (debug) System.out.println(i + " new facts"); cnt += i; } - if (debug) - System.out.println("===="); + if (debug) System.out.println("===="); } while (cnt > 0); for (Relation relation : relations.values()) { relation.flush(); @@ -150,7 +174,9 @@ private void refresh() { } public Relation createRelation(String name, int n) { - checkState(stackDepth == 0, "Cannot create a relation when the program is in temporary (pushed) state"); + checkState( + stackDepth == 0, + "Cannot create a relation when the program is in temporary (pushed) state"); checkState(n > 0, "Relation must have positive arity"); Relation ret = new Relation(name, n); relations.put(name, ret); @@ -162,39 +188,13 @@ public Relation createTransitive(String name, Relation simple) { Relation path = createRelation(name, 2); Datalog.Variable var1, var2, var3; path.addRule( - TupleN.of( - var1 = getVariable(), - var2 = getVariable() - ), - Set.of( - Tuple2.of( - simple, - TupleN.of(var1, var2) - ) - ) - ); + TupleN.of(var1 = getVariable(), var2 = getVariable()), + Set.of(Tuple2.of(simple, TupleN.of(var1, var2)))); path.addRule( - TupleN.of( - var1 = getVariable(), - var2 = getVariable() - ), + TupleN.of(var1 = getVariable(), var2 = getVariable()), Set.of( - Tuple2.of( - path, - TupleN.of( - var1, - var3 = getVariable() - ) - ), - Tuple2.of( - path, - TupleN.of( - var3, - var2 - ) - ) - ) - ); + Tuple2.of(path, TupleN.of(var1, var3 = getVariable())), + Tuple2.of(path, TupleN.of(var3, var2)))); return path; } @@ -203,27 +203,10 @@ public Relation createCommonSource(String name, Relation simple) { Relation path = createRelation(name, 2); Datalog.Variable var1 = getVariable(), var2 = getVariable(), var3 = getVariable(); path.addRule( - TupleN.of( - var1, - var2 - ), + TupleN.of(var1, var2), Set.of( - Tuple2.of( - simple, - TupleN.of( - var3, - var1 - ) - ), - Tuple2.of( - simple, - TupleN.of( - var3, - var2 - ) - ) - ) - ); + Tuple2.of(simple, TupleN.of(var3, var1)), + Tuple2.of(simple, TupleN.of(var3, var2)))); return path; } @@ -232,7 +215,8 @@ public Relation createDisjunction(String name, Iterable relations) { for (Relation relation : relations) { if (arity == null) arity = relation.getArity(); else - checkState(relation.getArity() == arity, "Only same arity relations are supported!"); + checkState( + relation.getArity() == arity, "Only same arity relations are supported!"); } checkState(arity != null, "At least one relation is necessary!"); Relation disjunction = createRelation(name, arity); @@ -242,15 +226,7 @@ public Relation createDisjunction(String name, Iterable relations) { } TupleN varTuple = TupleN.of(vars); for (Relation relation : relations) { - disjunction.addRule( - varTuple, - Set.of( - Tuple2.of( - relation, - varTuple - ) - ) - ); + disjunction.addRule(varTuple, Set.of(Tuple2.of(relation, varTuple))); } return disjunction; } @@ -268,16 +244,14 @@ public Relation createConjuction(String name, Iterable relations) { } varTuple = TupleN.of(vars); } else - checkState(relation.getArity() == arity, "Only same arity relations are supported!"); + checkState( + relation.getArity() == arity, "Only same arity relations are supported!"); deps.add(Tuple2.of(relation, varTuple)); } checkState(arity != null, "At least one relation is necessary!"); Relation conjuction = createRelation(name, arity); - conjuction.addRule( - varTuple, - deps - ); + conjuction.addRule(varTuple, deps); return conjuction; } @@ -293,8 +267,7 @@ public Variable getVariable() { return new Variable(); } - public static class Variable { - } + public static class Variable {} public class Relation { private final String name; @@ -303,7 +276,12 @@ public class Relation { private final Set> toAdd; private final Set, Set>>>> rules; private final int arity; - private final Stack>, Set>, Set>>> stack; + private final Stack< + Tuple3< + Set>, + Set>, + Set>>> + stack; private Relation(int n) { this("", n); @@ -329,8 +307,11 @@ public void addFact(TupleN fact) { refresh(); } - public void addRule(TupleN args, Set>> dependencies) { - checkState(stackDepth == 0, "Cannot create new rule when the program is in temporary (pushed) state"); + public void addRule( + TupleN args, Set>> dependencies) { + checkState( + stackDepth == 0, + "Cannot create new rule when the program is in temporary (pushed) state"); checkState(args.arity() == arity); for (Tuple2> dependency : dependencies) { checkState(dependency.get1().arity == dependency.get2().arity()); @@ -349,19 +330,24 @@ public int getArity() { return arity; } - private boolean validate(List>> oldClauses, Map currentAssignments, List> assignments) { + private boolean validate( + List>> oldClauses, + Map currentAssignments, + List> assignments) { List>> clauses = new ArrayList<>(oldClauses); if (clauses.size() > 0) { Tuple2> clause = clauses.get(0); clauses.remove(0); for (TupleN element : clause.get1().elements) { - Map nextAssignments = new LinkedHashMap<>(currentAssignments); + Map nextAssignments = + new LinkedHashMap<>(currentAssignments); if (!putAssignments(nextAssignments, clause, element)) { validate(clauses, nextAssignments, assignments); } } for (TupleN element : clause.get1().newElements) { - Map nextAssignments = new LinkedHashMap<>(currentAssignments); + Map nextAssignments = + new LinkedHashMap<>(currentAssignments); if (!putAssignments(nextAssignments, clause, element)) { validate(clauses, nextAssignments, assignments); } @@ -381,7 +367,10 @@ private int calc() { boolean atLeastOne = true; while (atLeastOne) { atLeastOne = false; - for (TupleN newElement : clause.get1().newElements.stream().filter(objects -> !alreadyAdded.contains(objects)).collect(Collectors.toCollection(LinkedHashSet::new))) { + for (TupleN newElement : + clause.get1().newElements.stream() + .filter(objects -> !alreadyAdded.contains(objects)) + .collect(Collectors.toCollection(LinkedHashSet::new))) { cnt = addElements(cnt, rule, clause, newElement); alreadyAdded.add(newElement); atLeastOne = true; @@ -391,7 +380,10 @@ private int calc() { atLeastOne = true; while (atLeastOne) { atLeastOne = false; - for (TupleN newElement : clause.get1().toAdd.stream().filter(objects -> !alreadyAdded.contains(objects)).collect(Collectors.toCollection(LinkedHashSet::new))) { + for (TupleN newElement : + clause.get1().toAdd.stream() + .filter(objects -> !alreadyAdded.contains(objects)) + .collect(Collectors.toCollection(LinkedHashSet::new))) { cnt = addElements(cnt, rule, clause, newElement); alreadyAdded.add(newElement); atLeastOne = true; @@ -402,10 +394,13 @@ private int calc() { return cnt; } - private int addElements(int cnt, Tuple2, Set>>> rule, Tuple2> clause, TupleN newElement) { + private int addElements( + int cnt, + Tuple2, Set>>> rule, + Tuple2> clause, + TupleN newElement) { Map assignments = new LinkedHashMap<>(); - if (putAssignments(assignments, clause, newElement)) - return cnt; + if (putAssignments(assignments, clause, newElement)) return cnt; if (debug) { System.out.println("\t(" + name + ")Checking " + newElement); } @@ -417,11 +412,15 @@ private int addElements(int cnt, Tuple2, Set arguments = new ArrayList<>(); for (Object o : rule.get1()) { Variable v = (Variable) o; - checkState(satisfyingAssignment.containsKey(v), "Not all variables are bound!"); + checkState( + satisfyingAssignment.containsKey(v), + "Not all variables are bound!"); arguments.add(satisfyingAssignment.get(v)); } TupleN item = TupleN.of(arguments); - if (!elements.contains(item) && !newElements.contains(item) && !toAdd.contains(item)) { + if (!elements.contains(item) + && !newElements.contains(item) + && !toAdd.contains(item)) { toAdd.add(item); if (debug) { System.out.println("(" + name + ")Adding " + item); @@ -429,12 +428,14 @@ private int addElements(int cnt, Tuple2, Set assignments, Tuple2> validatorClause, TupleN element) { + private boolean putAssignments( + Map assignments, + Tuple2> validatorClause, + TupleN element) { for (int i = 0; i < element.arity(); i++) { if (assignments.containsKey(validatorClause.get2().get(i))) { if (!assignments.get(validatorClause.get2().get(i)).equals(element.get(i))) @@ -449,9 +450,14 @@ private boolean putAssignments(Map assignments, Tuple private void flush() { if (debug) { StringBuilder stringBuilder = new StringBuilder("["); - newElements.forEach(objects -> stringBuilder.append(objects.toString()).append(", ")); - - System.out.println("(" + name + ") Promoting newElements to elements: " + stringBuilder.append("]").toString()); + newElements.forEach( + objects -> stringBuilder.append(objects.toString()).append(", ")); + + System.out.println( + "(" + + name + + ") Promoting newElements to elements: " + + stringBuilder.append("]").toString()); } elements.addAll(newElements); newElements.clear(); @@ -460,26 +466,32 @@ private void flush() { StringBuilder stringBuilder1 = new StringBuilder("["); toAdd.forEach(objects -> stringBuilder1.append(objects.toString()).append(", ")); - System.out.println("(" + name + ") Promoting toAdd to newElements: " + stringBuilder1.append("]").toString()); + System.out.println( + "(" + + name + + ") Promoting toAdd to newElements: " + + stringBuilder1.append("]").toString()); } newElements.addAll(toAdd); toAdd.clear(); } - public void push() { stack.push(Tuple3.of(Set.copyOf(elements), Set.copyOf(newElements), Set.copyOf(toAdd))); } public void pop() { - final Tuple3>, Set>, Set>> popped = stack.pop(); + final Tuple3< + Set>, + Set>, + Set>> + popped = stack.pop(); elements.clear(); elements.addAll(popped.get1()); newElements.clear(); newElements.addAll(popped.get2()); toAdd.clear(); toAdd.addAll(popped.get3()); - } @Override diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/DatalogArgument.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/DatalogArgument.java index d27aa34fe4..6eb1b36c7b 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/DatalogArgument.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/DatalogArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.common.datalog; /* * Every atom used with the Datalog engine must implement this interface */ -public interface DatalogArgument { - -} +public interface DatalogArgument {} diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/GenericDatalogArgument.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/GenericDatalogArgument.java index f8d3278b28..9207876b13 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/GenericDatalogArgument.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/GenericDatalogArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.common.datalog; public class GenericDatalogArgument implements DatalogArgument { diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/StringDatalogArgument.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/StringDatalogArgument.java index 8b0a5c261e..4012dbcb7e 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/StringDatalogArgument.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/datalog/StringDatalogArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.common.datalog; public class StringDatalogArgument implements DatalogArgument { diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicDynamicScope.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicDynamicScope.java index 3366c96701..7edb660531 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicDynamicScope.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicDynamicScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,11 @@ */ package hu.bme.mit.theta.common.dsl; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Collection; import java.util.Optional; -import static com.google.common.base.Preconditions.checkNotNull; - public class BasicDynamicScope implements DynamicScope { private final Optional enclosingScope; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScope.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScope.java index 232685227b..5831853b6a 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScope.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -57,5 +57,4 @@ public Optional resolve(final String name) { return enclosingScope.get().resolve(name); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScopedSymbol.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScopedSymbol.java index 90fe8d6678..128490f415 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScopedSymbol.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/BasicScopedSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,8 +26,10 @@ public final class BasicScopedSymbol implements ScopedSymbol { private final String name; private final BasicScope scope; - public BasicScopedSymbol(final String name, final Scope eclosingScope, - final Collection symbols) { + public BasicScopedSymbol( + final String name, + final Scope eclosingScope, + final Collection symbols) { checkNotNull(name); checkArgument(name.length() > 0); this.name = name; @@ -60,5 +62,4 @@ public Optional resolve(final String name) { public Optional enclosingScope() { return scope.enclosingScope(); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/DynamicScope.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/DynamicScope.java index 4b5b7cf81b..2f8b4bb1ae 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/DynamicScope.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/DynamicScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,5 +25,4 @@ public interface DynamicScope extends Scope { void declareAll(final Collection symbols); Optional enclosingScope(); - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Env.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Env.java index 3c4536e6b5..c769e804cc 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Env.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Env.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.common.dsl; +import static com.google.common.base.Preconditions.*; +import static java.util.stream.Collectors.toList; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; - import java.util.Map; import java.util.StringJoiner; import java.util.function.Function; -import static com.google.common.base.Preconditions.*; -import static java.util.stream.Collectors.toList; - public final class Env { private Frame currentFrame; @@ -71,8 +70,8 @@ public String toString() { return sj.toString(); } - public Object compute(final S symbol, - final Function mapping) { + public Object compute( + final S symbol, final Function mapping) { checkNotNull(symbol); checkNotNull(mapping); Object value = currentFrame.eval(symbol); @@ -94,7 +93,8 @@ private Frame(final Frame parent) { } public void define(final Symbol symbol, final Object value) { - checkArgument(eval(symbol) == null, "Symbol " + symbol.getName() + " is already defined"); + checkArgument( + eval(symbol) == null, "Symbol " + symbol.getName() + " is already defined"); symbolToValue.put(symbol, value); } @@ -111,9 +111,12 @@ public Object eval(final Symbol symbol) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).addAll(symbolToValue.entrySet().stream() - .map(e -> e.getKey().getName() + " <- " + e.getValue()).collect(toList())).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .addAll( + symbolToValue.entrySet().stream() + .map(e -> e.getKey().getName() + " <- " + e.getValue()) + .collect(toList())) + .toString(); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/MutableScope.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/MutableScope.java index 5f57514977..d8b9b3823e 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/MutableScope.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/MutableScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ public interface MutableScope extends Scope { void add(final Symbol symbol); void addAll(final Iterable symbols); - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Scope.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Scope.java index ca2dc6f150..48c16744a2 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Scope.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Scope.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,5 +22,4 @@ public interface Scope { Optional enclosingScope(); Optional resolve(String name); - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/ScopedSymbol.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/ScopedSymbol.java index ff6655d142..e5d839ab75 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/ScopedSymbol.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/ScopedSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,4 @@ */ package hu.bme.mit.theta.common.dsl; -public interface ScopedSymbol extends Scope, Symbol { - -} +public interface ScopedSymbol extends Scope, Symbol {} diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Symbol.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Symbol.java index b96c998226..bb4907537c 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Symbol.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/Symbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ public interface Symbol { String getName(); - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/SymbolTable.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/SymbolTable.java index c6508b304e..410e8296aa 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/SymbolTable.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/dsl/SymbolTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -34,7 +34,8 @@ public SymbolTable() { public void add(final Symbol symbol) { checkNotNull(symbol); - checkArgument(!stringToSymbol.containsKey(symbol.getName()), + checkArgument( + !stringToSymbol.containsKey(symbol.getName()), String.format("Symbol %s is already declared in this scope", symbol.getName())); stringToSymbol.put(symbol.getName(), symbol); } @@ -59,5 +60,4 @@ public String toString() { } return sj.toString(); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/exception/NotSolvableException.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/exception/NotSolvableException.java index 47ecf977dd..4c30ddae28 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/exception/NotSolvableException.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/exception/NotSolvableException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.common.exception; public class NotSolvableException extends RuntimeException { @@ -21,4 +20,4 @@ public class NotSolvableException extends RuntimeException { public NotSolvableException() { super("Task is not solvable with this configuration!"); } -} \ No newline at end of file +} diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/BaseLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/BaseLogger.java index 134abc1f81..0064f3a8c5 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/BaseLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/BaseLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,7 @@ */ package hu.bme.mit.theta.common.logging; -/** - * Base class for loggers. Only prints entries above a given level. - */ +/** Base class for loggers. Only prints entries above a given level. */ public abstract class BaseLogger implements Logger { private final Level minLevel; @@ -35,5 +33,4 @@ public Logger write(final Level level, final String pattern, final Object... obj } protected abstract void writeStr(String str); - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLabelledLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLabelledLogger.java index dd0ef193e7..cbee750443 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLabelledLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLabelledLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLogger.java index 3c544f28b0..ee99ca6468 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/ConsoleLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,5 +29,4 @@ public ConsoleLogger(final Level minLevel) { protected void writeStr(final String str) { CONSOLE.print(str); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/FileLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/FileLogger.java index 5495a05bf9..5b9c6f1b36 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/FileLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/FileLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,8 +24,11 @@ public final class FileLogger extends BaseLogger { private final PrintWriter pw; private final boolean instantFlush; - public FileLogger(final Level minLevel, final String fileName, final boolean instantFlush, - final boolean append) + public FileLogger( + final Level minLevel, + final String fileName, + final boolean instantFlush, + final boolean append) throws FileNotFoundException { super(minLevel); pw = new PrintWriter(new FileOutputStream(fileName, append)); @@ -43,5 +46,4 @@ protected void writeStr(final String str) { pw.flush(); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/Logger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/Logger.java index 6cd2229ccb..3e556d995c 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/Logger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/Logger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/NullLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/NullLogger.java index ee9bad5e11..ba41051595 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/NullLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/NullLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,8 +22,7 @@ private static final class LazyHolder { private static final NullLogger INSTANCE = new NullLogger(); } - private NullLogger() { - } + private NullLogger() {} public static NullLogger getInstance() { return LazyHolder.INSTANCE; @@ -33,5 +32,4 @@ public static NullLogger getInstance() { public Logger write(final Level level, final String pattern, final Object... objects) { return this; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/UniqueWarningLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/UniqueWarningLogger.java index 14f212bf4f..d77c9489a9 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/UniqueWarningLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/UniqueWarningLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/package-info.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/package-info.java index 14db0042ae..ecc8c19915 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/package-info.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/logging/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ * @see hu.bme.mit.theta.common.logging.ConsoleLogger * @see hu.bme.mit.theta.common.logging.FileLogger */ - -package hu.bme.mit.theta.common.logging; \ No newline at end of file +package hu.bme.mit.theta.common.logging; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LexerException.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LexerException.java index 9364e2d757..32cd2eca1c 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LexerException.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LexerException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,5 +26,4 @@ public LexerException(final String message) { public LexerException(final Throwable cause) { super(cause); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispLexer.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispLexer.java index 1d7c698b38..a4ac59d1cc 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispLexer.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispLexer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -104,5 +104,4 @@ private void match(final char x) { throw new LexerException("Expecting " + x + ", found " + c); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispParser.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispParser.java index 0d0a59d6df..9b618ce0c9 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispParser.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/LispParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,10 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.common.parser.SExpr.SAtom; import hu.bme.mit.theta.common.parser.SExpr.SList; +import java.util.List; public final class LispParser { @@ -88,5 +86,4 @@ private void consume() { lookahead(); lookahead = null; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/ParserException.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/ParserException.java index ea75de66b2..51d7ed1b42 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/ParserException.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/ParserException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,5 +22,4 @@ public final class ParserException extends RuntimeException { public ParserException(final String message) { super(message); } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/SExpr.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/SExpr.java index 236b61f8ec..7c57b5b3ee 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/SExpr.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/SExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,21 @@ */ package hu.bme.mit.theta.common.parser; -import com.google.common.collect.ImmutableList; - -import java.io.Reader; -import java.io.StringReader; -import java.util.Iterator; -import java.util.List; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.Streams.stream; import static java.util.stream.Collectors.joining; +import com.google.common.collect.ImmutableList; +import java.io.Reader; +import java.io.StringReader; +import java.util.Iterator; +import java.util.List; + public abstract class SExpr { - private SExpr() { - } + private SExpr() {} public static SAtom atom(final String atom) { return new SAtom(atom); @@ -52,13 +50,13 @@ public static SExpr build(final Object object) { return atom(string); } else if (object instanceof Iterable) { final Iterable iterable = (Iterable) object; - final List sexprs = stream(iterable).map(SExpr::build) - .collect(toImmutableList()); + final List sexprs = + stream(iterable).map(SExpr::build).collect(toImmutableList()); return list(sexprs); } else { throw new IllegalArgumentException( - "Only String and Iterable types are supported, found: " + object.getClass() - .getSimpleName()); + "Only String and Iterable types are supported, found: " + + object.getClass().getSimpleName()); } } @@ -205,5 +203,4 @@ public String toString() { return list.stream().map(Object::toString).collect(joining(SPACE, LPAREN, RPAREN)); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/Token.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/Token.java index 006e230cd2..130ae596d1 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/Token.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/Token.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -70,5 +70,4 @@ public boolean equals(final Object obj) { public String toString() { return string; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/TokenType.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/TokenType.java index 82cf153800..7da8f142a0 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/TokenType.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/parser/TokenType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,8 @@ package hu.bme.mit.theta.common.parser; public enum TokenType { - EOF, LPAREN, RPAREN, ATOM + EOF, + LPAREN, + RPAREN, + ATOM } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/process/SimpleProcessRunner.kt b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/process/SimpleProcessRunner.kt index a7964e735e..717e457557 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/process/SimpleProcessRunner.kt +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/process/SimpleProcessRunner.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/BasicTableWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/BasicTableWriter.java index a2d9d4899a..3681d5f93d 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/BasicTableWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/BasicTableWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,8 +20,8 @@ /** * A simple table writer that prints tables to a PrintStream using an arbitrary delimeter and a cell * pre/postfix. - *

- * For exemple in ordinary CSV files, the delimeter is ',' and the pre/postfix is '"'. + * + *

For exemple in ordinary CSV files, the delimeter is ',' and the pre/postfix is '"'. */ public final class BasicTableWriter implements TableWriter { @@ -31,8 +31,11 @@ public final class BasicTableWriter implements TableWriter { private final String postfix; private boolean isFirstCell = true; - public BasicTableWriter(final PrintStream stream, final String delimeter, final String prefix, - final String postfix) { + public BasicTableWriter( + final PrintStream stream, + final String delimeter, + final String prefix, + final String postfix) { this.stream = stream; this.delimeter = delimeter; this.prefix = prefix; @@ -82,5 +85,4 @@ public TableWriter startTable() { public TableWriter endTable() { return this; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/HtmlTableWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/HtmlTableWriter.java index 9960f70e5a..5fcf9c4f49 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/HtmlTableWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/HtmlTableWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,14 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.common.table; import java.io.PrintStream; -/** - * A table writer that prints tables to a PrintStream in HTML format. - */ +/** A table writer that prints tables to a PrintStream in HTML format. */ public class HtmlTableWriter implements TableWriter { private final PrintStream stream; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/TableWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/TableWriter.java index 8d3a26798e..41f712e2d5 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/TableWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/TableWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,7 @@ */ package hu.bme.mit.theta.common.table; -/** - * Interface for printing tables with cells and rows. - */ +/** Interface for printing tables with cells and rows. */ public interface TableWriter { default TableWriter cell(final Object obj) { diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/package-info.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/package-info.java index 0616d13bdc..3fcda986fb 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/package-info.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/table/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,4 @@ * * @see hu.bme.mit.theta.common.table.TableWriter */ - -package hu.bme.mit.theta.common.table; \ No newline at end of file +package hu.bme.mit.theta.common.table; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Alignment.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Alignment.java index d8b01671d7..e59596164a 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Alignment.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Alignment.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.common.visualization; public enum Alignment { - LEFT, CENTER, RIGHT + LEFT, + CENTER, + RIGHT } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/CompositeNode.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/CompositeNode.java index 5f714de420..f521cab8ad 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/CompositeNode.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/CompositeNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,9 +22,7 @@ import java.util.Collection; import java.util.Collections; -/** - * Represents a compisite node of the visualizable graph. - */ +/** Represents a compisite node of the visualizable graph. */ public final class CompositeNode extends Node { private final Collection children; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Edge.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Edge.java index ef12f67d34..b1ba3e3b0e 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Edge.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Edge.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; -/** - * Represents a directed edge of the visualizable graph. - */ +/** Represents a directed edge of the visualizable graph. */ public final class Edge { private final Node source; @@ -53,5 +51,4 @@ public Node getTarget() { public EdgeAttributes getAttributes() { return attributes; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/EdgeAttributes.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/EdgeAttributes.java index 23f57275de..4ac30fcd7d 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/EdgeAttributes.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/EdgeAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,9 +28,13 @@ public final class EdgeAttributes { private final int weight; private final Alignment alignment; - private EdgeAttributes(final String label, final Color color, final LineStyle lineStyle, - final String font, - final int weight, final Alignment alignment) { + private EdgeAttributes( + final String label, + final Color color, + final LineStyle lineStyle, + final String font, + final int weight, + final Alignment alignment) { this.label = label; this.color = color; this.lineStyle = lineStyle; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Graph.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Graph.java index 063f4b4509..99a46957a1 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Graph.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Graph.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,12 +18,10 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.common.container.Containers; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.Map; import java.util.stream.Stream; @@ -94,8 +92,8 @@ public void setChild(final String parentId, final String childId) { * @param targetId * @param attributes */ - public void addEdge(final String sourceId, final String targetId, - final EdgeAttributes attributes) { + public void addEdge( + final String sourceId, final String targetId, final EdgeAttributes attributes) { checkArgument(nodes.containsKey(sourceId), "Source node does not exist!"); checkArgument(nodes.containsKey(targetId), "Target node does not exist!"); final Node source = nodes.get(sourceId); diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/JSONWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/JSONWriter.java index 16a049c98a..2576cc9dc2 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/JSONWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/JSONWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,13 +16,11 @@ package hu.bme.mit.theta.common.visualization.writer; import hu.bme.mit.theta.common.visualization.*; - import java.awt.*; public final class JSONWriter extends AbstractGraphWriter { - private JSONWriter() { - } + private JSONWriter() {} private static class LazyHolder { static final JSONWriter INSTANCE = new JSONWriter(); @@ -61,25 +59,44 @@ public String writeString(Graph graph) { private void printEdges(Node node, StringBuilder sb) { if (node instanceof CompositeNode) { if (node.getOutEdges().size() != 0) { - throw new UnsupportedOperationException("Composite nodes have outgoing edges. Not supported ?"); + throw new UnsupportedOperationException( + "Composite nodes have outgoing edges. Not supported ?"); } } else { for (final Edge edge : node.getOutEdges()) { final EdgeAttributes attributes = edge.getAttributes(); StringBuilder meta = new StringBuilder(); - meta.append("\"color\": \"").append(mapColorToString(attributes.getColor())).append("\", "); - meta.append("\"style\": \"").append(attributes.getLineStyle().toString()).append("\", "); + meta.append("\"color\": \"") + .append(mapColorToString(attributes.getColor())) + .append("\", "); + meta.append("\"style\": \"") + .append(attributes.getLineStyle().toString()) + .append("\", "); meta.append("\"weight\": \"").append(attributes.getWeight()).append("\", "); meta.append("\"font\": \"").append(attributes.getFont()).append("\", "); - meta.append("\"align\": \"").append(attributes.getAlignment().toString()).append("\", "); + meta.append("\"align\": \"") + .append(attributes.getAlignment().toString()) + .append("\", "); meta.deleteCharAt(meta.length() - 1); meta.deleteCharAt(meta.length() - 1); sb.append(System.lineSeparator()).append("\t\t\t{"); - sb.append(System.lineSeparator()).append("\t\t\t\t\"label\": \"").append(convertLabel(attributes.getLabel())).append("\","); - sb.append(System.lineSeparator()).append("\t\t\t\t\"source\": \"").append(edge.getSource().getId()).append("\","); - sb.append(System.lineSeparator()).append("\t\t\t\t\"target\": \"").append(edge.getTarget().getId()).append("\","); - sb.append(System.lineSeparator()).append("\t\t\t\t\"metadata\": { ").append(meta).append(" }"); + sb.append(System.lineSeparator()) + .append("\t\t\t\t\"label\": \"") + .append(convertLabel(attributes.getLabel())) + .append("\","); + sb.append(System.lineSeparator()) + .append("\t\t\t\t\"source\": \"") + .append(edge.getSource().getId()) + .append("\","); + sb.append(System.lineSeparator()) + .append("\t\t\t\t\"target\": \"") + .append(edge.getTarget().getId()) + .append("\","); + sb.append(System.lineSeparator()) + .append("\t\t\t\t\"metadata\": { ") + .append(meta) + .append(" }"); sb.append(System.lineSeparator()).append("\t\t\t},"); } } @@ -88,13 +105,24 @@ private void printEdges(Node node, StringBuilder sb) { private void printNode(final Node node, final StringBuilder sb) { final NodeAttributes attributes = node.getAttributes(); - sb.append(System.lineSeparator()).append("\t\t\t\"").append(node.getId()).append("\": {").append(System.lineSeparator()); - sb.append("\t\t\t\t\"label\": \"").append(this.convertLabel(attributes.getLabel())).append("\",").append(System.lineSeparator()); + sb.append(System.lineSeparator()) + .append("\t\t\t\"") + .append(node.getId()) + .append("\": {") + .append(System.lineSeparator()); + sb.append("\t\t\t\t\"label\": \"") + .append(this.convertLabel(attributes.getLabel())) + .append("\",") + .append(System.lineSeparator()); StringBuilder meta = new StringBuilder(); meta.append("\"style\": \"").append(attributes.getLineStyle().toString()).append("\", "); - meta.append("\"color\": \"").append(mapColorToString(attributes.getLineColor())).append("\", "); - meta.append("\"fill\": \"").append(mapColorToString(attributes.getFillColor())).append("\", "); + meta.append("\"color\": \"") + .append(mapColorToString(attributes.getLineColor())) + .append("\", "); + meta.append("\"fill\": \"") + .append(mapColorToString(attributes.getFillColor())) + .append("\", "); meta.append("\"font\": \"").append(attributes.getFont()).append("\", "); meta.append("\"align\": \"").append(attributes.getAlignment().toString()).append("\", "); meta.append("\"shape\": \"").append(attributes.getShape().toString()).append("\", "); @@ -102,7 +130,10 @@ private void printNode(final Node node, final StringBuilder sb) { meta.deleteCharAt(meta.length() - 1); meta.deleteCharAt(meta.length() - 1); - sb.append("\t\t\t\t\"metadata\": { ").append(meta).append(" }").append(System.lineSeparator()); + sb.append("\t\t\t\t\"metadata\": { ") + .append(meta) + .append(" }") + .append(System.lineSeparator()); sb.append("\t\t\t").append("},"); } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/LineStyle.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/LineStyle.java index b6aef7df03..c10bcbf129 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/LineStyle.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/LineStyle.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.common.visualization; public enum LineStyle { - NORMAL, DASHED, DOTTED + NORMAL, + DASHED, + DOTTED } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Node.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Node.java index 033e6a206a..5f46e88d86 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Node.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Node.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,9 +22,7 @@ import java.util.Collection; import java.util.Collections; -/** - * Represents a simple node of the visualizable graph. - */ +/** Represents a simple node of the visualizable graph. */ public class Node { private final String id; @@ -90,5 +88,4 @@ void setParent(final Node parent) { public boolean isRoot() { return getParent() == null; } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/NodeAttributes.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/NodeAttributes.java index e90e9ec3f6..810cd58c50 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/NodeAttributes.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/NodeAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -30,9 +30,15 @@ public final class NodeAttributes { private final Shape shape; private final Alignment alignment; - private NodeAttributes(final String label, final Color lineColor, final Color fillColor, - final LineStyle lineStyle, - final String font, final int peripheries, final Shape shape, final Alignment alignment) { + private NodeAttributes( + final String label, + final Color lineColor, + final Color fillColor, + final LineStyle lineStyle, + final String font, + final int peripheries, + final Shape shape, + final Alignment alignment) { this.label = checkNotNull(label); this.lineColor = checkNotNull(lineColor); this.fillColor = checkNotNull(fillColor); @@ -131,8 +137,8 @@ public Builder alignment(final Alignment alignment) { } public NodeAttributes build() { - return new NodeAttributes(label, lineColor, fillColor, lineStyle, font, peripheries, - shape, alignment); + return new NodeAttributes( + label, lineColor, fillColor, lineStyle, font, peripheries, shape, alignment); } } } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Shape.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Shape.java index 1be6f36687..92780bfabc 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Shape.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/Shape.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.common.visualization; public enum Shape { - CIRCLE, ELLIPSE, RECTANGLE + CIRCLE, + ELLIPSE, + RECTANGLE } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/WebDebuggerLogger.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/WebDebuggerLogger.java index bb2b2a0383..a6a3f391b1 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/WebDebuggerLogger.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/WebDebuggerLogger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,8 +29,7 @@ public class WebDebuggerLogger { private final ArrayList traces = new ArrayList(); private String title = "Cfa"; - private WebDebuggerLogger() { - } + private WebDebuggerLogger() {} public static void enableWebDebuggerLogger() { enabled = true; @@ -47,7 +46,11 @@ public static WebDebuggerLogger getInstance() { public void addIteration(int iteration, String arg, String prec) { if (enabled) { StringBuilder sb = new StringBuilder(); - sb.append("{").append(System.lineSeparator()).append("\"iteration\": ").append(iteration).append(","); + sb.append("{") + .append(System.lineSeparator()) + .append("\"iteration\": ") + .append(iteration) + .append(","); sb.append("\"arg\": ").append(arg).append(","); sb.append("\"precision\": \"").append(prec).append("\""); sb.append("}"); @@ -63,7 +66,10 @@ private String getFileContent() { StringBuilder sb = new StringBuilder(); sb.append("{").append(System.lineSeparator()); sb.append("\"title\": \"").append(title).append("\",").append(System.lineSeparator()); - sb.append("\"date\": \"").append(java.time.LocalDateTime.now()).append("\",").append(System.lineSeparator()); + sb.append("\"date\": \"") + .append(java.time.LocalDateTime.now()) + .append("\",") + .append(System.lineSeparator()); sb.append("\"iterations\": ["); for (String iteration : iterations) { sb.append(iteration).append(","); diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/package-info.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/package-info.java index b63a5ca42c..6dcdbc8345 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/package-info.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ * @see hu.bme.mit.theta.common.visualization.Graph * @see hu.bme.mit.theta.common.visualization.writer.GraphWriter */ - -package hu.bme.mit.theta.common.visualization; \ No newline at end of file +package hu.bme.mit.theta.common.visualization; diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/AbstractGraphWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/AbstractGraphWriter.java index 00a133c923..0825d4ad82 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/AbstractGraphWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/AbstractGraphWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,14 +16,11 @@ package hu.bme.mit.theta.common.visualization.writer; import hu.bme.mit.theta.common.visualization.Graph; - import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; -/** - * Base class for writing graphs. - */ +/** Base class for writing graphs. */ public abstract class AbstractGraphWriter implements GraphWriter { @Override @@ -36,12 +33,10 @@ public final void writeFile(final Graph graph, final String fileName) writeFile(graph, file); } - public final void writeFile(final Graph graph, final File file) - throws FileNotFoundException { + public final void writeFile(final Graph graph, final File file) throws FileNotFoundException { try (PrintWriter printWriter = new PrintWriter(file)) { final String graphAsString = writeString(graph); printWriter.write(graphAsString); } } - } diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphWriter.java index 1f6da8f513..a0f2200281 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,10 @@ */ package hu.bme.mit.theta.common.visualization.writer; -import java.io.FileNotFoundException; - import hu.bme.mit.theta.common.visualization.Graph; +import java.io.FileNotFoundException; -/** - * Inteface for writing graphs to strings and files. - */ +/** Inteface for writing graphs to strings and files. */ public interface GraphWriter { String writeString(Graph graph); diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphvizWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphvizWriter.java index 3b060e7d9c..9297853717 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphvizWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/GraphvizWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,6 @@ */ package hu.bme.mit.theta.common.visualization.writer; -import java.awt.Color; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; - import hu.bme.mit.theta.common.visualization.Alignment; import hu.bme.mit.theta.common.visualization.CompositeNode; import hu.bme.mit.theta.common.visualization.Edge; @@ -29,6 +24,9 @@ import hu.bme.mit.theta.common.visualization.Node; import hu.bme.mit.theta.common.visualization.NodeAttributes; import hu.bme.mit.theta.common.visualization.Shape; +import java.awt.Color; +import java.io.File; +import java.io.IOException; /** * Class for writing graphs in GraphViz format. Known limitations (due to GraphViz): - Fill color of @@ -38,7 +36,12 @@ public final class GraphvizWriter extends AbstractGraphWriter { public enum Format { - PDF("-Tpdf"), PNG("-Tpng"), SVG("-Tsvg"), GIF("-Tgif"), EPS("-Teps"), JPG("-Tjpg"); + PDF("-Tpdf"), + PNG("-Tpng"), + SVG("-Tsvg"), + GIF("-Tgif"), + EPS("-Teps"), + JPG("-Tjpg"); private final String option; @@ -51,8 +54,7 @@ private String getOption() { } } - private GraphvizWriter() { - } + private GraphvizWriter() {} private static class LazyHolder { @@ -67,7 +69,9 @@ public static GraphvizWriter getInstance() { public String writeString(final Graph graph) { final StringBuilder sb = new StringBuilder(); sb.append("digraph ").append(graph.getId()).append(" {").append(System.lineSeparator()); - sb.append("\tlabel=\"").append(graph.getLabel()).append("\";") + sb.append("\tlabel=\"") + .append(graph.getLabel()) + .append("\";") .append(System.lineSeparator()); graph.getRootNodes().forEach(n -> printNode(n, sb)); @@ -140,7 +144,6 @@ private void printNode(final Node node, final StringBuilder sb) { } else { printSimpleNode(node, sb); } - } private void printSimpleNode(final Node node, final StringBuilder sb) { @@ -154,7 +157,8 @@ private void printSimpleNode(final Node node, final StringBuilder sb) { sb.append("\t\t").append(node.getId()); sb.append(" [label=\"") - .append(convertLabel(attributes.getLabel(), attributes.getAlignment())).append('\"'); + .append(convertLabel(attributes.getLabel(), attributes.getAlignment())) + .append('\"'); if (attributes.getPeripheries() > 1) { sb.append(",peripheries=").append(attributes.getPeripheries()); } @@ -172,9 +176,13 @@ private void printCompositeNode(final CompositeNode node, final StringBuilder sb final NodeAttributes attributes = node.getAttributes(); final String style = mapLineStyleToString(attributes.getLineStyle()); - sb.append("\tsubgraph cluster_").append(node.getId()).append(" {") + sb.append("\tsubgraph cluster_") + .append(node.getId()) + .append(" {") .append(System.lineSeparator()); - sb.append("\t\tcolor=").append(mapColorToString(attributes.getLineColor())).append(';') + sb.append("\t\tcolor=") + .append(mapColorToString(attributes.getLineColor())) + .append(';') .append(System.lineSeparator()); if (!"".equals(style)) { sb.append("\t\tstyle=").append(style).append(';').append(System.lineSeparator()); @@ -183,7 +191,8 @@ private void printCompositeNode(final CompositeNode node, final StringBuilder sb sb.append(",fontname=\"").append(attributes.getFont()).append('\"'); } sb.append("\t\tlabel=\"") - .append(convertLabel(attributes.getLabel(), attributes.getAlignment())).append("\";") + .append(convertLabel(attributes.getLabel(), attributes.getAlignment())) + .append("\";") .append(System.lineSeparator()); for (final Node child : node.getChildren()) { printNode(child, sb); @@ -200,7 +209,9 @@ private void printEdges(final Node node, final StringBuilder sb) { } else { for (final Edge edge : node.getOutEdges()) { final EdgeAttributes attributes = edge.getAttributes(); - sb.append('\t').append(edge.getSource().getId()).append(" -> ") + sb.append('\t') + .append(edge.getSource().getId()) + .append(" -> ") .append(edge.getTarget().getId()); sb.append(" [label=\"") .append(convertLabel(attributes.getLabel(), attributes.getAlignment())) @@ -243,8 +254,8 @@ private String getLineSeparator(final Alignment alignment) { } private String mapColorToString(final Color color) { - return String.format("\"#%02X%02X%02X\"", color.getRed(), color.getGreen(), - color.getBlue()); + return String.format( + "\"#%02X%02X%02X\"", color.getRed(), color.getGreen(), color.getBlue()); } private String mapLineStyleToString(final LineStyle lineStyle) { diff --git a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/YedWriter.java b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/YedWriter.java index 82223ac545..437b2e9561 100644 --- a/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/YedWriter.java +++ b/subprojects/common/common/src/main/java/hu/bme/mit/theta/common/visualization/writer/YedWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,8 +15,6 @@ */ package hu.bme.mit.theta.common.visualization.writer; -import java.awt.Color; - import hu.bme.mit.theta.common.visualization.CompositeNode; import hu.bme.mit.theta.common.visualization.Edge; import hu.bme.mit.theta.common.visualization.EdgeAttributes; @@ -25,14 +23,12 @@ import hu.bme.mit.theta.common.visualization.Node; import hu.bme.mit.theta.common.visualization.NodeAttributes; import hu.bme.mit.theta.common.visualization.Shape; +import java.awt.Color; -/** - * Class for writing graphs in yED (GraphML) format. - */ +/** Class for writing graphs in yED (GraphML) format. */ public final class YedWriter extends AbstractGraphWriter { - private YedWriter() { - } + private YedWriter() {} private static class LazyHolder { @@ -55,7 +51,8 @@ public String writeString(final Graph graph) { sb.append("\txmlns:y=\"http://www.yworks.com/xml/graphml\"").append(System.lineSeparator()); sb.append("\txmlns:yed=\"http://www.yworks.com/xml/yed/3\"").append(System.lineSeparator()); sb.append( - "\txsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd\">") + "\txsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns" + + " http://www.yworks.com/xml/schema/graphml/1.1/ygraphml.xsd\">") .append(System.lineSeparator()); sb.append("") .append(System.lineSeparator()); @@ -89,7 +86,8 @@ private void printSimpleNode(final Node node, final StringBuilder sb) { sb.append("\t"); sb.append(""); sb.append("").append(escape(attributes.getLabel())).append(""); - sb.append(""); sb.append(""); - sb.append("").append(System.lineSeparator()); + sb.append("") + .append(System.lineSeparator()); } private void printCompositeNode(final CompositeNode node, final StringBuilder sb) { final NodeAttributes attributes = node.getAttributes(); sb.append("").append(System.lineSeparator()); sb.append( - "\t") + "\t") .append(System.lineSeparator()); sb.append("\t") .append(escape(attributes.getLabel())) - .append("").append(System.lineSeparator()); - sb.append("\t").append(System.lineSeparator()); + .append("") + .append(System.lineSeparator()); + sb.append("\t") + .append(System.lineSeparator()); sb.append(""); - sb.append("\t") .append(System.lineSeparator()); sb.append("\t").append(System.lineSeparator()); @@ -132,18 +137,25 @@ private void printCompositeNode(final CompositeNode node, final StringBuilder sb for (final Node child : node.getChildren()) { printNode(child, sb); } - sb.append("\t").append(System.lineSeparator()).append("") + sb.append("\t") + .append(System.lineSeparator()) + .append("") .append(System.lineSeparator()); } private void printEdges(final Node node, final StringBuilder sb) { for (final Edge edge : node.getOutEdges()) { final EdgeAttributes attributes = edge.getAttributes(); - sb.append("\t"); + .append("\" target=\"") + .append(edge.getTarget().getId()) + .append("\">"); sb.append("", "<"); - } private String mapColorToString(final Color color) { diff --git a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogJavaTest.java b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogJavaTest.java index 88afc58336..263a925582 100644 --- a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogJavaTest.java +++ b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogJavaTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.common.datalog; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.TupleN; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; import java.util.Set; - -import static org.junit.Assert.assertEquals; +import org.junit.Test; /* * Tests initial and incremental deduction with Datalog @@ -42,22 +41,30 @@ public final class DatalogJavaTest { public DatalogJavaTest() { datalog = Datalog.createProgram(); - //datalog.setDebug(true); + // datalog.setDebug(true); edge = datalog.createRelation("edge", 2); successor = datalog.createRelation("successor", 2); reflexive = datalog.createRelation("reflexive", 1); - Tuple2 accessibleVariables = Tuple2.of( - datalog.getVariable(), datalog.getVariable()); + Tuple2 accessibleVariables = + Tuple2.of(datalog.getVariable(), datalog.getVariable()); Datalog.Variable next = datalog.getVariable(); - successor.addRule(TupleN.of(accessibleVariables), Set.of( - Tuple2.of(edge, TupleN.of(accessibleVariables.get1(), accessibleVariables.get2())))); - successor.addRule(TupleN.of(accessibleVariables), - Set.of(Tuple2.of(edge, TupleN.of(accessibleVariables.get1(), next)), + successor.addRule( + TupleN.of(accessibleVariables), + Set.of( + Tuple2.of( + edge, + TupleN.of( + accessibleVariables.get1(), accessibleVariables.get2())))); + successor.addRule( + TupleN.of(accessibleVariables), + Set.of( + Tuple2.of(edge, TupleN.of(accessibleVariables.get1(), next)), Tuple2.of(successor, TupleN.of(next, accessibleVariables.get2())))); Datalog.Variable reflexivity = datalog.getVariable(); - reflexive.addRule(TupleN.of(List.of(reflexivity)), + reflexive.addRule( + TupleN.of(List.of(reflexivity)), Set.of(Tuple2.of(edge, TupleN.of(reflexivity, reflexivity)))); } @@ -106,10 +113,7 @@ private Node(char a, int i) { @Override public String toString() { - return "Node" + c + "{" + - "i=" + i + - '}'; + return "Node" + c + "{" + "i=" + i + '}'; } } - } diff --git a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogStringTest.java b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogStringTest.java index a3b57e84cb..e70d1aab62 100644 --- a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogStringTest.java +++ b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/datalog/DatalogStringTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,6 @@ */ package hu.bme.mit.theta.common.datalog; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -27,33 +22,40 @@ import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; @RunWith(value = Parameterized.class) public final class DatalogStringTest { - @Parameterized.Parameter - public String name; + @Parameterized.Parameter public String name; @Parameterized.Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - {"succ"}, - {"trains"} - //this benchmark is from the exercise in http://ysangkok.github.io/mitre-datalog.js/wrapper.html - }); + return Arrays.asList( + new Object[][] {{"succ"}, {"trains"} + // this benchmark is from the exercise in + // http://ysangkok.github.io/mitre-datalog.js/wrapper.html + }); } @Test public void test() { - final InputStream inStream = getClass().getResourceAsStream( - "/datalog/in/" + name + ".datalog"); - final InputStream outStream = getClass().getResourceAsStream( - "/datalog/out/" + name + ".output"); + final InputStream inStream = + getClass().getResourceAsStream("/datalog/in/" + name + ".datalog"); + final InputStream outStream = + getClass().getResourceAsStream("/datalog/out/" + name + ".output"); - String input = new BufferedReader(new InputStreamReader(inStream)).lines() - .collect(Collectors.joining()); - Set output = new BufferedReader(new InputStreamReader(outStream)).lines() - .collect(Collectors.toSet()); + String input = + new BufferedReader(new InputStreamReader(inStream)) + .lines() + .collect(Collectors.joining()); + Set output = + new BufferedReader(new InputStreamReader(outStream)) + .lines() + .collect(Collectors.toSet()); String[] s = Datalog.runProgram(input).split("\r\n"); for (String s1 : s) { @@ -61,7 +63,5 @@ public void test() { output.remove(s1); } Assert.assertTrue(output.isEmpty()); - } - } diff --git a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/LispLexerTest.java b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/LispLexerTest.java index 5687d77d1c..a0f0a36820 100644 --- a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/LispLexerTest.java +++ b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/LispLexerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -48,43 +47,29 @@ public final class LispLexerTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"", of()}, - - {";", of()}, - - {";;", of()}, - - {"; comment", of()}, - - {"atom1", of(ATOM1)}, - - {"(", of(LPAREN)}, - - {")", of(RPAREN)}, - - {"()", of(LPAREN, RPAREN)}, - - {"( )", of(LPAREN, RPAREN)}, - - {"( )", of(LPAREN, RPAREN)}, - - {"() ; comment", of(LPAREN, RPAREN)}, - - {"(atom1)", of(LPAREN, ATOM1, RPAREN)}, - - {"(atom1 atom2)", of(LPAREN, ATOM1, ATOM2, RPAREN)}, - - {"(atom1 atom2 atom3)", of(LPAREN, ATOM1, ATOM2, ATOM3, RPAREN)}, - - {"(atom1 atom2 atom3) ; comment", of(LPAREN, ATOM1, ATOM2, ATOM3, RPAREN)}, - - {"(atom1 (atom2 atom3))", of(LPAREN, ATOM1, LPAREN, ATOM2, ATOM3, RPAREN, RPAREN)}, - - {"(()(()", of(LPAREN, LPAREN, RPAREN, LPAREN, LPAREN, RPAREN)}, - - }); + return Arrays.asList( + new Object[][] { + {"", of()}, + {";", of()}, + {";;", of()}, + {"; comment", of()}, + {"atom1", of(ATOM1)}, + {"(", of(LPAREN)}, + {")", of(RPAREN)}, + {"()", of(LPAREN, RPAREN)}, + {"( )", of(LPAREN, RPAREN)}, + {"( )", of(LPAREN, RPAREN)}, + {"() ; comment", of(LPAREN, RPAREN)}, + {"(atom1)", of(LPAREN, ATOM1, RPAREN)}, + {"(atom1 atom2)", of(LPAREN, ATOM1, ATOM2, RPAREN)}, + {"(atom1 atom2 atom3)", of(LPAREN, ATOM1, ATOM2, ATOM3, RPAREN)}, + {"(atom1 atom2 atom3) ; comment", of(LPAREN, ATOM1, ATOM2, ATOM3, RPAREN)}, + { + "(atom1 (atom2 atom3))", + of(LPAREN, ATOM1, LPAREN, ATOM2, ATOM3, RPAREN, RPAREN) + }, + {"(()(()", of(LPAREN, LPAREN, RPAREN, LPAREN, LPAREN, RPAREN)}, + }); } @Test @@ -105,5 +90,4 @@ public void test() { // Assert assertEquals(tokens, actTokens); } - } diff --git a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/SExpTest.java b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/SExpTest.java index 5ad0080cb1..6d148fd37b 100644 --- a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/SExpTest.java +++ b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/parser/SExpTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collection; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -47,24 +46,20 @@ public final class SExpTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {A, atom(A), A}, - - {of(), list(), "()"}, - - {of(A), list(atom(A)), "(A)"}, - - {of(A, B), list(atom(A), atom(B)), "(A B)"}, - - {of(A, B, C), list(atom(A), atom(B), atom(C)), "(A B C)"}, - - {of(A, of(B, C)), list(atom(A), list(atom(B), atom(C))), "(A (B C))"}, - - {of(A, B, of(C, of(A))), list(atom(A), atom(B), list(atom(C), list(atom(A)))), - "(A B (C (A)))"} - - }); + return Arrays.asList( + new Object[][] { + {A, atom(A), A}, + {of(), list(), "()"}, + {of(A), list(atom(A)), "(A)"}, + {of(A, B), list(atom(A), atom(B)), "(A B)"}, + {of(A, B, C), list(atom(A), atom(B), atom(C)), "(A B C)"}, + {of(A, of(B, C)), list(atom(A), list(atom(B), atom(C))), "(A (B C))"}, + { + of(A, B, of(C, of(A))), + list(atom(A), atom(B), list(atom(C), list(atom(A)))), + "(A B (C (A)))" + } + }); } @Test @@ -84,5 +79,4 @@ public void testToString() { final String actString = sexpr.toString(); assertEquals(string, actString); } - } diff --git a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/table/TableWriterTest.java b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/table/TableWriterTest.java index 30eb36c796..7c7d04eae8 100644 --- a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/table/TableWriterTest.java +++ b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/table/TableWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,13 @@ */ package hu.bme.mit.theta.common.table; +import com.google.common.collect.ImmutableList; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.nio.charset.StandardCharsets; - import org.junit.Assert; import org.junit.Test; -import com.google.common.collect.ImmutableList; - public class TableWriterTest { @Test diff --git a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/visualization/VisualizationTest.java b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/visualization/VisualizationTest.java index 05f19cc8e3..409d09d447 100644 --- a/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/visualization/VisualizationTest.java +++ b/subprojects/common/common/src/test/java/hu/bme/mit/theta/common/visualization/VisualizationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,8 @@ */ package hu.bme.mit.theta.common.visualization; -import java.awt.Color; - import hu.bme.mit.theta.common.visualization.writer.YedWriter; +import java.awt.Color; public class VisualizationTest { @@ -26,14 +25,20 @@ public static void main(final String[] args) { g.addNode("n1", NodeAttributes.builder().fillColor(Color.RED).label("1").build()); g.addNode("n2", NodeAttributes.builder().lineColor(Color.BLUE).label("2").build()); g.addNode("n3", NodeAttributes.builder().lineStyle(LineStyle.DASHED).label("3").build()); - g.addNode("n4", + g.addNode( + "n4", NodeAttributes.builder().peripheries(3).label("4").shape(Shape.RECTANGLE).build()); - g.addCompositeNode("c1", - NodeAttributes.builder().label("cluster1").lineStyle(LineStyle.DOTTED) - .shape(Shape.RECTANGLE).peripheries(2).build()); - g.addCompositeNode("c2", - NodeAttributes.builder().label("cluster2").shape(Shape.RECTANGLE).build()); + g.addCompositeNode( + "c1", + NodeAttributes.builder() + .label("cluster1") + .lineStyle(LineStyle.DOTTED) + .shape(Shape.RECTANGLE) + .peripheries(2) + .build()); + g.addCompositeNode( + "c2", NodeAttributes.builder().label("cluster2").shape(Shape.RECTANGLE).build()); g.setChild("c1", "n1"); g.setChild("c1", "n2"); diff --git a/subprojects/common/core/build.gradle.kts b/subprojects/common/core/build.gradle.kts index 1ba5923b5f..e8b16987d2 100644 --- a/subprojects/common/core/build.gradle.kts +++ b/subprojects/common/core/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 efd0e2917d..1ba863961f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AndConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AndConstr.java index d3a498c3cd..399d053638 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AndConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AndConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static java.util.stream.Collectors.toSet; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.booltype.AndExpr; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; import java.util.StringJoiner; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static java.util.stream.Collectors.toSet; - public final class AndConstr implements ClockConstr { private static final int HASH_SEED = 6133; @@ -65,8 +64,8 @@ public AndExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -118,5 +117,4 @@ private static Collection toAtomicConstrs( } return builder.build(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AtomicConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AtomicConstr.java index e2e5623785..1710512273 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AtomicConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/AtomicConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,5 +26,4 @@ public AtomicConstr(final int bound) { public final int getBound() { return bound; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstr.java index 6873a9ec96..bd43c34705 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,11 @@ */ package hu.bme.mit.theta.core.clock.constr; -import java.util.Collection; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.Collection; public interface ClockConstr { @@ -29,5 +28,4 @@ public interface ClockConstr { Expr toExpr(); R accept(final ClockConstrVisitor visitor, final P param); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrVisitor.java index fcb3b23591..aa925921b4 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -42,5 +42,4 @@ public interface ClockConstrVisitor { R visit(final DiffEqConstr constr, final P param); R visit(final AndConstr constr, final P param); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrs.java index c7479f9685..3f30fe57f3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/ClockConstrs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,12 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import java.util.Collection; -import java.util.List; - import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.common.DispatchTable; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; @@ -44,6 +40,8 @@ import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.core.utils.ExprUtils; import hu.bme.mit.theta.core.utils.TypeUtils; +import java.util.Collection; +import java.util.List; public final class ClockConstrs { @@ -55,8 +53,7 @@ public final class ClockConstrs { FALSE_CONSTR = new FalseConstr(); } - private ClockConstrs() { - } + private ClockConstrs() {} //// @@ -99,41 +96,36 @@ public static UnitEqConstr Eq(final VarDecl clock, final int bound) { return new UnitEqConstr(clock, bound); } - public static DiffLtConstr Lt(final VarDecl leftClock, - final VarDecl rightClock, - final int bound) { + public static DiffLtConstr Lt( + final VarDecl leftClock, final VarDecl rightClock, final int bound) { checkNotNull(leftClock); checkNotNull(rightClock); return new DiffLtConstr(leftClock, rightClock, bound); } - public static DiffLeqConstr Leq(final VarDecl leftClock, - final VarDecl rightClock, - final int bound) { + public static DiffLeqConstr Leq( + final VarDecl leftClock, final VarDecl rightClock, final int bound) { checkNotNull(leftClock); checkNotNull(rightClock); return new DiffLeqConstr(leftClock, rightClock, bound); } - public static DiffGtConstr Gt(final VarDecl leftClock, - final VarDecl rightClock, - final int bound) { + public static DiffGtConstr Gt( + final VarDecl leftClock, final VarDecl rightClock, final int bound) { checkNotNull(leftClock); checkNotNull(rightClock); return new DiffGtConstr(leftClock, rightClock, bound); } - public static DiffGeqConstr Geq(final VarDecl leftClock, - final VarDecl rightClock, - final int bound) { + public static DiffGeqConstr Geq( + final VarDecl leftClock, final VarDecl rightClock, final int bound) { checkNotNull(leftClock); checkNotNull(rightClock); return new DiffGeqConstr(leftClock, rightClock, bound); } - public static DiffEqConstr Eq(final VarDecl leftClock, - final VarDecl rightClock, - final int bound) { + public static DiffEqConstr Eq( + final VarDecl leftClock, final VarDecl rightClock, final int bound) { checkNotNull(leftClock); checkNotNull(rightClock); return new DiffEqConstr(leftClock, rightClock, bound); @@ -160,29 +152,21 @@ private static final class FromExprHelper { private final DispatchTable table; private FromExprHelper() { - table = DispatchTable.builder() - - .addCase(TrueExpr.class, this::transformTrue) - - .addCase(FalseExpr.class, this::transformFalse) - - .addCase(RatLtExpr.class, this::transformLt) - - .addCase(RatLeqExpr.class, this::transformLeq) - - .addCase(RatGtExpr.class, this::transformGt) - - .addCase(RatGeqExpr.class, this::transformGeq) - - .addCase(RatEqExpr.class, this::transformEq) - - .addCase(AndExpr.class, this::transformAnd) - - .addDefault(o -> { - throw new IllegalArgumentException(); - }) - - .build(); + table = + DispatchTable.builder() + .addCase(TrueExpr.class, this::transformTrue) + .addCase(FalseExpr.class, this::transformFalse) + .addCase(RatLtExpr.class, this::transformLt) + .addCase(RatLeqExpr.class, this::transformLeq) + .addCase(RatGtExpr.class, this::transformGt) + .addCase(RatGeqExpr.class, this::transformGeq) + .addCase(RatEqExpr.class, this::transformEq) + .addCase(AndExpr.class, this::transformAnd) + .addDefault( + o -> { + throw new IllegalArgumentException(); + }) + .build(); } public ClockConstr transform(final Expr expr) { @@ -305,7 +289,5 @@ private static int extractConstrRhs(final BinaryExpr expr) { throw new IllegalArgumentException(); } - } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffConstr.java index 801444fbbf..a5a856171b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,10 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.Collection; public abstract class DiffConstr extends AtomicConstr { @@ -31,8 +29,8 @@ public abstract class DiffConstr extends AtomicConstr { private volatile int hashCode = 0; - protected DiffConstr(final VarDecl leftVar, final VarDecl rightVar, - final int bound) { + protected DiffConstr( + final VarDecl leftVar, final VarDecl rightVar, final int bound) { super(bound); this.leftVar = checkNotNull(leftVar); this.rightVar = checkNotNull(rightVar); @@ -80,5 +78,4 @@ public final String toString() { protected abstract int getHashSeed(); protected abstract String getOperatorLabel(); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffEqConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffEqConstr.java index c7ffc576f6..737a76a46f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffEqConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffEqConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Eq; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatEqExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Eq; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; - public final class DiffEqConstr extends DiffConstr { private static final int HASH_SEED = 5261; @@ -49,8 +49,8 @@ public RatEqExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -60,7 +60,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final DiffEqConstr that = (DiffEqConstr) obj; - return this.getBound() == that.getBound() && this.getLeftVar().equals(that.getLeftVar()) + return this.getBound() == that.getBound() + && this.getLeftVar().equals(that.getLeftVar()) && this.getRightVar().equals(that.getRightVar()); } else { return false; @@ -76,5 +77,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGeqConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGeqConstr.java index 22d69bb0e2..0e2c7e0fe2 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGeqConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGeqConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Geq; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatGeqExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Geq; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; - public final class DiffGeqConstr extends DiffConstr { private static final int HASH_SEED = 4327; @@ -32,8 +32,8 @@ public final class DiffGeqConstr extends DiffConstr { private volatile RatGeqExpr expr = null; - DiffGeqConstr(final VarDecl leftVar, final VarDecl rightVar, - final int bound) { + DiffGeqConstr( + final VarDecl leftVar, final VarDecl rightVar, final int bound) { super(leftVar, rightVar, bound); } @@ -50,8 +50,8 @@ public RatGeqExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -61,7 +61,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final DiffGeqConstr that = (DiffGeqConstr) obj; - return this.getBound() == that.getBound() && this.getLeftVar().equals(that.getLeftVar()) + return this.getBound() == that.getBound() + && this.getLeftVar().equals(that.getLeftVar()) && this.getRightVar().equals(that.getRightVar()); } else { return false; @@ -77,5 +78,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGtConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGtConstr.java index 0ed14ecf4c..32bd868459 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGtConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffGtConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatGtExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; - public final class DiffGtConstr extends DiffConstr { private static final int HASH_SEED = 1493; @@ -49,8 +49,8 @@ public RatGtExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -60,7 +60,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final DiffGtConstr that = (DiffGtConstr) obj; - return this.getBound() == that.getBound() && this.getLeftVar().equals(that.getLeftVar()) + return this.getBound() == that.getBound() + && this.getLeftVar().equals(that.getLeftVar()) && this.getRightVar().equals(that.getRightVar()); } else { return false; @@ -76,5 +77,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLeqConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLeqConstr.java index 754566122f..3b54953d3f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLeqConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLeqConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Leq; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatLeqExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Leq; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; - public final class DiffLeqConstr extends DiffConstr { private static final int HASH_SEED = 7019; @@ -32,8 +32,8 @@ public final class DiffLeqConstr extends DiffConstr { private volatile RatLeqExpr expr = null; - DiffLeqConstr(final VarDecl leftVar, final VarDecl rightVar, - final int bound) { + DiffLeqConstr( + final VarDecl leftVar, final VarDecl rightVar, final int bound) { super(leftVar, rightVar, bound); } @@ -50,8 +50,8 @@ public RatLeqExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -61,7 +61,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final DiffLeqConstr that = (DiffLeqConstr) obj; - return this.getBound() == that.getBound() && this.getLeftVar().equals(that.getLeftVar()) + return this.getBound() == that.getBound() + && this.getLeftVar().equals(that.getLeftVar()) && this.getRightVar().equals(that.getRightVar()); } else { return false; @@ -77,5 +78,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLtConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLtConstr.java index 875f1f738e..3c58aed9da 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLtConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/DiffLtConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Lt; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatLtExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Lt; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; - public final class DiffLtConstr extends DiffConstr { private static final int HASH_SEED = 8377; @@ -49,8 +49,8 @@ public RatLtExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -60,7 +60,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final DiffLtConstr that = (DiffLtConstr) obj; - return this.getBound() == that.getBound() && this.getLeftVar().equals(that.getLeftVar()) + return this.getBound() == that.getBound() + && this.getLeftVar().equals(that.getLeftVar()) && this.getRightVar().equals(that.getRightVar()); } else { return false; @@ -76,5 +77,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FailClockConstrVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FailClockConstrVisitor.java index 502aba683f..a8ea6a31d8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FailClockConstrVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FailClockConstrVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -81,5 +81,4 @@ public R visit(final DiffEqConstr constr, final P param) { public R visit(final AndConstr constr, final P param) { throw new UnsupportedOperationException(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FalseConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FalseConstr.java index 4c9e8e3d19..93859f8909 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FalseConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/FalseConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,11 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import java.util.Collection; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.booltype.FalseExpr; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.Collection; public final class FalseConstr implements ClockConstr { @@ -42,8 +40,8 @@ public FalseExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/TrueConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/TrueConstr.java index 096bb0cc07..058e70c068 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/TrueConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/TrueConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,11 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import java.util.Collection; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.booltype.TrueExpr; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.Collection; public final class TrueConstr implements ClockConstr { @@ -42,8 +40,8 @@ public TrueExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitConstr.java index 7aa3352ac0..c1e6359c44 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,10 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.Collection; public abstract class UnitConstr extends AtomicConstr { @@ -70,5 +68,4 @@ public final String toString() { protected abstract int getHashSeed(); protected abstract String getOperatorLabel(); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitEqConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitEqConstr.java index cbccff8ca7..2391d6e7cd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitEqConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitEqConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Eq; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatEqExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Eq; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class UnitEqConstr extends UnitConstr { private static final int HASH_SEED = 5987; @@ -47,8 +47,8 @@ public RatEqExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -73,5 +73,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGeqConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGeqConstr.java index 6a25cc2237..b5d0dc3d75 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGeqConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGeqConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Geq; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatGeqExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Geq; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class UnitGeqConstr extends UnitConstr { private static final int HASH_SEED = 2797; @@ -47,8 +47,8 @@ public RatGeqExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -73,5 +73,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGtConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGtConstr.java index ad0e78ab23..ef68d4a076 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGtConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitGtConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatGtExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class UnitGtConstr extends UnitConstr { private static final int HASH_SEED = 9161; @@ -47,8 +47,8 @@ public RatGtExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -73,5 +73,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLeqConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLeqConstr.java index 9e7232321a..e7435d4136 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLeqConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLeqConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Leq; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatLeqExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Leq; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class UnitLeqConstr extends UnitConstr { private static final int HASH_SEED = 6653; @@ -47,8 +47,8 @@ public RatLeqExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -73,5 +73,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLtConstr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLtConstr.java index e51f1f774c..e0161d884a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLtConstr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/constr/UnitLtConstr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.clock.constr; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Lt; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.rattype.RatLtExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Lt; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class UnitLtConstr extends UnitConstr { private static final int HASH_SEED = 3109; @@ -47,8 +47,8 @@ public RatLtExpr toExpr() { } @Override - public R accept(final ClockConstrVisitor visitor, - final P param) { + public R accept( + final ClockConstrVisitor visitor, final P param) { return visitor.visit(this, param); } @@ -73,5 +73,4 @@ protected int getHashSeed() { protected String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOp.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOp.java index 6dd851263a..3a8d3d54f7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOp.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,10 @@ */ package hu.bme.mit.theta.core.clock.op; -import java.util.Collection; - import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.Collection; public interface ClockOp { @@ -28,5 +27,4 @@ public interface ClockOp { Stmt toStmt(); R accept(final ClockOpVisitor visitor, final P param); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOpVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOpVisitor.java index 4ad3037032..a727a32de3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOpVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOpVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,5 +26,4 @@ public interface ClockOpVisitor { R visit(final ResetOp op, final P param); R visit(final ShiftOp op, final P param); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOps.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOps.java index 1f4689baff..7271b3dd53 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOps.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ClockOps.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.clock.op; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.clock.constr.ClockConstr; import hu.bme.mit.theta.core.clock.constr.ClockConstrs; import hu.bme.mit.theta.core.decl.Decl; @@ -41,8 +43,6 @@ import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.core.utils.TypeUtils; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class ClockOps { private static final StmtToClockOpVisitor VISITOR; @@ -51,8 +51,7 @@ public final class ClockOps { VISITOR = new StmtToClockOpVisitor(); } - private ClockOps() { - } + private ClockOps() {} //// @@ -86,8 +85,7 @@ public static ShiftOp Shift(final VarDecl varDecl, final int offset) { private static final class StmtToClockOpVisitor implements StmtVisitor { - private StmtToClockOpVisitor() { - } + private StmtToClockOpVisitor() {} @Override public ClockOp visit(final SkipStmt stmt, final Void param) { @@ -95,8 +93,8 @@ public ClockOp visit(final SkipStmt stmt, final Void param) { } @Override - public ClockOp visit(final HavocStmt stmt, - final Void param) { + public ClockOp visit( + final HavocStmt stmt, final Void param) { final VarDecl varDecl = TypeUtils.cast(stmt.getVarDecl(), Rat()); return Free(varDecl); } @@ -127,8 +125,8 @@ public ClockOp visit(IfStmt stmt, Void param) { } @Override - public ClockOp visit(final AssignStmt stmt, - final Void param) { + public ClockOp visit( + final AssignStmt stmt, final Void param) { final VarDecl varDecl = TypeUtils.cast(stmt.getVarDecl(), Rat()); final Expr expr = stmt.getExpr(); @@ -176,7 +174,8 @@ public ClockOp visit(final AssignStmt stmt, } @Override - public ClockOp visit(MemoryAssignStmt stmt, Void param) { + public ClockOp visit( + MemoryAssignStmt stmt, Void param) { throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); } @@ -191,7 +190,5 @@ public ClockOp visit(final AssumeStmt stmt, final Void param) { throw new IllegalArgumentException(); } } - } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/CopyOp.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/CopyOp.java index 6f0ba8882f..785fa69c82 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/CopyOp.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/CopyOp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.clock.op; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.stmt.Stmts.Assign; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.AssignStmt; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.stmt.Stmts.Assign; - public final class CopyOp implements ClockOp { private static final int HASH_SEED = 1289; @@ -95,8 +94,9 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder("copy").add(varDecl.getName()).add(value.getName()) + return Utils.lispStringBuilder("copy") + .add(varDecl.getName()) + .add(value.getName()) .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FailClockOpVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FailClockOpVisitor.java index fcff79029a..e7d6e11b4d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FailClockOpVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FailClockOpVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -41,5 +41,4 @@ public R visit(final ResetOp op, final P param) { public R visit(final ShiftOp op, final P param) { throw new UnsupportedOperationException(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FreeOp.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FreeOp.java index c33a965df5..7f99bae9b9 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FreeOp.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/FreeOp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.clock.op; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.stmt.Stmts.Havoc; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.HavocStmt; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.stmt.Stmts.Havoc; - public final class FreeOp implements ClockOp { private static final int HASH_SEED = 2281; @@ -90,5 +89,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder("free").add(varDecl.getName()).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/GuardOp.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/GuardOp.java index 7e05381d8a..e78531a950 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/GuardOp.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/GuardOp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.clock.op; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.stmt.Stmts.Assume; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.clock.constr.ClockConstr; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.stmt.Stmts.Assume; - public final class GuardOp implements ClockOp { private static final int HASH_SEED = 3533; @@ -90,5 +89,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder("guard").add(constr).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ResetOp.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ResetOp.java index 6c429bd29b..0694c32e7f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ResetOp.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ResetOp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.core.clock.op; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.stmt.Stmts.Assign; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.AssignStmt; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.stmt.Stmts.Assign; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class ResetOp implements ClockOp { private static final int HASH_SEED = 4507; @@ -100,5 +99,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder("reset").add(varDecl.getName()).add(value).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ShiftOp.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ShiftOp.java index 919d789802..50c4dd751e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ShiftOp.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/op/ShiftOp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.core.clock.op; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.stmt.Stmts.Assign; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Add; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.AssignStmt; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.stmt.Stmts.Assign; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Add; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class ShiftOp implements ClockOp { private static final int HASH_SEED = 5521; @@ -99,5 +98,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder("shift").add(varDecl.getName()).add(offset).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/package-info.java index 1ed0b739df..3a1111aa9e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/clock/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ * @see hu.bme.mit.theta.core.clock.constr.ClockConstrs * @see hu.bme.mit.theta.core.clock.op.ClockOps */ - -package hu.bme.mit.theta.core.clock; \ No newline at end of file +package hu.bme.mit.theta.core.clock; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/BasicConstDecl.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/BasicConstDecl.java index e30e9ee384..af0d3902ab 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/BasicConstDecl.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/BasicConstDecl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,5 +27,4 @@ public final class BasicConstDecl extends ConstDecl */ @@ -37,5 +37,4 @@ public abstract class ConstDecl extends Decl { public final String toString() { return Utils.lispStringBuilder(DECL_LABEL).add(getName()).add(getType()).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decl.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decl.java index fd3b4ac587..d08caf12f2 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decl.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -67,5 +67,4 @@ public final int hashCode() { public final boolean equals(final Object obj) { return this == obj; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decls.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decls.java index 49e22d9667..a5efae9451 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decls.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/Decls.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,10 @@ import hu.bme.mit.theta.core.type.Type; -/** - * Factory class to create declarations. - */ +/** Factory class to create declarations. */ public final class Decls { - private Decls() { - } + private Decls() {} /** * Create a constant declaration with a given name and type. @@ -60,5 +57,4 @@ public static ParamDecl Param(final String name, final T typ public static VarDecl Var(final String name, final T type) { return new VarDecl<>(name, type); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedConstDecl.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedConstDecl.java index ba49b320cc..8a50879cde 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedConstDecl.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedConstDecl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -47,5 +47,4 @@ public VarDecl getVarDecl() { public int getIndex() { return index; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedVarDecl.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedVarDecl.java index 3db7eac289..c84943485d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedVarDecl.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/IndexedVarDecl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.decl; import hu.bme.mit.theta.core.type.Type; @@ -32,7 +31,8 @@ public class IndexedVarDecl extends VarDecl { this.constRef = RefExpr.of(constDecl); } - public static IndexedVarDecl of(final String name, final VarDecl original) { + public static IndexedVarDecl of( + final String name, final VarDecl original) { return new IndexedVarDecl<>(name, original); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/ParamDecl.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/ParamDecl.java index 02fe29f6b5..cfa4c1fd13 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/ParamDecl.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/ParamDecl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/VarDecl.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/VarDecl.java index 416c951247..d416347a7a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/VarDecl.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/VarDecl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,17 @@ */ package hu.bme.mit.theta.core.decl; +import static com.google.common.base.Preconditions.checkArgument; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.anytype.RefExpr; - import java.util.Map; -import static com.google.common.base.Preconditions.checkArgument; - /** * Represents a variable declaration. Variables cannot be directly passed to the SMT solver, they - * must be replaced with constants for a given index ({@link IndexedConstDecl}). See also - * {@link hu.bme.mit.theta.core.utils.PathUtils}. + * must be replaced with constants for a given index ({@link IndexedConstDecl}). See also {@link + * hu.bme.mit.theta.core.utils.PathUtils}. * * @param */ @@ -60,5 +58,4 @@ public IndexedConstDecl getConstDecl(final int index) { public String toString() { return Utils.lispStringBuilder(DECL_LABEL).add(getName()).add(getType()).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/package-info.java index 90d55d2ff4..a6c9b114bf 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/decl/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,11 @@ */ /** * This package contains the different declarations. - {@link hu.bme.mit.theta.core.decl.ConstDecl} - * represents a constant that can be directly handled by the SMT solvers. - - * {@link hu.bme.mit.theta.core.decl.VarDecl} represents a variable, that can have multiple - * associated {@link hu.bme.mit.theta.core.decl.ConstDecl}s for each index (e.g. in a path) - - * {@link hu.bme.mit.theta.core.decl.ParamDecl} represents a parameter declaration. - *

- * Use the factory class {@link hu.bme.mit.theta.core.decl.Decls} to instantiate them. + * represents a constant that can be directly handled by the SMT solvers. - {@link + * hu.bme.mit.theta.core.decl.VarDecl} represents a variable, that can have multiple associated + * {@link hu.bme.mit.theta.core.decl.ConstDecl}s for each index (e.g. in a path) - {@link + * hu.bme.mit.theta.core.decl.ParamDecl} represents a parameter declaration. + * + *

Use the factory class {@link hu.bme.mit.theta.core.decl.Decls} to instantiate them. */ - -package hu.bme.mit.theta.core.decl; \ No newline at end of file +package hu.bme.mit.theta.core.decl; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/CoreDslManager.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/CoreDslManager.java index adbd5660f8..ca05a3e400 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/CoreDslManager.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/CoreDslManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,11 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.tree.ParseTree; - import hu.bme.mit.theta.common.dsl.BasicScope; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.dsl.gen.CoreDslLexer; @@ -34,10 +29,12 @@ import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.tree.ParseTree; -/** - * Utility class for parsing types, expressions and statements. - */ +/** Utility class for parsing types, expressions and statements. */ public final class CoreDslManager { private final BasicScope scope; @@ -93,5 +90,4 @@ private static CoreDslParser createParserForString(final String string) { final CoreDslParser parser = new CoreDslParser(tokens); return parser; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/DeclSymbol.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/DeclSymbol.java index 206b220866..76d8f63a54 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/DeclSymbol.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/DeclSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.core.dsl; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.decl.Decl; -import static com.google.common.base.Preconditions.checkNotNull; - public final class DeclSymbol implements Symbol { private static final int HASH_SEED = 8513; @@ -73,5 +73,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder(getClass().getSimpleName()).add(decl).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParamBinding.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParamBinding.java index 987cf9160f..e06d780916 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParamBinding.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParamBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,29 +18,25 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - -import hu.bme.mit.theta.common.container.Containers; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - import com.google.common.collect.ImmutableList; - +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.model.Substitution; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; public final class ParamBinding implements Substitution { private final List> params; private final Map, Expr> paramToArg; - public ParamBinding(final List> params, - final List> args) { + public ParamBinding( + final List> params, final List> args) { checkNotNull(params); checkNotNull(args); checkArgument(params.size() == args.size()); @@ -56,8 +52,8 @@ public ParamBinding(final List> params, } } - public static ParamBinding create(final List> params, - final List> args) { + public static ParamBinding create( + final List> params, final List> args) { return new ParamBinding(params, args); } @@ -71,8 +67,8 @@ public Collection> getDecls() { @Override public Optional> eval( final Decl decl) { - @SuppressWarnings("unchecked") final Expr value = (Expr) paramToArg.get( - decl); + @SuppressWarnings("unchecked") + final Expr value = (Expr) paramToArg.get(decl); return Optional.ofNullable(value); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParseException.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParseException.java index 2a234197be..b5749b64e3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParseException.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/ParseException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,8 +24,13 @@ public ParseException(ParserRuleContext ctx, String message) { } public ParseException(ParserRuleContext ctx, String message, Throwable cause) { - super("Line " + ctx.getStart().getLine() + " col " + ctx.getStart().getCharPositionInLine() - + ": " + message, cause); + super( + "Line " + + ctx.getStart().getLine() + + " col " + + ctx.getStart().getCharPositionInLine() + + ": " + + message, + cause); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/CoreDslHelper.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/CoreDslHelper.java index 839423f6e4..4e7894a761 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/CoreDslHelper.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/CoreDslHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,10 +20,6 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static java.util.stream.Collectors.toList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.decl.ParamDecl; @@ -40,11 +36,13 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.TypeUtils; +import java.util.Collections; +import java.util.List; +import java.util.Optional; public final class CoreDslHelper { - private CoreDslHelper() { - } + private CoreDslHelper() {} public static ParamDecl createParamDecl(final DeclContext declCtx) { final String name = declCtx.name.getText(); @@ -73,13 +71,13 @@ public static Expr createExpr(final Scope scope, final ExprContext exprCtx) { return expr; } - public static List> createExprList(final Scope scope, - final ExprListContext exprListCtx) { + public static List> createExprList( + final Scope scope, final ExprListContext exprListCtx) { if (exprListCtx == null || exprListCtx.exprs == null) { return Collections.emptyList(); } else { - final List> exprs = exprListCtx.exprs.stream() - .map(ctx -> createExpr(scope, ctx)).collect(toList()); + final List> exprs = + exprListCtx.exprs.stream().map(ctx -> createExpr(scope, ctx)).collect(toList()); return exprs; } } @@ -88,11 +86,11 @@ public static Expr createBoolExpr(final Scope scope, final ExprContext return TypeUtils.cast(createExpr(scope, exprCtx), Bool()); } - public static List> createBoolExprList(final Scope scope, - final ExprListContext exprListCtx) { + public static List> createBoolExprList( + final Scope scope, final ExprListContext exprListCtx) { final List> exprs = createExprList(scope, exprListCtx); - final List> boolExprs = exprs.stream().map(e -> TypeUtils.cast(e, Bool())) - .collect(toList()); + final List> boolExprs = + exprs.stream().map(e -> TypeUtils.cast(e, Bool())).collect(toList()); return boolExprs; } @@ -106,8 +104,8 @@ public static List createStmtList(final Scope scope, final StmtListContext if (stmtListCtx == null || stmtListCtx.stmts.isEmpty()) { return Collections.emptyList(); } else { - final List stmts = stmtListCtx.stmts.stream().map(ctx -> createStmt(scope, ctx)) - .collect(toList()); + final List stmts = + stmtListCtx.stmts.stream().map(ctx -> createStmt(scope, ctx)).collect(toList()); return stmts; } } @@ -123,5 +121,4 @@ public static DeclSymbol resolveDecl(final Scope scope, final String name) { return declSymbol; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprCreatorVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprCreatorVisitor.java index 62d63559c3..0e265cfe84 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprCreatorVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprCreatorVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,83 +15,6 @@ */ package hu.bme.mit.theta.core.dsl.impl; -import com.google.common.collect.ImmutableList; -import hu.bme.mit.theta.common.dsl.BasicScope; -import hu.bme.mit.theta.common.dsl.Scope; -import hu.bme.mit.theta.common.dsl.Symbol; -import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.decl.ParamDecl; -import hu.bme.mit.theta.core.dsl.DeclSymbol; -import hu.bme.mit.theta.core.dsl.gen.CoreDslBaseVisitor; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AccessContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AccessorExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AdditiveExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AndExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ArrayAccessContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseAndExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseOrExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseShiftExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseXorExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BvConcatExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BvExtendExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BvExtractAccessContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.DeclListContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.EqualityExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ExistsExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.FalseExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ForallExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.FuncAccessContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.FuncLitExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IdExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IffExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ImplyExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IntLitExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IteExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.MultiplicativeExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.NotExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.OrExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ParenExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.RatLitExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.RelationExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.TrueExprContext; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.UnaryExprContext; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.abstracttype.AddExpr; -import hu.bme.mit.theta.core.type.abstracttype.DivExpr; -import hu.bme.mit.theta.core.type.abstracttype.MulExpr; -import hu.bme.mit.theta.core.type.abstracttype.SubExpr; -import hu.bme.mit.theta.core.type.anytype.RefExpr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.booltype.FalseExpr; -import hu.bme.mit.theta.core.type.booltype.TrueExpr; -import hu.bme.mit.theta.core.type.bvtype.BvAddExpr; -import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr; -import hu.bme.mit.theta.core.type.bvtype.BvExprs; -import hu.bme.mit.theta.core.type.bvtype.BvMulExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSModExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSubExpr; -import hu.bme.mit.theta.core.type.bvtype.BvType; -import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr; -import hu.bme.mit.theta.core.type.bvtype.BvURemExpr; -import hu.bme.mit.theta.core.type.functype.FuncExprs; -import hu.bme.mit.theta.core.type.inttype.IntLitExpr; -import hu.bme.mit.theta.core.type.inttype.IntModExpr; -import hu.bme.mit.theta.core.type.inttype.IntRemExpr; -import hu.bme.mit.theta.core.type.inttype.IntType; -import hu.bme.mit.theta.core.type.rattype.RatLitExpr; -import hu.bme.mit.theta.core.utils.TypeUtils; -import org.antlr.v4.runtime.Token; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.stream.Stream; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; @@ -170,6 +93,82 @@ import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; import static java.util.stream.Collectors.toList; +import com.google.common.collect.ImmutableList; +import hu.bme.mit.theta.common.dsl.BasicScope; +import hu.bme.mit.theta.common.dsl.Scope; +import hu.bme.mit.theta.common.dsl.Symbol; +import hu.bme.mit.theta.core.decl.Decl; +import hu.bme.mit.theta.core.decl.ParamDecl; +import hu.bme.mit.theta.core.dsl.DeclSymbol; +import hu.bme.mit.theta.core.dsl.gen.CoreDslBaseVisitor; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AccessContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AccessorExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AdditiveExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AndExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ArrayAccessContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseAndExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseOrExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseShiftExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BitwiseXorExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BvConcatExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BvExtendExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BvExtractAccessContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.DeclListContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.EqualityExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ExistsExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.FalseExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ForallExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.FuncAccessContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.FuncLitExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IdExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IffExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ImplyExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IntLitExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.IteExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.MultiplicativeExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.NotExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.OrExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ParenExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.RatLitExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.RelationExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.TrueExprContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.UnaryExprContext; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.abstracttype.AddExpr; +import hu.bme.mit.theta.core.type.abstracttype.DivExpr; +import hu.bme.mit.theta.core.type.abstracttype.MulExpr; +import hu.bme.mit.theta.core.type.abstracttype.SubExpr; +import hu.bme.mit.theta.core.type.anytype.RefExpr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.booltype.FalseExpr; +import hu.bme.mit.theta.core.type.booltype.TrueExpr; +import hu.bme.mit.theta.core.type.bvtype.BvAddExpr; +import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr; +import hu.bme.mit.theta.core.type.bvtype.BvExprs; +import hu.bme.mit.theta.core.type.bvtype.BvMulExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSModExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSubExpr; +import hu.bme.mit.theta.core.type.bvtype.BvType; +import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr; +import hu.bme.mit.theta.core.type.bvtype.BvURemExpr; +import hu.bme.mit.theta.core.type.functype.FuncExprs; +import hu.bme.mit.theta.core.type.inttype.IntLitExpr; +import hu.bme.mit.theta.core.type.inttype.IntModExpr; +import hu.bme.mit.theta.core.type.inttype.IntRemExpr; +import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.core.type.rattype.RatLitExpr; +import hu.bme.mit.theta.core.utils.TypeUtils; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; +import org.antlr.v4.runtime.Token; + public final class ExprCreatorVisitor extends CoreDslBaseVisitor> { private Scope currentScope; @@ -199,13 +198,13 @@ public Expr visitFuncLitExpr(final FuncLitExprContext ctx) { final List> params = createParamList(ctx.paramDecls); checkArgument(params.size() == 1); - @SuppressWarnings("unchecked") final ParamDecl param = (ParamDecl) singleElementOf( - params); + @SuppressWarnings("unchecked") + final ParamDecl param = (ParamDecl) singleElementOf(params); push(params); - @SuppressWarnings("unchecked") final Expr result = (Expr) ctx.result.accept( - this); + @SuppressWarnings("unchecked") + final Expr result = (Expr) ctx.result.accept(this); pop(); @@ -220,9 +219,15 @@ private List> createParamList(final DeclListContext ctx) { if (ctx.decls == null) { return Collections.emptyList(); } else { - final List> paramDecls = ctx.decls.stream() - .map(d -> Param(d.name.getText(), d.ttype.accept(TypeCreatorVisitor.getInstance()))) - .collect(toList()); + final List> paramDecls = + ctx.decls.stream() + .map( + d -> + Param( + d.name.getText(), + d.ttype.accept( + TypeCreatorVisitor.getInstance()))) + .collect(toList()); return paramDecls; } } @@ -296,8 +301,8 @@ public Expr visitExistsExpr(final ExistsExprContext ctx) { @Override public Expr visitOrExpr(final OrExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> TypeUtils.cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> TypeUtils.cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return Or(ops); } else { @@ -308,8 +313,8 @@ public Expr visitOrExpr(final OrExprContext ctx) { @Override public Expr visitAndExpr(final AndExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> TypeUtils.cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> TypeUtils.cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return And(ops); } else { @@ -486,8 +491,10 @@ public Expr visitAdditiveExpr(final AdditiveExprContext ctx) { } } - private Expr createAdditiveExpr(final Expr opsHead, final List> opsTail, - final List opers) { + private Expr createAdditiveExpr( + final Expr opsHead, + final List> opsTail, + final List opers) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -505,10 +512,9 @@ private Expr createAdditiveExpr(final Expr opsHead, final List createAdditiveSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper) { + private Expr createAdditiveSubExpr( + final Expr leftOp, final Expr rightOp, final Token oper) { switch (oper.getType()) { - case PLUS: return createAddExpr(leftOp, rightOp); @@ -529,8 +535,11 @@ private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightO private AddExpr createAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof AddExpr) { final AddExpr addLeftOp = (AddExpr) leftOp; - final List> ops = ImmutableList.>builder().addAll(addLeftOp.getOps()) - .add(rightOp).build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Add(ops); } else { return Add(leftOp, rightOp); @@ -544,9 +553,11 @@ private SubExpr createSubExpr(final Expr leftOp, final Expr rightOp) { private BvAddExpr createBvAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof BvAddExpr) { final BvAddExpr addLeftOp = (BvAddExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return BvExprs.Add(ops); } else { return BvExprs.Add(Arrays.asList(leftOp, rightOp)); @@ -572,12 +583,12 @@ public Expr visitMultiplicativeExpr(final MultiplicativeExprContext ctx) { } else { return visitChildren(ctx); } - } - private Expr createMutliplicativeExpr(final Expr opsHead, - final List> opsTail, - final List opers) { + private Expr createMutliplicativeExpr( + final Expr opsHead, + final List> opsTail, + final List opers) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -595,10 +606,9 @@ private Expr createMutliplicativeExpr(final Expr opsHead, } } - private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper) { + private Expr createMultiplicativeSubExpr( + final Expr leftOp, final Expr rightOp, final Token oper) { switch (oper.getType()) { - case MUL: return createMulExpr(leftOp, rightOp); @@ -637,8 +647,11 @@ private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof MulExpr) { final MulExpr addLeftOp = (MulExpr) leftOp; - final List> ops = ImmutableList.>builder().addAll(addLeftOp.getOps()) - .add(rightOp).build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Mul(ops); } else { return Mul(leftOp, rightOp); @@ -648,9 +661,11 @@ private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { private BvMulExpr createBvMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof BvMulExpr) { final BvMulExpr addLeftOp = (BvMulExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return BvExprs.Mul(ops); } else { return BvExprs.Mul(Arrays.asList(leftOp, rightOp)); @@ -710,8 +725,10 @@ public Expr visitBvConcatExpr(final BvConcatExprContext ctx) { } } - private Expr createConcatExpr(final Expr opsHead, final List> opsTail, - final List opers) { + private Expr createConcatExpr( + final Expr opsHead, + final List> opsTail, + final List opers) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -729,8 +746,8 @@ private Expr createConcatExpr(final Expr opsHead, final List createConcatSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper) { + private Expr createConcatSubExpr( + final Expr leftOp, final Expr rightOp, final Token oper) { switch (oper.getType()) { case BV_CONCAT: return createBvConcatExpr(castBv(leftOp), castBv(rightOp)); @@ -743,16 +760,17 @@ private Expr createConcatSubExpr(final Expr leftOp, final Expr rightOp, private BvConcatExpr createBvConcatExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof BvConcatExpr) { final BvConcatExpr addLeftOp = (BvConcatExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return BvExprs.Concat(ops); } else { return BvExprs.Concat(Arrays.asList(leftOp, rightOp)); } } - @Override public Expr visitBvExtendExpr(final BvExtendExprContext ctx) { if (ctx.rightOp != null) { @@ -890,5 +908,4 @@ public RefExpr visitIdExpr(final IdExprContext ctx) { public Expr visitParenExpr(final ParenExprContext ctx) { return ctx.op.accept(this); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprWriter.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprWriter.java index de972ad3ef..1c05beeebb 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprWriter.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/ExprWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -124,7 +124,6 @@ import hu.bme.mit.theta.core.type.rattype.RatNeqExpr; import hu.bme.mit.theta.core.type.rattype.RatPosExpr; import hu.bme.mit.theta.core.type.rattype.RatSubExpr; - import java.util.Arrays; import java.util.stream.Collectors; @@ -142,236 +141,139 @@ public static ExprWriter instance() { } private ExprWriter() { - table = DispatchTable.builder() - - // Boolean - - .addCase(NotExpr.class, e -> prefixUnary(e, "not ")) - - .addCase(ImplyExpr.class, e -> infixBinary(e, " imply ")) - - .addCase(IffExpr.class, e -> infixBinary(e, " iff ")) - - .addCase(AndExpr.class, e -> infixMultiary(e, " and ")) - - .addCase(OrExpr.class, e -> infixMultiary(e, " or ")) - - .addCase(XorExpr.class, e -> infixBinary(e, " xor ")) - - .addCase(TrueExpr.class, e -> "true") - - .addCase(FalseExpr.class, e -> "false") - - .addCase(ForallExpr.class, this::forall) - - .addCase(ExistsExpr.class, this::exists) - - // Integer - - .addCase(IntAddExpr.class, e -> infixMultiary(e, " + ")) - - .addCase(IntSubExpr.class, e -> infixBinary(e, " - ")) - - .addCase(IntPosExpr.class, e -> prefixUnary(e, "+")) - - .addCase(IntNegExpr.class, e -> prefixUnary(e, "-")) - - .addCase(IntMulExpr.class, e -> infixMultiary(e, " * ")) - - .addCase(IntDivExpr.class, e -> infixBinary(e, " / ")) - - .addCase(IntModExpr.class, e -> infixBinary(e, " mod ")) - - .addCase(IntRemExpr.class, e -> infixBinary(e, " rem ")) - - .addCase(IntEqExpr.class, e -> infixBinary(e, " = ")) - - .addCase(IntNeqExpr.class, e -> infixBinary(e, " /= ")) - - .addCase(IntGeqExpr.class, e -> infixBinary(e, " >= ")) - - .addCase(IntGtExpr.class, e -> infixBinary(e, " > ")) - - .addCase(IntLeqExpr.class, e -> infixBinary(e, " <= ")) - - .addCase(IntLtExpr.class, e -> infixBinary(e, " < ")) - - .addCase(IntLitExpr.class, e -> e.getValue() + "") - - .addCase(IntToRatExpr.class, e -> prefixUnary(e, "(rat)")) - - // Rational - - .addCase(RatAddExpr.class, e -> infixMultiary(e, " + ")) - - .addCase(RatSubExpr.class, e -> infixBinary(e, " - ")) - - .addCase(RatPosExpr.class, e -> prefixUnary(e, "+")) - - .addCase(RatNegExpr.class, e -> prefixUnary(e, "-")) - - .addCase(RatMulExpr.class, e -> infixMultiary(e, " * ")) - - .addCase(RatDivExpr.class, e -> infixBinary(e, " / ")) - - .addCase(RatEqExpr.class, e -> infixBinary(e, " = ")) - - .addCase(RatNeqExpr.class, e -> infixBinary(e, " /= ")) - - .addCase(RatGeqExpr.class, e -> infixBinary(e, " >= ")) - - .addCase(RatGtExpr.class, e -> infixBinary(e, " > ")) - - .addCase(RatLeqExpr.class, e -> infixBinary(e, " <= ")) - - .addCase(RatLtExpr.class, e -> infixBinary(e, " < ")) - - .addCase(RatLitExpr.class, e -> e.getNum() + "%" + e.getDenom()) - - // Bitvector - - .addCase(BvConcatExpr.class, this::bvConcat) - - .addCase(BvExtractExpr.class, this::bvExtract) - - .addCase(BvZExtExpr.class, this::bvZExt) - - .addCase(BvSExtExpr.class, this::bvSExt) - - .addCase(BvAddExpr.class, e -> infixMultiary(e, " bvadd ")) - - .addCase(BvSubExpr.class, e -> infixBinary(e, " bvsub ")) - - .addCase(BvMulExpr.class, e -> infixMultiary(e, " bvmul ")) - - .addCase(BvUDivExpr.class, e -> infixBinary(e, " bvudiv ")) - - .addCase(BvSDivExpr.class, e -> infixBinary(e, " bvsdiv ")) - - .addCase(BvSModExpr.class, e -> infixBinary(e, " bvsmod ")) - - .addCase(BvURemExpr.class, e -> infixBinary(e, " bvurem ")) - - .addCase(BvSRemExpr.class, e -> infixBinary(e, " bvsrem ")) - - .addCase(BvPosExpr.class, e -> prefixUnary(e, "bvpos")) - - .addCase(BvSignChangeExpr.class, e -> prefixUnary(e, "bvsign")) - - .addCase(BvNegExpr.class, e -> prefixUnary(e, "bvneg")) - - .addCase(BvAndExpr.class, e -> infixMultiary(e, " bvand ")) - - .addCase(BvOrExpr.class, e -> infixMultiary(e, " bvor ")) - - .addCase(BvXorExpr.class, e -> infixMultiary(e, " bvxor ")) - - .addCase(BvNotExpr.class, e -> prefixUnary(e, "bvnot")) - - .addCase(BvShiftLeftExpr.class, e -> infixBinary(e, " bvshl ")) - - .addCase(BvArithShiftRightExpr.class, e -> infixBinary(e, " bvashr ")) - - .addCase(BvLogicShiftRightExpr.class, e -> infixBinary(e, " bvlshr ")) - - .addCase(BvRotateLeftExpr.class, e -> infixBinary(e, " bvrol ")) - - .addCase(BvRotateRightExpr.class, e -> infixBinary(e, " bvror ")) - - .addCase(BvEqExpr.class, e -> infixBinary(e, " = ")) - - .addCase(BvNeqExpr.class, e -> infixBinary(e, " /= ")) - - .addCase(BvULtExpr.class, e -> infixBinary(e, " bvult ")) - - .addCase(BvULeqExpr.class, e -> infixBinary(e, " bvule ")) - - .addCase(BvUGtExpr.class, e -> infixBinary(e, " bvugt ")) - - .addCase(BvUGeqExpr.class, e -> infixBinary(e, " buge ")) - - .addCase(BvSLtExpr.class, e -> infixBinary(e, " bvslt ")) - - .addCase(BvSLeqExpr.class, e -> infixBinary(e, " bvsle ")) - - .addCase(BvSGtExpr.class, e -> infixBinary(e, " bvsgt ")) - - .addCase(BvSGeqExpr.class, e -> infixBinary(e, " bsge ")) - - .addCase(BvLitExpr.class, this::bvLit) - - // Array - - .addCase(ArrayReadExpr.class, this::arrayRead) - - .addCase(ArrayWriteExpr.class, this::arrayWrite) - - .addCase(ArrayEqExpr.class, e -> infixBinary(e, " = ")) - - .addCase(ArrayNeqExpr.class, e -> infixBinary(e, " /= ")) - - .addCase(ArrayLitExpr.class, this::arrayLit) - - .addCase(ArrayInitExpr.class, this::arrayInit) - - // FloatingPoint - - .addCase(FpAbsExpr.class, e -> prefixUnary(e, " fpabs ")) - - .addCase(FpAddExpr.class, e -> infixMultiary(e, " + ")) - - .addCase(FpDivExpr.class, e -> infixBinary(e, " / ")) - - .addCase(FpEqExpr.class, e -> infixBinary(e, " == ")) - - .addCase(FpFromBvExpr.class, e -> prefixUnary(e, " fpfrombv ")) - - .addCase(FpGeqExpr.class, e -> infixBinary(e, " >= ")) - - .addCase(FpGtExpr.class, e -> infixBinary(e, " > ")) - - .addCase(FpLeqExpr.class, e -> infixBinary(e, " <= ")) - - .addCase(FpLtExpr.class, e -> infixBinary(e, " < ")) - - .addCase(FpLitExpr.class, FpLitExpr::toString) - - .addCase(FpMaxExpr.class, e -> infixBinary(e, " fpmax ")) - - .addCase(FpMinExpr.class, e -> infixBinary(e, " fpmin ")) - - .addCase(FpMulExpr.class, e -> infixMultiary(e, " * ")) - - .addCase(FpNegExpr.class, e -> prefixUnary(e, " - ")) - - .addCase(FpNeqExpr.class, e -> infixBinary(e, " != ")) - - .addCase(FpPosExpr.class, e -> prefixUnary(e, " + ")) - - .addCase(FpRemExpr.class, e -> infixBinary(e, " % ")) - - .addCase(FpSqrtExpr.class, e -> prefixUnary(e, " sqrt ")) - - .addCase(FpSubExpr.class, e -> infixBinary(e, " - ")) - - .addCase(FpToBvExpr.class, e -> prefixUnary(e, " fptobv ")) - - .addCase(FpToFpExpr.class, e -> prefixUnary(e, " fptofp ")) - - // General - - .addCase(RefExpr.class, e -> e.getDecl().getName()) - - .addCase(IteExpr.class, this::ite) - - .addCase(PrimeExpr.class, e -> postfixUnary(e, "'")) - - .addDefault(e -> { - throw new UnsupportedOperationException( - "Expression not supported: " + e.toString()); - }) - - .build(); + table = + DispatchTable.builder() + + // Boolean + + .addCase(NotExpr.class, e -> prefixUnary(e, "not ")) + .addCase(ImplyExpr.class, e -> infixBinary(e, " imply ")) + .addCase(IffExpr.class, e -> infixBinary(e, " iff ")) + .addCase(AndExpr.class, e -> infixMultiary(e, " and ")) + .addCase(OrExpr.class, e -> infixMultiary(e, " or ")) + .addCase(XorExpr.class, e -> infixBinary(e, " xor ")) + .addCase(TrueExpr.class, e -> "true") + .addCase(FalseExpr.class, e -> "false") + .addCase(ForallExpr.class, this::forall) + .addCase(ExistsExpr.class, this::exists) + + // Integer + + .addCase(IntAddExpr.class, e -> infixMultiary(e, " + ")) + .addCase(IntSubExpr.class, e -> infixBinary(e, " - ")) + .addCase(IntPosExpr.class, e -> prefixUnary(e, "+")) + .addCase(IntNegExpr.class, e -> prefixUnary(e, "-")) + .addCase(IntMulExpr.class, e -> infixMultiary(e, " * ")) + .addCase(IntDivExpr.class, e -> infixBinary(e, " / ")) + .addCase(IntModExpr.class, e -> infixBinary(e, " mod ")) + .addCase(IntRemExpr.class, e -> infixBinary(e, " rem ")) + .addCase(IntEqExpr.class, e -> infixBinary(e, " = ")) + .addCase(IntNeqExpr.class, e -> infixBinary(e, " /= ")) + .addCase(IntGeqExpr.class, e -> infixBinary(e, " >= ")) + .addCase(IntGtExpr.class, e -> infixBinary(e, " > ")) + .addCase(IntLeqExpr.class, e -> infixBinary(e, " <= ")) + .addCase(IntLtExpr.class, e -> infixBinary(e, " < ")) + .addCase(IntLitExpr.class, e -> e.getValue() + "") + .addCase(IntToRatExpr.class, e -> prefixUnary(e, "(rat)")) + + // Rational + + .addCase(RatAddExpr.class, e -> infixMultiary(e, " + ")) + .addCase(RatSubExpr.class, e -> infixBinary(e, " - ")) + .addCase(RatPosExpr.class, e -> prefixUnary(e, "+")) + .addCase(RatNegExpr.class, e -> prefixUnary(e, "-")) + .addCase(RatMulExpr.class, e -> infixMultiary(e, " * ")) + .addCase(RatDivExpr.class, e -> infixBinary(e, " / ")) + .addCase(RatEqExpr.class, e -> infixBinary(e, " = ")) + .addCase(RatNeqExpr.class, e -> infixBinary(e, " /= ")) + .addCase(RatGeqExpr.class, e -> infixBinary(e, " >= ")) + .addCase(RatGtExpr.class, e -> infixBinary(e, " > ")) + .addCase(RatLeqExpr.class, e -> infixBinary(e, " <= ")) + .addCase(RatLtExpr.class, e -> infixBinary(e, " < ")) + .addCase(RatLitExpr.class, e -> e.getNum() + "%" + e.getDenom()) + + // Bitvector + + .addCase(BvConcatExpr.class, this::bvConcat) + .addCase(BvExtractExpr.class, this::bvExtract) + .addCase(BvZExtExpr.class, this::bvZExt) + .addCase(BvSExtExpr.class, this::bvSExt) + .addCase(BvAddExpr.class, e -> infixMultiary(e, " bvadd ")) + .addCase(BvSubExpr.class, e -> infixBinary(e, " bvsub ")) + .addCase(BvMulExpr.class, e -> infixMultiary(e, " bvmul ")) + .addCase(BvUDivExpr.class, e -> infixBinary(e, " bvudiv ")) + .addCase(BvSDivExpr.class, e -> infixBinary(e, " bvsdiv ")) + .addCase(BvSModExpr.class, e -> infixBinary(e, " bvsmod ")) + .addCase(BvURemExpr.class, e -> infixBinary(e, " bvurem ")) + .addCase(BvSRemExpr.class, e -> infixBinary(e, " bvsrem ")) + .addCase(BvPosExpr.class, e -> prefixUnary(e, "bvpos")) + .addCase(BvSignChangeExpr.class, e -> prefixUnary(e, "bvsign")) + .addCase(BvNegExpr.class, e -> prefixUnary(e, "bvneg")) + .addCase(BvAndExpr.class, e -> infixMultiary(e, " bvand ")) + .addCase(BvOrExpr.class, e -> infixMultiary(e, " bvor ")) + .addCase(BvXorExpr.class, e -> infixMultiary(e, " bvxor ")) + .addCase(BvNotExpr.class, e -> prefixUnary(e, "bvnot")) + .addCase(BvShiftLeftExpr.class, e -> infixBinary(e, " bvshl ")) + .addCase(BvArithShiftRightExpr.class, e -> infixBinary(e, " bvashr ")) + .addCase(BvLogicShiftRightExpr.class, e -> infixBinary(e, " bvlshr ")) + .addCase(BvRotateLeftExpr.class, e -> infixBinary(e, " bvrol ")) + .addCase(BvRotateRightExpr.class, e -> infixBinary(e, " bvror ")) + .addCase(BvEqExpr.class, e -> infixBinary(e, " = ")) + .addCase(BvNeqExpr.class, e -> infixBinary(e, " /= ")) + .addCase(BvULtExpr.class, e -> infixBinary(e, " bvult ")) + .addCase(BvULeqExpr.class, e -> infixBinary(e, " bvule ")) + .addCase(BvUGtExpr.class, e -> infixBinary(e, " bvugt ")) + .addCase(BvUGeqExpr.class, e -> infixBinary(e, " buge ")) + .addCase(BvSLtExpr.class, e -> infixBinary(e, " bvslt ")) + .addCase(BvSLeqExpr.class, e -> infixBinary(e, " bvsle ")) + .addCase(BvSGtExpr.class, e -> infixBinary(e, " bvsgt ")) + .addCase(BvSGeqExpr.class, e -> infixBinary(e, " bsge ")) + .addCase(BvLitExpr.class, this::bvLit) + + // Array + + .addCase(ArrayReadExpr.class, this::arrayRead) + .addCase(ArrayWriteExpr.class, this::arrayWrite) + .addCase(ArrayEqExpr.class, e -> infixBinary(e, " = ")) + .addCase(ArrayNeqExpr.class, e -> infixBinary(e, " /= ")) + .addCase(ArrayLitExpr.class, this::arrayLit) + .addCase(ArrayInitExpr.class, this::arrayInit) + + // FloatingPoint + + .addCase(FpAbsExpr.class, e -> prefixUnary(e, " fpabs ")) + .addCase(FpAddExpr.class, e -> infixMultiary(e, " + ")) + .addCase(FpDivExpr.class, e -> infixBinary(e, " / ")) + .addCase(FpEqExpr.class, e -> infixBinary(e, " == ")) + .addCase(FpFromBvExpr.class, e -> prefixUnary(e, " fpfrombv ")) + .addCase(FpGeqExpr.class, e -> infixBinary(e, " >= ")) + .addCase(FpGtExpr.class, e -> infixBinary(e, " > ")) + .addCase(FpLeqExpr.class, e -> infixBinary(e, " <= ")) + .addCase(FpLtExpr.class, e -> infixBinary(e, " < ")) + .addCase(FpLitExpr.class, FpLitExpr::toString) + .addCase(FpMaxExpr.class, e -> infixBinary(e, " fpmax ")) + .addCase(FpMinExpr.class, e -> infixBinary(e, " fpmin ")) + .addCase(FpMulExpr.class, e -> infixMultiary(e, " * ")) + .addCase(FpNegExpr.class, e -> prefixUnary(e, " - ")) + .addCase(FpNeqExpr.class, e -> infixBinary(e, " != ")) + .addCase(FpPosExpr.class, e -> prefixUnary(e, " + ")) + .addCase(FpRemExpr.class, e -> infixBinary(e, " % ")) + .addCase(FpSqrtExpr.class, e -> prefixUnary(e, " sqrt ")) + .addCase(FpSubExpr.class, e -> infixBinary(e, " - ")) + .addCase(FpToBvExpr.class, e -> prefixUnary(e, " fptobv ")) + .addCase(FpToFpExpr.class, e -> prefixUnary(e, " fptofp ")) + + // General + + .addCase(RefExpr.class, e -> e.getDecl().getName()) + .addCase(IteExpr.class, this::ite) + .addCase(PrimeExpr.class, e -> postfixUnary(e, "'")) + .addDefault( + e -> { + throw new UnsupportedOperationException( + "Expression not supported: " + e.toString()); + }) + .build(); } public String write(final Expr expr) { @@ -392,8 +294,9 @@ private String postfixUnary(final UnaryExpr expr, final String operator) { } private String infixBinary(final BinaryExpr expr, final String operator) { - return writeWithBrackets(expr.getLeftOp()) + operator + writeWithBrackets( - expr.getRightOp()); + return writeWithBrackets(expr.getLeftOp()) + + operator + + writeWithBrackets(expr.getRightOp()); } private String infixMultiary(final MultiaryExpr expr, final String operator) { @@ -431,17 +334,27 @@ private String bvConcat(final BvConcatExpr expr) { } private String bvExtract(final BvExtractExpr e) { - return writeWithBrackets(e.getBitvec()) + "[" + write(e.getFrom()) + ":" + write( - e.getUntil()) + "]"; + return writeWithBrackets(e.getBitvec()) + + "[" + + write(e.getFrom()) + + ":" + + write(e.getUntil()) + + "]"; } private String bvZExt(final BvZExtExpr e) { - return "(" + writeWithBrackets(e.getOp()) + " zero_extend " + e.getExtendType().toString() + return "(" + + writeWithBrackets(e.getOp()) + + " zero_extend " + + e.getExtendType().toString() + ")"; } private String bvSExt(final BvSExtExpr e) { - return "(" + writeWithBrackets(e.getOp()) + " sign_extend " + e.getExtendType().toString() + return "(" + + writeWithBrackets(e.getOp()) + + " sign_extend " + + e.getExtendType().toString() + ")"; } @@ -450,8 +363,12 @@ private String arrayRead(final ArrayReadExpr e) { } private String arrayWrite(final ArrayWriteExpr e) { - return writeWithBrackets(e.getArray()) + "[" + write(e.getIndex()) + " <- " + write( - e.getElem()) + "]"; + return writeWithBrackets(e.getArray()) + + "[" + + write(e.getIndex()) + + " <- " + + write(e.getElem()) + + "]"; } private String ite(final IteExpr expr) { @@ -466,33 +383,40 @@ private String ite(final IteExpr expr) { } private String bvLit(final BvLitExpr expr) { - var value = Arrays.toString(expr.getValue()) - .replace("true", "1") - .replace("false", "0") - .replace("[", "") - .replace("]", "") - .replace(",", "") - .replace(" ", ""); + var value = + Arrays.toString(expr.getValue()) + .replace("true", "1") + .replace("false", "0") + .replace("[", "") + .replace("]", "") + .replace(",", "") + .replace(" ", ""); return expr.getType().getSize() + "'b" + value; } private String arrayLit(final ArrayLitExpr expr) { - return "[" + - expr.getElements().stream().map(e -> write(e.get1()) + " <- " + write(e.get2())) - .collect(Collectors.joining(", ")) + - "<" + expr.getType().getIndexType().toString() + ">default" + " <- " + write( - expr.getElseElem()) + - "]"; + return "[" + + expr.getElements().stream() + .map(e -> write(e.get1()) + " <- " + write(e.get2())) + .collect(Collectors.joining(", ")) + + "<" + + expr.getType().getIndexType().toString() + + ">default" + + " <- " + + write(expr.getElseElem()) + + "]"; } private String arrayInit(final ArrayInitExpr expr) { - return "[" + - expr.getElements().stream().map(e -> write(e.get1()) + " <- " + write(e.get2())) - .collect(Collectors.joining(", ")) + - "<" + expr.getType().getIndexType().toString() + ">default" + " <- " + write( - expr.getElseElem()) + - "]"; + return "[" + + expr.getElements().stream() + .map(e -> write(e.get1()) + " <- " + write(e.get2())) + .collect(Collectors.joining(", ")) + + "<" + + expr.getType().getIndexType().toString() + + ">default" + + " <- " + + write(expr.getElseElem()) + + "]"; } - } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtCreatorVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtCreatorVisitor.java index c24b9f7d5a..89b8a8daad 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtCreatorVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtCreatorVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,9 +24,9 @@ import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.dsl.DeclSymbol; import hu.bme.mit.theta.core.dsl.gen.CoreDslBaseVisitor; -import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.HavocStmtContext; import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AssignStmtContext; import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.AssumeStmtContext; +import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.HavocStmtContext; import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.Expr; @@ -44,8 +44,8 @@ public StmtCreatorVisitor(final Scope scope) { @Override public Stmt visitAssignStmt(final AssignStmtContext ctx) { - @SuppressWarnings("unchecked") final VarDecl lhs = (VarDecl) resolveVar(scope, - ctx.lhs.getText()); + @SuppressWarnings("unchecked") + final VarDecl lhs = (VarDecl) resolveVar(scope, ctx.lhs.getText()); final Expr expr = CoreDslHelper.createExpr(scope, ctx.value); final Expr value = TypeUtils.cast(expr, lhs.getType()); return Assign(lhs, value); @@ -67,9 +67,8 @@ public AssumeStmt visitAssumeStmt(final AssumeStmtContext ctx) { @Override public Stmt visitHavocStmt(final HavocStmtContext ctx) { - @SuppressWarnings("unchecked") final VarDecl lhs = (VarDecl) resolveVar(scope, - ctx.lhs.getText()); + @SuppressWarnings("unchecked") + final VarDecl lhs = (VarDecl) resolveVar(scope, ctx.lhs.getText()); return Havoc(lhs); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtWriter.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtWriter.java index 1d872c615e..81eb13068e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtWriter.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/StmtWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -51,7 +51,8 @@ public String visit(final AssignStmt stmt, fin } @Override - public String visit(MemoryAssignStmt stmt, Void param) { + public String visit( + MemoryAssignStmt stmt, Void param) { return stmt.getDeref() + " := " + writeExpr(stmt.getExpr()); } @@ -83,5 +84,4 @@ public String visit(LoopStmt stmt, Void param) { public String visit(IfStmt stmt, Void param) { throw new UnsupportedOperationException(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/TypeCreatorVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/TypeCreatorVisitor.java index 26364b2ae0..6581616c1b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/TypeCreatorVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/impl/TypeCreatorVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,9 +23,6 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; import static java.util.stream.Collectors.toList; -import java.util.Collections; -import java.util.List; - import hu.bme.mit.theta.core.dsl.gen.CoreDslBaseVisitor; import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.ArrayTypeContext; import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.BoolTypeContext; @@ -34,13 +31,14 @@ import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.RatTypeContext; import hu.bme.mit.theta.core.dsl.gen.CoreDslParser.TypeListContext; import hu.bme.mit.theta.core.type.Type; +import java.util.Collections; +import java.util.List; public final class TypeCreatorVisitor extends CoreDslBaseVisitor { private static final TypeCreatorVisitor INSTANCE = new TypeCreatorVisitor(); - private TypeCreatorVisitor() { - } + private TypeCreatorVisitor() {} public static TypeCreatorVisitor getInstance() { return INSTANCE; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/package-info.java index 4c330d5f17..2d6adef253 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/dsl/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,5 +17,4 @@ * This package contains the domain specific language (DSL) and the parser for expressions. Use * {@link hu.bme.mit.theta.core.dsl.CoreDslManager} as the entry point. */ - -package hu.bme.mit.theta.core.dsl; \ No newline at end of file +package hu.bme.mit.theta.core.dsl; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/BasicSubstitution.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/BasicSubstitution.java index e9abe1dd42..787d05bfbb 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/BasicSubstitution.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/BasicSubstitution.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,22 @@ */ package hu.bme.mit.theta.core.model; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -/** - * Basic, immutable implementation of a substitution. - */ +/** Basic, immutable implementation of a substitution. */ public final class BasicSubstitution implements Substitution { private static final int HASH_SEED = 2521; @@ -51,8 +48,8 @@ private BasicSubstitution(final Builder builder) { public Optional> eval(final Decl decl) { checkNotNull(decl); if (declToExpr.containsKey(decl)) { - @SuppressWarnings("unchecked") final Expr val = (Expr) declToExpr.get( - decl); + @SuppressWarnings("unchecked") + final Expr val = (Expr) declToExpr.get(decl); return Optional.of(val); } return Optional.empty(); @@ -66,8 +63,9 @@ public Collection> getDecls() { @Override public String toString() { return Utils.lispStringBuilder("Substitution") - .addAll(declToExpr.entrySet().stream() - .map(e -> e.getKey().getName() + " <- " + e.getValue())) + .addAll( + declToExpr.entrySet().stream() + .map(e -> e.getKey().getName() + " <- " + e.getValue())) .toString(); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/ImmutableValuation.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/ImmutableValuation.java index f75cb62fb8..8ce37c73c3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/ImmutableValuation.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/ImmutableValuation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.core.model; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableMap; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Collection; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Basic, immutable implementation of a valuation. The inner builder class can be used to create a * new instance. @@ -79,8 +78,8 @@ public Collection> getDecls() { @Override public Optional> eval(final Decl decl) { checkNotNull(decl); - @SuppressWarnings("unchecked") final LitExpr val = (LitExpr) declToExpr.get( - decl); + @SuppressWarnings("unchecked") + final LitExpr val = (LitExpr) declToExpr.get(decl); return Optional.ofNullable(val); } @@ -103,7 +102,7 @@ public static Builder builder() { return new Builder(); } - public final static class Builder { + public static final class Builder { private final ImmutableMap.Builder, LitExpr> builder; @@ -120,7 +119,5 @@ public Builder put(final Decl decl, final LitExpr value) { public ImmutableValuation build() { return new ImmutableValuation(this); } - } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutablePartitionedValuation.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutablePartitionedValuation.java index c7ae0bc8b7..d78b2d4776 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutablePartitionedValuation.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutablePartitionedValuation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,17 @@ */ package hu.bme.mit.theta.core.model; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; + import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -32,11 +36,6 @@ import java.util.Optional; import java.util.Set; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; - /** * Mutable implementation of a partitioned valuation. A partitioned valuation contains orthogonal * valuations, making it possible for a single declaration to have several valuations as per @@ -65,13 +64,12 @@ public int createPartition() { return partitions.size() - 1; } - public List, LitExpr>> getPartitions() { return Collections.unmodifiableList(partitions); } - public MutablePartitionedValuation put(final int id, final Decl decl, - final LitExpr value) { + public MutablePartitionedValuation put( + final int id, final Decl decl, final LitExpr value) { checkArgument(value.getType().equals(decl.getType()), "Type mismatch."); checkArgument(partitions.size() > id, "Index out of bounds"); partitions.get(id).put(decl, value); @@ -135,8 +133,8 @@ public Valuation getValuation(final int id) { public Optional> eval(final Decl decl) { checkNotNull(decl); for (Map, LitExpr> decls : partitions) { - @SuppressWarnings("unchecked") final LitExpr val = (LitExpr) decls.get( - decl); + @SuppressWarnings("unchecked") + final LitExpr val = (LitExpr) decls.get(decl); if (val != null) { return Optional.of(val); } @@ -146,8 +144,10 @@ public Optional> eval(final Decl toExpr() { - return SmartBoolExprs.And(getDecls().stream().map(e -> Eq(e.getRef(), eval(e).get())) - .collect(toImmutableList())); + return SmartBoolExprs.And( + getDecls().stream() + .map(e -> Eq(e.getRef(), eval(e).get())) + .collect(toImmutableList())); } @Override @@ -158,5 +158,4 @@ public Map, LitExpr> toMap() { } return Collections.unmodifiableMap(ret); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutableValuation.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutableValuation.java index d3e4fe4ca0..6760bf0f7c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutableValuation.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/MutableValuation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,22 +20,19 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; - import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Optional; -/** - * Mutable implementation of a valuation. - */ +/** Mutable implementation of a valuation. */ public final class MutableValuation extends Valuation { private final Map, LitExpr> declToExpr; @@ -84,15 +81,16 @@ public Collection> getDecls() { @Override public Optional> eval(final Decl decl) { checkNotNull(decl); - @SuppressWarnings("unchecked") final LitExpr val = (LitExpr) declToExpr.get( - decl); + @SuppressWarnings("unchecked") + final LitExpr val = (LitExpr) declToExpr.get(decl); return Optional.ofNullable(val); } @Override public Expr toExpr() { return SmartBoolExprs.And( - declToExpr.entrySet().stream().map(e -> Eq(e.getKey().getRef(), e.getValue())) + declToExpr.entrySet().stream() + .map(e -> Eq(e.getKey().getRef(), e.getValue())) .collect(toImmutableList())); } @@ -100,5 +98,4 @@ public Expr toExpr() { public Map, LitExpr> toMap() { return Collections.unmodifiableMap(declToExpr); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/NestedSubstitution.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/NestedSubstitution.java index 80af382935..990eb87cac 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/NestedSubstitution.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/NestedSubstitution.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,16 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import hu.bme.mit.theta.common.container.Containers; - -import java.util.Optional; -import java.util.Set; - import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; +import java.util.Collection; +import java.util.Optional; +import java.util.Set; /** * Class representing a nested substitution. If a declaration is not present in the actual @@ -42,8 +39,8 @@ private NestedSubstitution(final Substitution enclosingSubst, final Substitution this.subst = checkNotNull(subst); } - public static NestedSubstitution create(final Substitution enclosingSubst, - final Substitution subst) { + public static NestedSubstitution create( + final Substitution enclosingSubst, final Substitution subst) { return new NestedSubstitution(enclosingSubst, subst); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Substitution.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Substitution.java index d6264a6d73..2b1ae2aabf 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Substitution.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Substitution.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,14 @@ */ package hu.bme.mit.theta.core.model; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.anytype.RefExpr; +import java.util.Collection; +import java.util.Optional; -/** - * Interface for a substitution, which is a mapping from declarations to expressions. - */ +/** Interface for a substitution, which is a mapping from declarations to expressions. */ public interface Substitution { /** diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Valuation.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Valuation.java index 46b95dfb20..be125ea65f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Valuation.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/Valuation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.model; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; @@ -22,17 +24,12 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; - import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; - -/** - * Interface for a valuation, which is a mapping from declarations to literal expressions. - */ +/** Interface for a valuation, which is a mapping from declarations to literal expressions. */ public abstract class Valuation implements Substitution { private static final int HASH_SEED = 2141; @@ -97,10 +94,11 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder("val").aligned() + return Utils.lispStringBuilder("val") + .aligned() .addAll( - getDecls().stream().map(d -> String.format("(%s %s)", d.getName(), eval(d).get()))) + getDecls().stream() + .map(d -> String.format("(%s %s)", d.getName(), eval(d).get()))) .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/package-info.java index 005809d574..8abbf13208 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/model/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,5 +24,4 @@ * valuation. - {@link hu.bme.mit.theta.core.model.ImmutableValuation} implements an immutable * valuation. */ - -package hu.bme.mit.theta.core.model; \ No newline at end of file +package hu.bme.mit.theta.core.model; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreInterpreter.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreInterpreter.java index 82ee1ccebf..4f08efe2db 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreInterpreter.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreInterpreter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,15 +24,7 @@ import static hu.bme.mit.theta.core.type.anytype.Exprs.Ref; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import java.math.BigInteger; -import java.util.List; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.UnaryOperator; - import com.google.common.primitives.Ints; - import hu.bme.mit.theta.common.TernaryOperator; import hu.bme.mit.theta.common.parser.SExpr; import hu.bme.mit.theta.common.parser.SExpr.SAtom; @@ -74,10 +66,16 @@ import hu.bme.mit.theta.core.type.booltype.XorExpr; import hu.bme.mit.theta.core.type.functype.FuncAppExpr; import hu.bme.mit.theta.core.type.functype.FuncType; -import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.inttype.IntModExpr; import hu.bme.mit.theta.core.type.inttype.IntRemExpr; +import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.math.BigInteger; +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.UnaryOperator; public class CoreInterpreter { @@ -155,8 +153,8 @@ public void defineExpr(final String symbol, final Expr expr) { env.define(symbol, expr); } - public void defineExpr(final String symbol, - final BiFunction, Expr> function) { + public void defineExpr( + final String symbol, final BiFunction, Expr> function) { final Function, Expr> interpretation = sexprs -> function.apply(env, sexprs); env.define(symbol, interpretation); } @@ -235,7 +233,8 @@ private Object evalList(final SList slist) { if (head.isAtom()) { final String symbol = head.asAtom().getAtom(); final Object object = env.eval(symbol); - @SuppressWarnings("unchecked") final Function, ?> interpretation = (Function, ?>) object; + @SuppressWarnings("unchecked") + final Function, ?> interpretation = (Function, ?>) object; final Object value = interpretation.apply(tail); return value; } else if (head.isList()) { @@ -358,5 +357,4 @@ private BiFunction, Stmt> createHavoc() { return HavocStmt.of(varDecl); }; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreParser.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreParser.java index d5114e090b..0a581a471a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreParser.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/CoreParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,8 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.io.Reader; - import hu.bme.mit.theta.common.parser.LispLexer; import hu.bme.mit.theta.common.parser.LispParser; import hu.bme.mit.theta.common.parser.SExpr; @@ -26,6 +24,7 @@ import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; +import java.io.Reader; public final class CoreParser { @@ -64,5 +63,4 @@ public Stmt stmt() { final Stmt stmt = interpreter.stmt(sexpr); return stmt; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/Env.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/Env.java index 10e1b3474c..d2aaf93ee5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/Env.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/parser/Env.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,13 +19,11 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; - import java.util.Map; import java.util.function.Function; -import hu.bme.mit.theta.common.Utils; - public final class Env { private Frame currentFrame; @@ -61,8 +59,8 @@ public Object eval(final String symbol) { return value; } - public Object compute(final String symbol, - final Function mapping) { + public Object compute( + final String symbol, final Function mapping) { checkNotNull(symbol); checkNotNull(mapping); Object value = currentFrame.eval(symbol); @@ -85,7 +83,8 @@ private Frame(final Frame parent) { } public void define(final String symbol, final Object value) { - checkArgument(!symbolToValue.containsKey(symbol), + checkArgument( + !symbolToValue.containsKey(symbol), "Symbol \"" + symbol + "\" is already defined"); symbolToValue.put(symbol, value); } @@ -103,11 +102,12 @@ public Object eval(final String symbol) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).aligned().addAll( + return Utils.lispStringBuilder(getClass().getSimpleName()) + .aligned() + .addAll( symbolToValue.entrySet().stream() .map(e -> String.format("(%s %s)", e.getKey(), e.getValue()))) .toString(); } } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssignStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssignStmt.java index c3cd378673..a1ca15e0a7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssignStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssignStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.stmt; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - /** * Assignment statement of the form VARIABLE := EXPRESSION. The statement updates the VARIABLE with * the result of EXPRESSION. @@ -44,14 +44,15 @@ private AssignStmt(final VarDecl varDecl, final Expr expr) { this.expr = checkNotNull(expr); } - public static AssignStmt of(final VarDecl lhs, - final Expr rhs) { + public static AssignStmt of( + final VarDecl lhs, final Expr rhs) { return new AssignStmt<>(lhs, rhs); } - public static AssignStmt create(final VarDecl lhs, - final Expr rhs) { - @SuppressWarnings("unchecked") final VarDecl newLhs = (VarDecl) lhs; + public static AssignStmt create( + final VarDecl lhs, final Expr rhs) { + @SuppressWarnings("unchecked") + final VarDecl newLhs = (VarDecl) lhs; final Expr newRhs = cast(rhs, newLhs.getType()); return AssignStmt.of(newLhs, newRhs); } @@ -87,8 +88,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final AssignStmt that = (AssignStmt) obj; - return this.getVarDecl().equals(that.getVarDecl()) && this.getExpr() - .equals(that.getExpr()); + return this.getVarDecl().equals(that.getVarDecl()) + && this.getExpr().equals(that.getExpr()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssumeStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssumeStmt.java index 06c6b28651..0a6c4e5d7f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssumeStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/AssumeStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.stmt; -import hu.bme.mit.theta.common.Utils; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; - import static com.google.common.base.Preconditions.checkNotNull; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import hu.bme.mit.theta.common.Utils; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; + /** * Assume statement of the form [EXPRESSION], where EXPRESSION is a Boolean {@link Expr}. The * statement is a guard that can only be passed if EXPRESSION evaluates to true. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/HavocStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/HavocStmt.java index acf109f575..106e9e0496 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/HavocStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/HavocStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.core.stmt; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Type; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Havoc statement of the form havoc VARIABLE, which performs a non-deterministic assignment to * VARIABLE. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/IfStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/IfStmt.java index 76ad1f3017..1ae942ce28 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/IfStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/IfStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.core.stmt; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static com.google.common.base.Preconditions.checkNotNull; - public class IfStmt implements Stmt { private final Expr cond; @@ -82,9 +82,9 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IfStmt that = (IfStmt) obj; - return this.cond.equals(that.getCond()) && - this.then.equals(that.getThen()) && - this.elze.equals(that.getElze()); + return this.cond.equals(that.getCond()) + && this.then.equals(that.getThen()) + && this.elze.equals(that.getElze()); } else { return false; } @@ -94,5 +94,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder(STMT_LABEL).add(cond).add(then).add(elze).toString(); } - -} \ No newline at end of file +} diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/LoopStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/LoopStmt.java index 72aad17ea4..398f15b928 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/LoopStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/LoopStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -32,16 +32,22 @@ public final class LoopStmt implements Stmt { private volatile int hashCode = 0; - private LoopStmt(final Stmt stmt, final VarDecl loopVariable, final Expr from, - final Expr to) { + private LoopStmt( + final Stmt stmt, + final VarDecl loopVariable, + final Expr from, + final Expr to) { this.stmt = stmt; this.loopVariable = loopVariable; this.from = from; this.to = to; } - public static LoopStmt of(final Stmt stmt, final VarDecl loopVariable, - final Expr from, final Expr to) { + public static LoopStmt of( + final Stmt stmt, + final VarDecl loopVariable, + final Expr from, + final Expr to) { return new LoopStmt(stmt, loopVariable, from, to); } @@ -71,8 +77,12 @@ public int hashCode() { int result = hashCode; if (result == 0) { result = HASH_SEED; - result = 37 * result + stmt.hashCode() + loopVariable.hashCode() + from.hashCode() - + to.hashCode(); + result = + 37 * result + + stmt.hashCode() + + loopVariable.hashCode() + + from.hashCode() + + to.hashCode(); hashCode = result; } return result; @@ -96,7 +106,7 @@ public boolean equals(final Object obj) { @Override public String toString() { return Utils.lispStringBuilder(STMT_LABEL) - .add(loopVariable + " from " + from + " to " + to + " " + stmt).toString(); + .add(loopVariable + " from " + from + " to " + to + " " + stmt) + .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/MemoryAssignStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/MemoryAssignStmt.java index 333148d750..ddbcfd8b88 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/MemoryAssignStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/MemoryAssignStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,43 +15,48 @@ */ package hu.bme.mit.theta.core.stmt; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Objects; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.anytype.Dereference; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Assignment statement of the form *(DEREF_EXPRESSION) := EXPRESSION. The statement updates the * value pointed to by DEREF_EXPRESSION with the result of EXPRESSION. * * @param */ -public final class MemoryAssignStmt implements Stmt { +public final class MemoryAssignStmt< + PtrType extends Type, OffsetType extends Type, DeclType extends Type> + implements Stmt { private static final String STMT_LABEL = "memassign"; private final Dereference deref; private final Expr expr; - private MemoryAssignStmt(final Dereference deref, final Expr expr) { + private MemoryAssignStmt( + final Dereference deref, final Expr expr) { this.deref = checkNotNull(deref); this.expr = checkNotNull(expr); } - public static MemoryAssignStmt of( - final Dereference deref, - final Expr expr) { + public static + MemoryAssignStmt of( + final Dereference deref, + final Expr expr) { return new MemoryAssignStmt<>(deref, expr); } @SuppressWarnings("unchecked") - public static MemoryAssignStmt create( - final Dereference deref, - final Expr expr) { - final Dereference typedDeref = (Dereference) deref; + public static + MemoryAssignStmt create( + final Dereference deref, final Expr expr) { + final Dereference typedDeref = + (Dereference) deref; final Expr typedExpr = expr; return MemoryAssignStmt.of(typedDeref, typedExpr); } @@ -79,8 +84,8 @@ public boolean equals(final Object obj) { if (this == obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { - return Objects.equal(deref, ((MemoryAssignStmt) obj).deref) && - Objects.equal(expr, ((MemoryAssignStmt) obj).expr); + return Objects.equal(deref, ((MemoryAssignStmt) obj).deref) + && Objects.equal(expr, ((MemoryAssignStmt) obj).expr); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/NonDetStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/NonDetStmt.java index f96d543789..a6d074665f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/NonDetStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/NonDetStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; - import java.util.List; public final class NonDetStmt implements Stmt { @@ -77,5 +76,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder(STMT_LABEL).addAll(stmts).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/OrtStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/OrtStmt.java index dfb23447ab..2e79eec0fd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/OrtStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/OrtStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; - import java.util.List; public final class OrtStmt implements Stmt { @@ -77,5 +76,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder(STMT_LABEL).addAll(stmts).toString(); } - -} \ No newline at end of file +} diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SequenceStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SequenceStmt.java index 7f4b7a4ae1..22fc264288 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SequenceStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SequenceStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; - import java.util.List; public final class SequenceStmt implements Stmt { @@ -76,5 +75,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder().addAll(stmts).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SkipStmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SkipStmt.java index 9ad8fdd44d..0336c5310f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SkipStmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/SkipStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,13 @@ */ package hu.bme.mit.theta.core.stmt; -/** - * A skip statement is a placeholder that does not perform any operation. - */ +/** A skip statement is a placeholder that does not perform any operation. */ public final class SkipStmt implements Stmt { private static final int HASH_CODE = 1310147; private static final String STMT_LABEL = "skip"; - private SkipStmt() { - } + private SkipStmt() {} private static class LazyHolder { @@ -60,5 +57,4 @@ public boolean equals(final Object obj) { public String toString() { return STMT_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmt.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmt.java index 8c2e819ab3..3c396ebd1b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmt.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ public interface Stmt { R accept(StmtVisitor visitor, P param); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/StmtVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/StmtVisitor.java index 81ec3f4deb..ce9ca2185d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/StmtVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/StmtVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,7 +25,8 @@ public interface StmtVisitor { R visit(AssignStmt stmt, P param); - R visit(MemoryAssignStmt stmt, P param); + R visit( + MemoryAssignStmt stmt, P param); R visit(HavocStmt stmt, P param); @@ -38,5 +39,4 @@ public interface StmtVisitor { R visit(LoopStmt stmt, P param); R visit(IfStmt stmt, P param); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmts.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmts.java index 1a07a5b69a..818cb605db 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmts.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/Stmts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,6 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.anytype.Dereference; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.List; /** @@ -30,8 +29,7 @@ */ public final class Stmts { - private Stmts() { - } + private Stmts() {} public static SkipStmt Skip() { return SkipStmt.getInstance(); @@ -45,7 +43,9 @@ public static AssignStmt Assign(final VarDecl lhs, final return AssignStmt.of(lhs, rhs); } - public static

MemoryAssignStmt MemoryAssign(final Dereference deref, final Expr expr) { + public static

+ MemoryAssignStmt MemoryAssign( + final Dereference deref, final Expr expr) { return MemoryAssignStmt.of(deref, expr); } @@ -60,5 +60,4 @@ public static SequenceStmt SequenceStmt(final List stmts) { public static NonDetStmt NonDetStmt(final List stmts) { return NonDetStmt.of(stmts); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/package-info.java index 56a508476a..cec1737dad 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/stmt/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ * usually package private, use the factory class {@link hu.bme.mit.theta.core.stmt.Stmts} to * instantiate them. */ - -package hu.bme.mit.theta.core.stmt; \ No newline at end of file +package hu.bme.mit.theta.core.stmt; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/BinaryExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/BinaryExpr.java index 9de08267f3..8a0ca0fa2e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/BinaryExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/BinaryExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -public abstract class BinaryExpr implements - Expr { +public abstract class BinaryExpr + implements Expr { private final Expr leftOp; private final Expr rightOp; @@ -79,11 +78,15 @@ public final int hashCode() { @Override public final String toString() { - return Utils.lispStringBuilder(getOperatorLabel()).body().add(leftOp).add(rightOp).toString(); + return Utils.lispStringBuilder(getOperatorLabel()) + .body() + .add(leftOp) + .add(rightOp) + .toString(); } - public abstract BinaryExpr with(final Expr leftOp, - final Expr rightOp); + public abstract BinaryExpr with( + final Expr leftOp, final Expr rightOp); public abstract BinaryExpr withLeftOp(final Expr leftOp); @@ -92,5 +95,4 @@ public abstract BinaryExpr with(final Expr leftOp, protected abstract int getHashSeed(); public abstract String getOperatorLabel(); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/DomainSize.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/DomainSize.java index 8bc2d25a76..aff9585e46 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/DomainSize.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/DomainSize.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,12 @@ */ package hu.bme.mit.theta.core.type; -import com.google.common.base.Objects; +import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.base.Objects; import java.math.BigInteger; import java.util.function.BinaryOperator; -import static com.google.common.base.Preconditions.checkArgument; - public class DomainSize { public static final DomainSize INFINITY = new DomainSize(BigInteger.valueOf(-1)); @@ -43,9 +42,9 @@ public static DomainSize of(long val) { return of(BigInteger.valueOf(val)); } - private static DomainSize infiniteForAnyInfiniteApplyElse(DomainSize left, DomainSize right, BinaryOperator operator) { - if (left.isInfinite() || right.isInfinite()) - return INFINITY; + private static DomainSize infiniteForAnyInfiniteApplyElse( + DomainSize left, DomainSize right, BinaryOperator operator) { + if (left.isInfinite() || right.isInfinite()) return INFINITY; return of(operator.apply(left.finiteSize, right.finiteSize)); } @@ -62,8 +61,7 @@ public static DomainSize multiply(DomainSize left, DomainSize right) { * parameter is infinite or exponent is too large ( = can't fit into an integer) */ public static DomainSize pow(DomainSize base, DomainSize exponent) { - if (base.isInfinite() || exponent.isInfinite()) - return INFINITY; + if (base.isInfinite() || exponent.isInfinite()) return INFINITY; int iExp; try { iExp = exponent.finiteSize.intValueExact(); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Expr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Expr.java index bbcae821fe..046581d89e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Expr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Expr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,11 +17,10 @@ import static com.google.common.collect.ImmutableList.toImmutableList; +import hu.bme.mit.theta.core.model.Valuation; import java.util.List; import java.util.function.Function; -import hu.bme.mit.theta.core.model.Valuation; - public interface Expr { int getArity(); @@ -46,5 +45,4 @@ default boolean isInvalid() { default Expr map(final Function, ? extends Expr> function) { return withOps(getOps().stream().map(function::apply).collect(toImmutableList())); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/LitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/LitExpr.java index bc2c6a3250..153f01977c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/LitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/LitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,4 @@ */ package hu.bme.mit.theta.core.type; -public interface LitExpr extends Expr { - -} +public interface LitExpr extends Expr {} diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/MultiaryExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/MultiaryExpr.java index b5c9c56e26..d30e2c176e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/MultiaryExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/MultiaryExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; - -public abstract class MultiaryExpr implements - Expr { +public abstract class MultiaryExpr + implements Expr { private final List> ops; @@ -53,8 +52,8 @@ public MultiaryExpr withOps(final List> ops) return with(ImmutableList.of()); } else { final OpType opType = getOps().get(0).getType(); - final List> newOps = ops.stream().map(op -> TypeUtils.cast(op, opType)) - .collect(toImmutableList()); + final List> newOps = + ops.stream().map(op -> TypeUtils.cast(op, opType)).collect(toImmutableList()); return with(newOps); } } @@ -80,5 +79,4 @@ public final String toString() { protected abstract int getHashSeed(); public abstract String getOperatorLabel(); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/NullaryExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/NullaryExpr.java index 79fa56b7bf..e1d686b6a8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/NullaryExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/NullaryExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,9 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; - import com.google.common.collect.ImmutableList; +import java.util.List; public abstract class NullaryExpr implements Expr { @@ -40,5 +39,4 @@ public final NullaryExpr withOps(final List> ops) { public final int getArity() { return 0; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Type.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Type.java index 38def58ad8..b3b5934fd8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Type.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/Type.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/UnaryExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/UnaryExpr.java index 9a82743233..0d32e7e1f7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/UnaryExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/UnaryExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -public abstract class UnaryExpr implements - Expr { +public abstract class UnaryExpr + implements Expr { private final Expr op; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AbstractExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AbstractExprs.java index 93c4ec0ed8..e3aa3d2338 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AbstractExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AbstractExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,10 +17,7 @@ import static com.google.common.base.Preconditions.checkArgument; -import java.util.List; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.common.Try; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Utils; @@ -29,18 +26,18 @@ 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.booltype.BoolType; +import java.util.List; public final class AbstractExprs { - private AbstractExprs() { - } + private AbstractExprs() {} /* * General */ - public static IteExpr Ite(final Expr cond, final Expr then, - final Expr elze) { + public static IteExpr Ite( + final Expr cond, final Expr then, final Expr elze) { final Tuple2, Expr> newOps = unify(then, elze); final Expr newThen = newOps.get1(); final Expr newElse = newOps.get2(); @@ -59,8 +56,8 @@ public static > AddExpr Add(final Iterable> AddExpr combineAdd(final Expr head, - final List> tail) { + private static > AddExpr combineAdd( + final Expr head, final List> tail) { if (tail.isEmpty()) { final Expr newOp = bind(head); final List> newOps = getAddOps(newOp); @@ -77,8 +74,8 @@ private static > AddExpr combineAdd(final Expr head, final T type = newLeftOp.getType(); final List> newLeftOps = getAddOps(newLeftOp); - final List> newOps = ImmutableList.>builder().addAll(newLeftOps) - .add(newRightOp).build(); + final List> newOps = + ImmutableList.>builder().addAll(newLeftOps).add(newRightOp).build(); final AddExpr newAddExpr = type.Add(newOps); return combineAdd(newAddExpr, newTail); } @@ -93,8 +90,8 @@ private static > List> getAddOps(final Expr exp } } - public static > SubExpr Sub(final Expr leftOp, - final Expr rightOp) { + public static > SubExpr Sub( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -127,8 +124,8 @@ public static > MulExpr Mul( return combineMul(head, tail); } - private static > MulExpr combineMul(final Expr head, - final List> tail) { + private static > MulExpr combineMul( + final Expr head, final List> tail) { if (tail.isEmpty()) { final Expr newOp = bind(head); final List> newOps = getMulOps(newOp); @@ -145,8 +142,8 @@ private static > MulExpr combineMul(final Expr final T type = newLeftOp.getType(); final List> newLeftOps = getMulOps(newLeftOp); - final List> newOps = ImmutableList.>builder().addAll(newLeftOps) - .add(newRightOp).build(); + final List> newOps = + ImmutableList.>builder().addAll(newLeftOps).add(newRightOp).build(); final MulExpr newMulExpr = type.Mul(newOps); return combineMul(newMulExpr, newTail); } @@ -161,8 +158,8 @@ private static > List> getMulOps(final Expr< } } - public static > DivExpr Div(final Expr leftOp, - final Expr rightOp) { + public static > DivExpr Div( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -174,8 +171,8 @@ public static > DivExpr Div(final Expr leftOp, * Divisible */ - public static > ModExpr Mod(final Expr leftOp, - final Expr rightOp) { + public static > ModExpr Mod( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -183,8 +180,8 @@ public static > ModExpr Mod(final Expr leftOp, return type.Mod(newLeftOp, newRightOp); } - public static > RemExpr Rem(final Expr leftOp, - final Expr rightOp) { + public static > RemExpr Rem( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -196,8 +193,8 @@ public static > RemExpr Rem(final Expr leftOp, * Equational */ - public static > EqExpr Eq(final Expr leftOp, - final Expr rightOp) { + public static > EqExpr Eq( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -205,8 +202,8 @@ public static > EqExpr Eq(final Expr leftOp, return type.Eq(newLeftOp, newRightOp); } - public static > NeqExpr Neq(final Expr leftOp, - final Expr rightOp) { + public static > NeqExpr Neq( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -226,8 +223,8 @@ public static > LtExpr Lt(final Expr leftOp, final Ex return type.Lt(newLeftOp, newRightOp); } - public static > LeqExpr Leq(final Expr leftOp, - final Expr rightOp) { + public static > LeqExpr Leq( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -243,8 +240,8 @@ public static > GtExpr Gt(final Expr leftOp, final Ex return type.Gt(newLeftOp, newRightOp); } - public static > GeqExpr Geq(final Expr leftOp, - final Expr rightOp) { + public static > GeqExpr Geq( + final Expr leftOp, final Expr rightOp) { final Tuple2, Expr> newOps = unify(leftOp, rightOp); final Expr newLeftOp = newOps.get1(); final Expr newRightOp = newOps.get2(); @@ -256,13 +253,13 @@ public static > GeqExpr Geq(final Expr leftOp, * Convenience methods */ - public static > AddExpr Add(final Expr leftOp, - final Expr rightOp) { + public static > AddExpr Add( + final Expr leftOp, final Expr rightOp) { return Add(ImmutableList.of(leftOp, rightOp)); } - public static > MulExpr Mul(final Expr leftOp, - final Expr rightOp) { + public static > MulExpr Mul( + final Expr leftOp, final Expr rightOp) { return Mul(ImmutableList.of(leftOp, rightOp)); } @@ -270,19 +267,22 @@ public static > MulExpr Mul(final Expr leftOp, * Helper methods */ - private static > Tuple2, Expr> unify( - final Expr expr1, final Expr expr2) { + private static > + Tuple2, Expr> unify(final Expr expr1, final Expr expr2) { final T1 type1 = expr1.getType(); final T2 type2 = expr2.getType(); if (expr1.getType().equals(expr2.getType())) { - @SuppressWarnings("unchecked") final Expr t1Expr2 = (Expr) expr2; + @SuppressWarnings("unchecked") + final Expr t1Expr2 = (Expr) expr2; return bind(expr1, t1Expr2); } if (type1 instanceof Castable) { - @SuppressWarnings("unchecked") final C cType1 = (C) type1; - @SuppressWarnings("unchecked") final Expr cExpr1 = (Expr) expr1; + @SuppressWarnings("unchecked") + final C cType1 = (C) type1; + @SuppressWarnings("unchecked") + final Expr cExpr1 = (Expr) expr1; final Try> tryToCast = Try.attempt(() -> cType1.Cast(cExpr1, type2)); if (tryToCast.isSuccess()) { final Expr t2Expr1 = tryToCast.asSuccess().getValue(); @@ -291,8 +291,10 @@ private static cExpr2 = (Expr) expr2; + @SuppressWarnings("unchecked") + final C cType2 = (C) type2; + @SuppressWarnings("unchecked") + final Expr cExpr2 = (Expr) expr2; final Try> tryToCast = Try.attempt(() -> cType2.Cast(cExpr2, type1)); if (tryToCast.isSuccess()) { final Expr t1Expr2 = tryToCast.asSuccess().getValue(); @@ -305,16 +307,17 @@ private static Expr bind(final Expr expr) { - @SuppressWarnings("unchecked") final Expr trExpr = (Expr) expr; + @SuppressWarnings("unchecked") + final Expr trExpr = (Expr) expr; return trExpr; } private static Tuple2, Expr> bind( - final Expr expr1, - final Expr expr2) { - @SuppressWarnings("unchecked") final Expr trExpr1 = (Expr) expr1; - @SuppressWarnings("unchecked") final Expr trExpr2 = (Expr) expr2; + final Expr expr1, final Expr expr2) { + @SuppressWarnings("unchecked") + final Expr trExpr1 = (Expr) expr1; + @SuppressWarnings("unchecked") + final Expr trExpr2 = (Expr) expr2; return Tuple2.of(trExpr1, trExpr2); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AddExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AddExpr.java index bafb9c4aff..56e801acff 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AddExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/AddExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,13 +19,12 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import java.util.List; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.MultiaryExpr; +import java.util.List; -public abstract class AddExpr> extends - MultiaryExpr { +public abstract class AddExpr> + extends MultiaryExpr { protected AddExpr(final Iterable> ops) { super(ops); @@ -34,8 +33,8 @@ protected AddExpr(final Iterable> ops) { public static > AddExpr create2( final List> ops) { checkArgument(!ops.isEmpty()); - @SuppressWarnings("unchecked") final ExprType type = (ExprType) ops.get(0).getType(); + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) ops.get(0).getType(); return type.Add(ops.stream().map(op -> cast(op, type)).collect(toImmutableList())); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Additive.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Additive.java index eaa8206c97..0035f620f7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Additive.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Additive.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,5 +27,4 @@ public interface Additive> extends Type { PosExpr Pos(Expr op); NegExpr Neg(Expr op); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/CastExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/CastExpr.java index d5f0a2acf5..65ec3fb7d7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/CastExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/CastExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,5 +25,4 @@ public abstract class CastExpr, TargetTy public CastExpr(final Expr op) { super(op); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Castable.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Castable.java index f7bf393126..73841e3762 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Castable.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Castable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,5 +21,4 @@ public interface Castable> extends Type { Expr Cast(Expr op, final TargetType type); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/DivExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/DivExpr.java index e70c1d3c91..348ee7d2dd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/DivExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/DivExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,8 +20,8 @@ import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -public abstract class DivExpr> extends - BinaryExpr { +public abstract class DivExpr> + extends BinaryExpr { protected DivExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); @@ -29,10 +29,10 @@ protected DivExpr(final Expr leftOp, final Expr rightOp) { public static > DivExpr create2( final Expr leftOp, final Expr rightOp) { - @SuppressWarnings("unchecked") final ExprType type = (ExprType) leftOp.getType(); + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Div(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Divisible.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Divisible.java index 9ee26b27fe..7eeaf458cc 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Divisible.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Divisible.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/EqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/EqExpr.java index 535a9fe3b1..d2629acd9d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/EqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/EqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,19 +21,19 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -public abstract class EqExpr> extends - BinaryExpr { +public abstract class EqExpr> + extends BinaryExpr { protected EqExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > EqExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final OpType type = (OpType) leftOp.getType(); + public static > EqExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final OpType type = (OpType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Eq(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Equational.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Equational.java index 8392f5f40c..0fa1b66b59 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Equational.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Equational.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,5 +23,4 @@ public interface Equational> extends Type { EqExpr Eq(Expr leftOp, Expr rightOp); NeqExpr Neq(Expr leftOp, Expr rightOp); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GeqExpr.java index b8c28da9c7..b9f16e3edd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,12 +27,12 @@ protected GeqExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > GeqExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final OpType type = (OpType) leftOp.getType(); + public static > GeqExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final OpType type = (OpType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Geq(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GtExpr.java index 74df7fb3a0..856205d2a6 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/GtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,12 +27,12 @@ protected GtExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > GtExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final OpType type = (OpType) leftOp.getType(); + public static > GtExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final OpType type = (OpType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Gt(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LeqExpr.java index 0fa4acc0eb..f59627f12a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,12 +27,12 @@ protected LeqExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > LeqExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final OpType type = (OpType) leftOp.getType(); + public static > LeqExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final OpType type = (OpType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Leq(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LtExpr.java index 9983afe1f6..338f192286 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/LtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,12 +27,12 @@ protected LtExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > LtExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final OpType type = (OpType) leftOp.getType(); + public static > LtExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final OpType type = (OpType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Lt(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/ModExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/ModExpr.java index 538ecb582e..7906c9af04 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/ModExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/ModExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,21 +15,22 @@ */ package hu.bme.mit.theta.core.type.abstracttype; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - -public abstract class ModExpr> extends - BinaryExpr { +public abstract class ModExpr> + extends BinaryExpr { protected ModExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > ModExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final ExprType type = (ExprType) leftOp.getType(); + public static > ModExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Mod(newLeftOp, newRightOp); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/MulExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/MulExpr.java index ab1b302fdf..5197c1f81a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/MulExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/MulExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,13 +19,12 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import java.util.List; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.MultiaryExpr; +import java.util.List; -public abstract class MulExpr> extends - MultiaryExpr { +public abstract class MulExpr> + extends MultiaryExpr { protected MulExpr(final Iterable> ops) { super(ops); @@ -34,8 +33,8 @@ protected MulExpr(final Iterable> ops) { public static > MulExpr create2( final List> ops) { checkArgument(!ops.isEmpty()); - @SuppressWarnings("unchecked") final T type = (T) ops.get(0).getType(); + @SuppressWarnings("unchecked") + final T type = (T) ops.get(0).getType(); return type.Mul(ops.stream().map(op -> cast(op, type)).collect(toImmutableList())); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Multiplicative.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Multiplicative.java index 4c1f638726..0f708ead4a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Multiplicative.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Multiplicative.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,5 +23,4 @@ public interface Multiplicative> exten MulExpr Mul(Iterable> ops); DivExpr Div(Expr leftOp, Expr rightOp); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NegExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NegExpr.java index 117cbc36d0..0750164827 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NegExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NegExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,17 +20,17 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; -public abstract class NegExpr> extends - UnaryExpr { +public abstract class NegExpr> + extends UnaryExpr { protected NegExpr(final Expr op) { super(op); } public static > NegExpr create2(final Expr op) { - @SuppressWarnings("unchecked") final ExprType type = (ExprType) op.getType(); + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) op.getType(); final Expr newOp = cast(op, type); return type.Neg(newOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NeqExpr.java index 73cac58441..254ae454d8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/NeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,19 +21,19 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -public abstract class NeqExpr> extends - BinaryExpr { +public abstract class NeqExpr> + extends BinaryExpr { protected NeqExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > NeqExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final OpType type = (OpType) leftOp.getType(); + public static > NeqExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final OpType type = (OpType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Neq(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Ordered.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Ordered.java index a631fe06be..a7b92e743d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Ordered.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/Ordered.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,5 +27,4 @@ public interface Ordered> extends Type { GtExpr Gt(Expr leftOp, Expr rightOp); GeqExpr Geq(Expr leftOp, Expr rightOp); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/PosExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/PosExpr.java index 6f394c49fb..7ea1cfc0e2 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/PosExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/PosExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,22 +15,22 @@ */ package hu.bme.mit.theta.core.type.abstracttype; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - -public abstract class PosExpr> extends - UnaryExpr { +public abstract class PosExpr> + extends UnaryExpr { protected PosExpr(final Expr op) { super(op); } public static > PosExpr create2(final Expr op) { - @SuppressWarnings("unchecked") final ExprType type = (ExprType) op.getType(); + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) op.getType(); final Expr newOp = cast(op, type); return type.Pos(newOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/RemExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/RemExpr.java index 3836b4239c..b93e4864e4 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/RemExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/RemExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,21 +15,22 @@ */ package hu.bme.mit.theta.core.type.abstracttype; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - -public abstract class RemExpr> extends - BinaryExpr { +public abstract class RemExpr> + extends BinaryExpr { protected RemExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > RemExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final ExprType type = (ExprType) leftOp.getType(); + public static > RemExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Rem(newLeftOp, newRightOp); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/SubExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/SubExpr.java index 497ef4aaf8..a263048118 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/SubExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/SubExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,19 +20,19 @@ import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -public abstract class SubExpr> extends - BinaryExpr { +public abstract class SubExpr> + extends BinaryExpr { protected SubExpr(final Expr leftOp, final Expr rightOp) { super(leftOp, rightOp); } - public static > SubExpr create2(final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final ExprType type = (ExprType) leftOp.getType(); + public static > SubExpr create2( + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final ExprType type = (ExprType) leftOp.getType(); final Expr newLeftOp = cast(leftOp, type); final Expr newRightOp = cast(rightOp, type); return type.Sub(newLeftOp, newRightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/package-info.java index 52ae3cd945..506f8dc56f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/abstracttype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -14,24 +14,23 @@ * limitations under the License. */ /** - * Expressions that work with multiple types. Use - * {@link hu.bme.mit.theta.core.type.abstracttype.AbstractExprs} to create them. Note that these are + * Expressions that work with multiple types. Use {@link + * hu.bme.mit.theta.core.type.abstracttype.AbstractExprs} to create them. Note that these are * abstract classes, and the corresponding expression for a given type will be created (e.g., * integer addition). - *

- * Arithmetic: - {@link hu.bme.mit.theta.core.type.abstracttype.AddExpr}: addition - - * {@link hu.bme.mit.theta.core.type.abstracttype.DivExpr}: division - - * {@link hu.bme.mit.theta.core.type.abstracttype.MulExpr}: multiplication - - * {@link hu.bme.mit.theta.core.type.abstracttype.SubExpr}: subtraction - *

- * Comparison: - {@link hu.bme.mit.theta.core.type.abstracttype.EqExpr}: equal - - * {@link hu.bme.mit.theta.core.type.abstracttype.GeqExpr}: greater or equal - - * {@link hu.bme.mit.theta.core.type.abstracttype.GtExpr}: greater - - * {@link hu.bme.mit.theta.core.type.abstracttype.LeqExpr}: less or equal - - * {@link hu.bme.mit.theta.core.type.abstracttype.LtExpr}: less - - * {@link hu.bme.mit.theta.core.type.abstracttype.NeqExpr}: not equal - *

- * Other - {@link hu.bme.mit.theta.core.type.abstracttype.CastExpr}: cast + * + *

Arithmetic: - {@link hu.bme.mit.theta.core.type.abstracttype.AddExpr}: addition - {@link + * hu.bme.mit.theta.core.type.abstracttype.DivExpr}: division - {@link + * hu.bme.mit.theta.core.type.abstracttype.MulExpr}: multiplication - {@link + * hu.bme.mit.theta.core.type.abstracttype.SubExpr}: subtraction + * + *

Comparison: - {@link hu.bme.mit.theta.core.type.abstracttype.EqExpr}: equal - {@link + * hu.bme.mit.theta.core.type.abstracttype.GeqExpr}: greater or equal - {@link + * hu.bme.mit.theta.core.type.abstracttype.GtExpr}: greater - {@link + * hu.bme.mit.theta.core.type.abstracttype.LeqExpr}: less or equal - {@link + * hu.bme.mit.theta.core.type.abstracttype.LtExpr}: less - {@link + * hu.bme.mit.theta.core.type.abstracttype.NeqExpr}: not equal + * + *

Other - {@link hu.bme.mit.theta.core.type.abstracttype.CastExpr}: cast */ - -package hu.bme.mit.theta.core.type.abstracttype; \ No newline at end of file +package hu.bme.mit.theta.core.type.abstracttype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Dereference.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Dereference.java index 1622683564..57ab22b884 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Dereference.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Dereference.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,22 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.anytype; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.inttype.IntType; - import java.util.List; import java.util.Objects; import java.util.Optional; -import static com.google.common.base.Preconditions.checkState; - public final class Dereference implements Expr { private static final String OPERATOR_LABEL = "deref"; @@ -45,7 +43,6 @@ private Dereference(Expr array, Expr offset, T type) { uniquenessIdx = Optional.empty(); } - private Dereference(Expr array, Expr offset, Expr uniqueness, T type) { this.array = array; this.offset = offset; @@ -61,12 +58,13 @@ public Expr getOffset() { return offset; } - - public static Dereference of(Expr array, Expr offset, T type) { + public static Dereference of( + Expr array, Expr offset, T type) { return new Dereference<>(array, offset, type); } - private static Dereference of(Expr array, Expr offset, Expr uniqueness, T type) { + private static Dereference of( + Expr array, Expr offset, Expr uniqueness, T type) { return new Dereference<>(array, offset, uniqueness, type); } @@ -92,7 +90,9 @@ public LitExpr eval(Valuation val) { @Override public List> getOps() { - return uniquenessIdx.isPresent() ? List.of(array, offset, uniquenessIdx.get()) : List.of(array, offset); + return uniquenessIdx.isPresent() + ? List.of(array, offset, uniquenessIdx.get()) + : List.of(array, offset); } @Override @@ -113,10 +113,10 @@ public int hashCode() { @Override public boolean equals(Object obj) { if (obj instanceof Dereference that) { - return Objects.equals(this.array, that.array) && - Objects.equals(this.offset, that.offset) && - Objects.equals(this.uniquenessIdx, that.uniquenessIdx) && - Objects.equals(this.type, that.type); + return Objects.equals(this.array, that.array) + && Objects.equals(this.offset, that.offset) + && Objects.equals(this.uniquenessIdx, that.uniquenessIdx) + && Objects.equals(this.type, that.type); } return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Exprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Exprs.java index 04df53164b..cea816fb2e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Exprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Exprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/InvalidLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/InvalidLitExpr.java index baa3ea487b..d9aef00d67 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/InvalidLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/InvalidLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,7 +21,8 @@ import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.Type; -public class InvalidLitExpr extends NullaryExpr implements LitExpr { +public class InvalidLitExpr extends NullaryExpr + implements LitExpr { private final ExprType type; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/IteExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/IteExpr.java index f22316a8e4..9857c29003 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/IteExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/IteExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.core.type.anytype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; @@ -23,14 +28,8 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IteExpr implements Expr { private static final int HASH_SEED = 181; @@ -42,23 +41,23 @@ public final class IteExpr implements Expr { private volatile int hashCode = 0; - private IteExpr(final Expr cond, final Expr then, - final Expr elze) { + private IteExpr( + final Expr cond, final Expr then, final Expr elze) { this.cond = checkNotNull(cond); this.then = checkNotNull(then); this.elze = checkNotNull(elze); } - public static IteExpr of(final Expr cond, - final Expr then, - final Expr elze) { + public static IteExpr of( + final Expr cond, final Expr then, final Expr elze) { return new IteExpr<>(cond, then, elze); } - public static IteExpr create(final Expr cond, final Expr then, - final Expr elze) { + public static IteExpr create( + final Expr cond, final Expr then, final Expr elze) { final Expr newCond = cast(cond, Bool()); - @SuppressWarnings("unchecked") final Expr newThen = (Expr) then; + @SuppressWarnings("unchecked") + final Expr newThen = (Expr) then; final Expr newElze = cast(elze, newThen.getType()); return IteExpr.of(newCond, newThen, newElze); } @@ -111,8 +110,8 @@ public IteExpr withOps(final List> ops) { return with(newCond, newThen, newElze); } - public IteExpr with(final Expr cond, final Expr then, - final Expr elze) { + public IteExpr with( + final Expr cond, final Expr then, final Expr elze) { if (this.cond == cond && this.then == then && this.elze == elze) { return this; } else { @@ -151,7 +150,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IteExpr that = (IteExpr) obj; - return this.getCond().equals(that.getCond()) && this.getThen().equals(that.getThen()) + return this.getCond().equals(that.getCond()) + && this.getThen().equals(that.getThen()) && this.getElse().equals(that.getElse()); } else { return false; @@ -160,8 +160,11 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(getCond()).add(getThen()).add(getElse()) + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .add(getCond()) + .add(getThen()) + .add(getElse()) .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/PrimeExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/PrimeExpr.java index 1131949b33..1f88acb42a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/PrimeExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/PrimeExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -75,5 +75,4 @@ protected final int getHashSeed() { public final String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/RefExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/RefExpr.java index b1bc8a36b4..2b08b82e0c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/RefExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/RefExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.type.anytype; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.Type; -import static com.google.common.base.Preconditions.checkNotNull; - public final class RefExpr extends NullaryExpr { private static final int HASH_SEED = 167; @@ -79,5 +79,4 @@ public boolean equals(final Object obj) { public String toString() { return decl.getName(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Reference.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Reference.java index 578f319c7e..b1bb3cb257 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Reference.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/Reference.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,21 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.anytype; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; - import java.util.List; import java.util.Objects; -import static com.google.common.base.Preconditions.checkState; - public final class Reference implements Expr { private static final String OPERATOR_LABEL = "ref"; @@ -71,7 +69,10 @@ public List> getOps() { @Override public Expr withOps(List> ops) { checkState(ops.size() == 1); - checkState(ops.get(0) instanceof RefExpr && ((RefExpr) ops.get(0)).getDecl() instanceof VarDecl, "Don't transform references to constants."); + checkState( + ops.get(0) instanceof RefExpr + && ((RefExpr) ops.get(0)).getDecl() instanceof VarDecl, + "Don't transform references to constants."); return Reference.of((Expr) ops.get(0), type); } @@ -83,15 +84,13 @@ public int hashCode() { @Override public boolean equals(Object obj) { if (obj instanceof Reference that) { - return Objects.equals(this.expr, that.expr) && - Objects.equals(this.type, that.type); + return Objects.equals(this.expr, that.expr) && Objects.equals(this.type, that.type); } return false; } @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(getExpr()).add(type) - .toString(); + return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(getExpr()).add(type).toString(); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/package-info.java index 45f623223f..1a2c75d46b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/anytype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,10 +16,9 @@ /** * Expressions that work with any type. Use {@link hu.bme.mit.theta.core.type.anytype.Exprs} to * create them. - *

- * - {@link hu.bme.mit.theta.core.type.anytype.IteExpr}: conditional expression, e.g., if x > 0 - * then x else -x - {@link hu.bme.mit.theta.core.type.anytype.PrimeExpr}: primed expression, e.g., + * + *

- {@link hu.bme.mit.theta.core.type.anytype.IteExpr}: conditional expression, e.g., if x > + * 0 then x else -x - {@link hu.bme.mit.theta.core.type.anytype.PrimeExpr}: primed expression, e.g., * x' - {@link hu.bme.mit.theta.core.type.anytype.RefExpr}: reference to a declaration, e.g., x */ - package hu.bme.mit.theta.core.type.anytype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayEqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayEqExpr.java index 61df9a6001..85990b461f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayEqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayEqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; @@ -23,30 +26,30 @@ import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class ArrayEqExpr extends EqExpr> { private static final int HASH_SEED = 4261; private static final String OPERATOR_LABEL = "="; - private ArrayEqExpr(final Expr> leftOp, - final Expr> rightOp) { + private ArrayEqExpr( + final Expr> leftOp, + final Expr> rightOp) { super(leftOp, rightOp); } - public static ArrayEqExpr of( - final Expr> leftOp, - final Expr> rightOp) { + public static + ArrayEqExpr of( + final Expr> leftOp, + final Expr> rightOp) { return new ArrayEqExpr<>(leftOp, rightOp); } public static ArrayEqExpr create( - final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final ArrayType arrayType = (ArrayType) leftOp.getType(); + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final ArrayType arrayType = + (ArrayType) leftOp.getType(); final Expr> newLeftOp = cast(leftOp, arrayType); final Expr> newRightOp = cast(rightOp, arrayType); return ArrayEqExpr.of(newLeftOp, newRightOp); @@ -91,8 +94,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayEqExpr that = (ArrayEqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -107,5 +110,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayExprs.java index 08159eea60..077bb661eb 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,53 +18,59 @@ import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.List; public final class ArrayExprs { - private ArrayExprs() { - } + private ArrayExprs() {} - public static ArrayType Array( - final IndexType indexType, final ElemType elemType) { + public static + ArrayType Array( + final IndexType indexType, final ElemType elemType) { return ArrayType.of(indexType, elemType); } - public static ArrayLitExpr Array( - final List, ? extends Expr>> elems, - final Expr elseElem, - final ArrayType type) { + public static + ArrayLitExpr Array( + final List, ? extends Expr>> elems, + final Expr elseElem, + final ArrayType type) { return ArrayLitExpr.of(elems, elseElem, type); } - public static ArrayInitExpr ArrayInit( - final List, Expr>> elems, final Expr elseElem, - final ArrayType type) { + public static + ArrayInitExpr ArrayInit( + final List, Expr>> elems, + final Expr elseElem, + final ArrayType type) { return ArrayInitExpr.of(elems, elseElem, type); } - public static ArrayReadExpr Read( - final Expr> array, final Expr index) { + public static + ArrayReadExpr Read( + final Expr> array, final Expr index) { return ArrayReadExpr.of(array, index); } - public static ArrayWriteExpr Write( - final Expr> array, final Expr index, - final Expr elem) { + public static + ArrayWriteExpr Write( + final Expr> array, + final Expr index, + final Expr elem) { return ArrayWriteExpr.of(array, index, elem); } - public static ArrayEqExpr Eq( - final Expr> leftOp, - final Expr> rightOp) { + public static + ArrayEqExpr Eq( + final Expr> leftOp, + final Expr> rightOp) { return ArrayEqExpr.of(leftOp, rightOp); } - public static ArrayNeqExpr Neq( - final Expr> leftOp, - final Expr> rightOp) { + public static + ArrayNeqExpr Neq( + final Expr> leftOp, + final Expr> rightOp) { return ArrayNeqExpr.of(leftOp, rightOp); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayInitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayInitExpr.java index 11c8d8a453..cb4c601a4e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayInitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayInitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.model.Valuation; @@ -22,25 +25,22 @@ import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.MultiaryExpr; import hu.bme.mit.theta.core.type.Type; - import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - /** - * ArrayInitExpr is a way to specify arbitrary array 'literals' that may contain non-literal elements as well. - * Note that while this class is a descendant of MultiaryExpr, it is used in a non-standard way: - * - ops is only used as a generic Type type, - * - ops are solely used for inter-object interactions, intra-class the `elems` and `elseElem` are used. - * - `elems` and `elseElem` are mapped to `ops` by first placing the `elseElem`, then all indices, then all elements. + * ArrayInitExpr is a way to specify arbitrary array 'literals' that may contain non-literal + * elements as well. Note that while this class is a descendant of MultiaryExpr, it is used in a + * non-standard way: - ops is only used as a generic Type type, - ops are solely used for + * inter-object interactions, intra-class the `elems` and `elseElem` are used. - `elems` and + * `elseElem` are mapped to `ops` by first placing the `elseElem`, then all indices, then all + * elements. */ - -public final class ArrayInitExpr extends MultiaryExpr> { +public final class ArrayInitExpr + extends MultiaryExpr> { private static final int HASH_SEED = 241; private static final String OPERATOR_LABEL = "arrayinit"; @@ -51,27 +51,40 @@ public final class ArrayInitExpr private final Expr elseElem; - private ArrayInitExpr(final List, Expr>> elems, - final Expr elseElem, final ArrayType type) { + private ArrayInitExpr( + final List, Expr>> elems, + final Expr elseElem, + final ArrayType type) { //noinspection unchecked - super(Stream.concat(List.of((Expr) elseElem).stream(), Stream.concat(elems.stream().map(objects -> (Expr) objects.get1()), elems.stream().map(objects -> (Expr) objects.get2()))).collect(Collectors.toList())); + super( + Stream.concat( + List.of((Expr) elseElem).stream(), + Stream.concat( + elems.stream().map(objects -> (Expr) objects.get1()), + elems.stream().map(objects -> (Expr) objects.get2()))) + .collect(Collectors.toList())); this.type = checkNotNull(type); this.elseElem = checkNotNull(elseElem); this.elems = checkNotNull(elems); } - public static ArrayInitExpr of( - final List, Expr>> elems, - final Expr elseElem, - final ArrayType type) { + public static + ArrayInitExpr of( + final List, Expr>> elems, + final Expr elseElem, + final ArrayType type) { return new ArrayInitExpr<>(elems, elseElem, type); } - public static ArrayInitExpr create( - final List, Expr>> elems, - final Expr elseElem, - final ArrayType type) { - final List, Expr>> typedElems = elems.stream().map(i -> Tuple2.of((Expr) i.get1(), (Expr) i.get2())).collect(Collectors.toList()); + public static + ArrayInitExpr create( + final List, Expr>> elems, + final Expr elseElem, + final ArrayType type) { + final List, Expr>> typedElems = + elems.stream() + .map(i -> Tuple2.of((Expr) i.get1(), (Expr) i.get2())) + .collect(Collectors.toList()); final Expr typedElseElem = (Expr) elseElem; final ArrayType typedType = (ArrayType) type; return of(typedElems, typedElseElem, typedType); @@ -92,26 +105,35 @@ public ArrayType getType() { @Override public LitExpr> eval(final Valuation val) { - return ArrayLitExpr.of(elems.stream().map(objects -> Tuple2.of(objects.get1().eval(val), objects.get2().eval(val))).collect(Collectors.toList()), elseElem, type); + return ArrayLitExpr.of( + elems.stream() + .map( + objects -> + Tuple2.of( + objects.get1().eval(val), objects.get2().eval(val))) + .collect(Collectors.toList()), + elseElem, + type); } - @Override public boolean equals(final Object obj) { if (this == obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayInitExpr that = (ArrayInitExpr) obj; - return this.type.equals(that.type) && this.elems.equals(that.elems) && elseElem.equals(that.elseElem); + return this.type.equals(that.type) + && this.elems.equals(that.elems) + && elseElem.equals(that.elseElem); } else { return false; } } - @SuppressWarnings("unchecked") @Override - public MultiaryExpr> with(Iterable> ops) { + public MultiaryExpr> with( + Iterable> ops) { long size = StreamSupport.stream(ops.spliterator(), false).count(); checkState(size % 2 == 1, "Ops must be odd long!"); long counter = 0; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayLitExpr.java index 012507dcff..df077122fc 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Utils; @@ -25,14 +28,11 @@ import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.utils.ExprSimplifier; - import java.util.List; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -public final class ArrayLitExpr extends NullaryExpr> +public final class ArrayLitExpr + extends NullaryExpr> implements LitExpr> { private static final int HASH_SEED = 229; @@ -46,25 +46,43 @@ public final class ArrayLitExpr e private volatile int hashCode; - private ArrayLitExpr(final List, ? extends Expr>> elems, - final Expr elseElem, final ArrayType type) { + private ArrayLitExpr( + final List, ? extends Expr>> elems, + final Expr elseElem, + final ArrayType type) { this.type = checkNotNull(type); final ExprSimplifier exprSimplifier = ExprSimplifier.create(); - Expr simplifiedElem = exprSimplifier.simplify(checkNotNull(elseElem), ImmutableValuation.empty()); - checkState(simplifiedElem instanceof LitExpr, "ArrayLitExprs shall only contain literal values!"); + Expr simplifiedElem = + exprSimplifier.simplify(checkNotNull(elseElem), ImmutableValuation.empty()); + checkState( + simplifiedElem instanceof LitExpr, + "ArrayLitExprs shall only contain literal values!"); this.elseElem = (LitExpr) simplifiedElem; - this.elems = checkNotNull(elems).stream().map(elem -> { - Expr index = exprSimplifier.simplify(elem.get1(), ImmutableValuation.empty()); - Expr element = exprSimplifier.simplify(elem.get2(), ImmutableValuation.empty()); - checkState(index instanceof LitExpr && element instanceof LitExpr, "ArrayLitExprs shall only contain literal values"); - return Tuple2.of((LitExpr) index, (LitExpr) element); - }).collect(Collectors.toList()); + this.elems = + checkNotNull(elems).stream() + .map( + elem -> { + Expr index = + exprSimplifier.simplify( + elem.get1(), ImmutableValuation.empty()); + Expr element = + exprSimplifier.simplify( + elem.get2(), ImmutableValuation.empty()); + checkState( + index instanceof LitExpr && element instanceof LitExpr, + "ArrayLitExprs shall only contain literal values"); + return Tuple2.of( + (LitExpr) index, + (LitExpr) element); + }) + .collect(Collectors.toList()); } - public static ArrayLitExpr of( - final List, ? extends Expr>> elems, - final Expr elseElem, - final ArrayType type) { + public static + ArrayLitExpr of( + final List, ? extends Expr>> elems, + final Expr elseElem, + final ArrayType type) { return new ArrayLitExpr<>(elems, elseElem, type); } @@ -106,7 +124,9 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayLitExpr that = (ArrayLitExpr) obj; - return this.type.equals(that.type) && this.elems.equals(that.elems) && elseElem.equals(that.elseElem); + return this.type.equals(that.type) + && this.elems.equals(that.elems) + && elseElem.equals(that.elseElem); } else { return false; } @@ -114,10 +134,12 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body() - .addAll(elems.stream().map(elem -> String.format("(%s %s)", elem.get1(), elem.get2()))) + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .addAll( + elems.stream() + .map(elem -> String.format("(%s %s)", elem.get1(), elem.get2()))) .add((String.format("(default %s)", elseElem))) .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayNeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayNeqExpr.java index 3d33111f84..86a4961787 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayNeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayNeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; @@ -23,30 +26,30 @@ import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class ArrayNeqExpr extends NeqExpr> { private static final int HASH_SEED = 5233; private static final String OPERATOR_LABEL = "/="; - private ArrayNeqExpr(final Expr> leftOp, - final Expr> rightOp) { + private ArrayNeqExpr( + final Expr> leftOp, + final Expr> rightOp) { super(leftOp, rightOp); } - public static ArrayNeqExpr of( - final Expr> leftOp, - final Expr> rightOp) { + public static + ArrayNeqExpr of( + final Expr> leftOp, + final Expr> rightOp) { return new ArrayNeqExpr<>(leftOp, rightOp); } public static ArrayNeqExpr create( - final Expr leftOp, - final Expr rightOp) { - @SuppressWarnings("unchecked") final ArrayType arrayType = (ArrayType) leftOp.getType(); + final Expr leftOp, final Expr rightOp) { + @SuppressWarnings("unchecked") + final ArrayType arrayType = + (ArrayType) leftOp.getType(); final Expr> newLeftOp = cast(leftOp, arrayType); final Expr> newRightOp = cast(rightOp, arrayType); return ArrayNeqExpr.of(newLeftOp, newRightOp); @@ -91,8 +94,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayNeqExpr that = (ArrayNeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -107,5 +110,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayReadExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayReadExpr.java index ed1bfe236b..fddd4141c3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayReadExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayReadExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Utils; @@ -22,15 +26,10 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - -public final class ArrayReadExpr implements - Expr { +public final class ArrayReadExpr + implements Expr { private static final int HASH_SEED = 1321; @@ -41,21 +40,23 @@ public final class ArrayReadExpr private final Expr> array; private final Expr index; - private ArrayReadExpr(final Expr> array, - final Expr index) { + private ArrayReadExpr( + final Expr> array, final Expr index) { this.array = checkNotNull(array); this.index = checkNotNull(index); } - public static ArrayReadExpr of( - final Expr> array, final Expr index) { + public static + ArrayReadExpr of( + final Expr> array, final Expr index) { return new ArrayReadExpr<>(array, index); } public static ArrayReadExpr create( - final Expr array, - final Expr index) { - @SuppressWarnings("unchecked") final ArrayType arrayType = (ArrayType) array.getType(); + final Expr array, final Expr index) { + @SuppressWarnings("unchecked") + final ArrayType arrayType = + (ArrayType) array.getType(); final Expr> newArray = cast(array, arrayType); final Expr newIndex = cast(index, arrayType.getIndexType()); return ArrayReadExpr.of(newArray, newIndex); @@ -76,8 +77,8 @@ public ElemType getType() { @Override public LitExpr eval(final Valuation val) { - ArrayLitExpr arrayVal = (ArrayLitExpr) array.eval( - val); + ArrayLitExpr arrayVal = + (ArrayLitExpr) array.eval(val); LitExpr indexVal = index.eval(val); for (Tuple2, LitExpr> elem : arrayVal.getElements()) { if (elem.get1().equals(indexVal)) { @@ -106,8 +107,8 @@ public Expr withOps(final List> ops) { return with(newArray, newIndex); } - public ArrayReadExpr with(final Expr> array, - final Expr index) { + public ArrayReadExpr with( + final Expr> array, final Expr index) { if (this.array == array && this.index == index) { return this; } else { @@ -143,8 +144,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayReadExpr that = (ArrayReadExpr) obj; - return this.getArray().equals(that.getArray()) && this.getIndex() - .equals(that.getIndex()); + return this.getArray().equals(that.getArray()) + && this.getIndex().equals(that.getIndex()); } else { return false; } @@ -154,5 +155,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(array).add(index).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayType.java index bcde7b3991..b6da9d0fad 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.DomainSize; import hu.bme.mit.theta.core.type.Expr; @@ -23,13 +25,11 @@ import hu.bme.mit.theta.core.type.abstracttype.Equational; import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; -import static com.google.common.base.Preconditions.checkNotNull; - public final class ArrayType implements Equational> { - private final static int HASH_SEED = 4919; - private final static String TYPE_LABEL = "Array"; + private static final int HASH_SEED = 4919; + private static final String TYPE_LABEL = "Array"; private final IndexType indexType; private final ElemType elemType; @@ -86,8 +86,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayType that = (ArrayType) obj; - return this.getIndexType().equals(that.getIndexType()) && this.getElemType() - .equals(that.getElemType()); + return this.getIndexType().equals(that.getIndexType()) + && this.getElemType().equals(that.getElemType()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayWriteExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayWriteExpr.java index b14ad4ef93..c3a4a8a23c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayWriteExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/ArrayWriteExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.core.type.arraytype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Utils; @@ -22,15 +27,9 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class ArrayWriteExpr implements Expr> { @@ -44,24 +43,28 @@ public final class ArrayWriteExpr private final Expr index; private final Expr elem; - private ArrayWriteExpr(final Expr> array, - final Expr index, - final Expr elem) { + private ArrayWriteExpr( + final Expr> array, + final Expr index, + final Expr elem) { this.array = checkNotNull(array); this.index = checkNotNull(index); this.elem = checkNotNull(elem); } - public static ArrayWriteExpr of( - final Expr> array, final Expr index, - final Expr elem) { + public static + ArrayWriteExpr of( + final Expr> array, + final Expr index, + final Expr elem) { return new ArrayWriteExpr<>(array, index, elem); } public static ArrayWriteExpr create( - final Expr array, - final Expr index, final Expr elem) { - @SuppressWarnings("unchecked") final ArrayType arrayType = (ArrayType) array.getType(); + final Expr array, final Expr index, final Expr elem) { + @SuppressWarnings("unchecked") + final ArrayType arrayType = + (ArrayType) array.getType(); final Expr> newArray = cast(array, arrayType); final Expr newIndex = cast(index, arrayType.getIndexType()); final Expr newElem = cast(elem, arrayType.getElemType()); @@ -87,12 +90,13 @@ public ArrayType getType() { @Override public LitExpr> eval(final Valuation val) { - ArrayLitExpr arrayVal = (ArrayLitExpr) array.eval( - val); + ArrayLitExpr arrayVal = + (ArrayLitExpr) array.eval(val); LitExpr indexVal = index.eval(val); LitExpr elemVal = elem.eval(val); - List, ? extends Expr>> elemList = new ArrayList<>(); + List, ? extends Expr>> elemList = + new ArrayList<>(); for (Tuple2, LitExpr> elem : arrayVal.getElements()) { if (!elem.get1().equals(indexVal)) { elemList.add(elem); @@ -125,7 +129,8 @@ public Expr> withOps(final List public ArrayWriteExpr with( final Expr> array, - final Expr index, final Expr elem) { + final Expr index, + final Expr elem) { if (this.array == array && this.index == index && elem == this.elem) { return this; } else { @@ -160,8 +165,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ArrayWriteExpr that = (ArrayWriteExpr) obj; - return this.getArray().equals(that.getArray()) && this.getIndex() - .equals(that.getIndex()) + return this.getArray().equals(that.getArray()) + && this.getIndex().equals(that.getIndex()) && this.getElem().equals(that.getElem()); } else { return false; @@ -170,7 +175,11 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(array).add(index).add(elem).toString(); + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .add(array) + .add(index) + .add(elem) + .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/package-info.java index de4071599f..a701cebd26 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/arraytype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,19 +16,18 @@ /** * SMT array type and its expressions. Use {@link hu.bme.mit.theta.core.type.arraytype.ArrayExprs} * to create them. SMT arrays are unbounded, associative mappings from a key type to a value type. - *

- * - {@link hu.bme.mit.theta.core.type.arraytype.ArrayType}: the actual array type - *

- * - {@link hu.bme.mit.theta.core.type.arraytype.ArrayLitExpr}: array literal, e.g., [0 <- 182, 1 - * <- 41, default <- 75] - {@link hu.bme.mit.theta.core.type.arraytype.ArrayInitExpr}: array - * init expression, e.g., [0 <- 182, 1 <- x, default <- 75] - *

- * - {@link hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr}: read array at an index, e.g., a[i] - * - {@link hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr}: write array at an index, e.g., a[i - * <- v], the result of write is a new array, where element i is v - *

- * - {@link hu.bme.mit.theta.core.type.arraytype.ArrayEqExpr}: equal - - * {@link hu.bme.mit.theta.core.type.arraytype.ArrayNeqExpr}: not equal + * + *

- {@link hu.bme.mit.theta.core.type.arraytype.ArrayType}: the actual array type + * + *

- {@link hu.bme.mit.theta.core.type.arraytype.ArrayLitExpr}: array literal, e.g., [0 <- + * 182, 1 <- 41, default <- 75] - {@link hu.bme.mit.theta.core.type.arraytype.ArrayInitExpr}: + * array init expression, e.g., [0 <- 182, 1 <- x, default <- 75] + * + *

- {@link hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr}: read array at an index, e.g., + * a[i] - {@link hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr}: write array at an index, + * e.g., a[i <- v], the result of write is a new array, where element i is v + * + *

- {@link hu.bme.mit.theta.core.type.arraytype.ArrayEqExpr}: equal - {@link + * hu.bme.mit.theta.core.type.arraytype.ArrayNeqExpr}: not equal */ - package hu.bme.mit.theta.core.type.arraytype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/AndExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/AndExpr.java index a4ea25d467..42b8167b48 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/AndExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/AndExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.booltype; -import hu.bme.mit.theta.core.model.Valuation; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.MultiaryExpr; - -import java.util.List; - import static com.google.common.collect.ImmutableList.toImmutableList; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import hu.bme.mit.theta.core.model.Valuation; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.MultiaryExpr; +import java.util.List; + public final class AndExpr extends MultiaryExpr { private static final int HASH_SEED = 41; @@ -90,5 +89,4 @@ public String getOperatorLabel() { protected int getHashSeed() { return HASH_SEED; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolExprs.java index 7d71ad2b9e..72ba2f936e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,14 +16,12 @@ package hu.bme.mit.theta.core.type.booltype; import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.type.Expr; public final class BoolExprs { - private BoolExprs() { - } + private BoolExprs() {} public static BoolType Bool() { return BoolType.getInstance(); @@ -65,13 +63,13 @@ public static OrExpr Or(final Iterable> ops) { return OrExpr.of(ops); } - public static ForallExpr Forall(final Iterable> paramDecls, - final Expr op) { + public static ForallExpr Forall( + final Iterable> paramDecls, final Expr op) { return ForallExpr.of(paramDecls, op); } - public static ExistsExpr Exists(final Iterable> paramDecls, - final Expr op) { + public static ExistsExpr Exists( + final Iterable> paramDecls, final Expr op) { return ExistsExpr.of(paramDecls, op); } @@ -83,20 +81,25 @@ public static AndExpr And(final Expr op1, final Expr op2) { return AndExpr.of(ImmutableList.of(op1, op2)); } - public static AndExpr And(final Expr op1, final Expr op2, - final Expr op3) { + public static AndExpr And( + final Expr op1, final Expr op2, final Expr op3) { return AndExpr.of(ImmutableList.of(op1, op2, op3)); } - public static AndExpr And(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static AndExpr And( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return AndExpr.of(ImmutableList.of(op1, op2, op3, op4)); } - public static AndExpr And(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static AndExpr And( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return AndExpr.of(ImmutableList.of(op1, op2, op3, op4, op5)); } @@ -106,21 +109,25 @@ public static OrExpr Or(final Expr op1, final Expr op2) { return OrExpr.of(ImmutableList.of(op1, op2)); } - public static OrExpr Or(final Expr op1, final Expr op2, - final Expr op3) { + public static OrExpr Or( + final Expr op1, final Expr op2, final Expr op3) { return OrExpr.of(ImmutableList.of(op1, op2, op3)); } - public static OrExpr Or(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static OrExpr Or( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return OrExpr.of(ImmutableList.of(op1, op2, op3, op4)); } - public static OrExpr Or(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static OrExpr Or( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return OrExpr.of(ImmutableList.of(op1, op2, op3, op4, op5)); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolLitExpr.java index f8b5f762bf..46424d44f7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,5 +25,4 @@ public abstract class BoolLitExpr extends NullaryExpr implements LitEx public static BoolLitExpr of(final boolean value) { return value ? TrueExpr.getInstance() : FalseExpr.getInstance(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolType.java index 233c92b454..92c2a35d12 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/BoolType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,8 +26,7 @@ public final class BoolType implements Equational { private static final int HASH_SEED = 754364; private static final String TYPE_LABEL = "Bool"; - private BoolType() { - } + private BoolType() {} public static BoolType getInstance() { return INSTANCE; @@ -64,5 +63,4 @@ public NeqExpr Neq(final Expr leftOp, final Expr r public DomainSize getDomainSize() { return DomainSize.TWO; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ExistsExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ExistsExpr.java index eb4b81a263..10ae6b17b9 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ExistsExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ExistsExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class ExistsExpr extends QuantifiedExpr { private static final int HASH_SEED = 7993; @@ -33,13 +33,13 @@ private ExistsExpr(final Iterable> paramDecls, final Expr super(paramDecls, op); } - public static ExistsExpr of(final Iterable> paramDecls, - final Expr op) { + public static ExistsExpr of( + final Iterable> paramDecls, final Expr op) { return new ExistsExpr(paramDecls, op); } - public static ExistsExpr create(final Iterable> paramDecls, - final Expr op) { + public static ExistsExpr create( + final Iterable> paramDecls, final Expr op) { final Expr newOp = cast(op, Bool()); return ExistsExpr.of(paramDecls, newOp); } @@ -64,8 +64,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ExistsExpr that = (ExistsExpr) obj; - return this.getParamDecls().equals(that.getParamDecls()) && this.getOp() - .equals(that.getOp()); + return this.getParamDecls().equals(that.getParamDecls()) + && this.getOp().equals(that.getOp()); } else { return false; } @@ -80,5 +80,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/FalseExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/FalseExpr.java index eb4ead5dd2..a18a9ac568 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/FalseExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/FalseExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public final class FalseExpr extends BoolLitExpr { private static final FalseExpr INSTANCE = new FalseExpr(); private static final int HASH_SEED = 712514; private static final String OPERATOR_LABEL = "false"; - private FalseExpr() { - } + private FalseExpr() {} public static FalseExpr getInstance() { return INSTANCE; @@ -62,5 +61,4 @@ public boolean equals(final Object obj) { public String toString() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ForallExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ForallExpr.java index 994cc07cd6..1afdf61c31 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ForallExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ForallExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class ForallExpr extends QuantifiedExpr { private static final int HASH_SEED = 6871; @@ -33,13 +33,13 @@ private ForallExpr(final Iterable> paramDecls, final Expr super(paramDecls, op); } - public static ForallExpr of(final Iterable> paramDecls, - final Expr op) { + public static ForallExpr of( + final Iterable> paramDecls, final Expr op) { return new ForallExpr(paramDecls, op); } - public static ForallExpr create(final Iterable> paramDecls, - final Expr op) { + public static ForallExpr create( + final Iterable> paramDecls, final Expr op) { final Expr newOp = cast(op, Bool()); return ForallExpr.of(paramDecls, newOp); } @@ -64,8 +64,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ForallExpr that = (ForallExpr) obj; - return this.getParamDecls().equals(that.getParamDecls()) && this.getOp() - .equals(that.getOp()); + return this.getParamDecls().equals(that.getParamDecls()) + && this.getOp().equals(that.getOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/IffExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/IffExpr.java index 8c6363c484..a53c33dc15 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/IffExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/IffExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IffExpr extends EqExpr { private static final int HASH_SEED = 67; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IffExpr that = (IffExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -95,5 +95,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ImplyExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ImplyExpr.java index 5130d2f69e..2ecc449679 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ImplyExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/ImplyExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class ImplyExpr extends BinaryExpr { private static final int HASH_SEED = 71; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ImplyExpr that = (ImplyExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -95,5 +95,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/NotExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/NotExpr.java index 5ae84f788a..94ea26cb14 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/NotExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/NotExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class NotExpr extends UnaryExpr { private static final int HASH_SEED = 127; @@ -82,5 +82,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERAND_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/OrExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/OrExpr.java index de8e43d0d2..cc51bc2334 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/OrExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/OrExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.booltype; -import hu.bme.mit.theta.core.model.Valuation; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.MultiaryExpr; - -import java.util.List; - import static com.google.common.collect.ImmutableList.toImmutableList; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import hu.bme.mit.theta.core.model.Valuation; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.MultiaryExpr; +import java.util.List; + public final class OrExpr extends MultiaryExpr { private static final int HASH_SEED = 131; @@ -91,5 +90,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/QuantifiedExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/QuantifiedExpr.java index 52c3f0a577..7dec9f0e7a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/QuantifiedExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/QuantifiedExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static java.util.stream.Collectors.joining; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static java.util.stream.Collectors.joining; - public abstract class QuantifiedExpr implements Expr { private final List> paramDecls; @@ -37,8 +36,8 @@ public abstract class QuantifiedExpr implements Expr { private volatile int hashCode = 0; - protected QuantifiedExpr(final Iterable> paramDecls, - final Expr op) { + protected QuantifiedExpr( + final Iterable> paramDecls, final Expr op) { this.paramDecls = ImmutableList.copyOf(checkNotNull(paramDecls)); this.op = checkNotNull(op); } @@ -88,10 +87,15 @@ public final int hashCode() { @Override public final String toString() { - final String paramString = paramDecls.stream() - .map(p -> "(" + p.getName() + " " + p.getType() + ")") - .collect(joining(" ", "(", ")")); - return Utils.lispStringBuilder(getOperatorLabel()).body().add(paramString).add(op).toString(); + final String paramString = + paramDecls.stream() + .map(p -> "(" + p.getName() + " " + p.getType() + ")") + .collect(joining(" ", "(", ")")); + return Utils.lispStringBuilder(getOperatorLabel()) + .body() + .add(paramString) + .add(op) + .toString(); } public abstract QuantifiedExpr with(final Expr op); @@ -99,5 +103,4 @@ public final String toString() { protected abstract int getHashSeed(); protected abstract String getOperatorLabel(); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/SmartBoolExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/SmartBoolExprs.java index 4f2eff8d4c..60f63a1481 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/SmartBoolExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/SmartBoolExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,18 +20,15 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import com.google.common.collect.ImmutableList; +import hu.bme.mit.theta.core.type.Expr; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; -import com.google.common.collect.ImmutableList; - -import hu.bme.mit.theta.core.type.Expr; - public final class SmartBoolExprs { - private SmartBoolExprs() { - } + private SmartBoolExprs() {} public static Expr Not(final Expr op) { if (op.equals(True())) { @@ -66,8 +63,8 @@ public static Expr And(final Collection> ops) return False(); } - final List> filteredOps = ops.stream().filter(o -> !o.equals(True())) - .collect(toImmutableList()); + final List> filteredOps = + ops.stream().filter(o -> !o.equals(True())).collect(toImmutableList()); if (filteredOps.isEmpty()) { return True(); @@ -85,8 +82,8 @@ public static Expr Or(final Collection> ops) return True(); } - final List> filteredOps = ops.stream().filter(o -> !o.equals(False())) - .collect(toImmutableList()); + final List> filteredOps = + ops.stream().filter(o -> !o.equals(False())).collect(toImmutableList()); if (filteredOps.isEmpty()) { return False(); @@ -105,20 +102,25 @@ public static Expr And(final Expr op1, final Expr return And(ImmutableList.of(op1, op2)); } - public static Expr And(final Expr op1, final Expr op2, - final Expr op3) { + public static Expr And( + final Expr op1, final Expr op2, final Expr op3) { return And(ImmutableList.of(op1, op2, op3)); } - public static Expr And(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static Expr And( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return And(ImmutableList.of(op1, op2, op3, op4)); } - public static Expr And(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static Expr And( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return And(ImmutableList.of(op1, op2, op3, op4, op5)); } @@ -128,20 +130,25 @@ public static Expr Or(final Expr op1, final Expr o return Or(ImmutableList.of(op1, op2)); } - public static Expr Or(final Expr op1, final Expr op2, - final Expr op3) { + public static Expr Or( + final Expr op1, final Expr op2, final Expr op3) { return Or(ImmutableList.of(op1, op2, op3)); } - public static Expr Or(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static Expr Or( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return Or(ImmutableList.of(op1, op2, op3, op4)); } - public static Expr Or(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static Expr Or( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return Or(ImmutableList.of(op1, op2, op3, op4, op5)); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/TrueExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/TrueExpr.java index 92a93f1cb9..a411c7bf73 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/TrueExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/TrueExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.booltype; -import hu.bme.mit.theta.core.model.Valuation; - import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import hu.bme.mit.theta.core.model.Valuation; + public final class TrueExpr extends BoolLitExpr { private static final TrueExpr INSTANCE = new TrueExpr(); private static final int HASH_SEED = 242181; private static final String OPERATOR = "true"; - private TrueExpr() { - } + private TrueExpr() {} public static TrueExpr getInstance() { return INSTANCE; @@ -61,5 +60,4 @@ public boolean equals(final Object obj) { public String toString() { return OPERATOR; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/XorExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/XorExpr.java index 4b98b2107c..940609473f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/XorExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/XorExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.type.booltype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class XorExpr extends NeqExpr { private static final int HASH_SEED = 937; @@ -57,8 +57,8 @@ public LitExpr eval(final Valuation val) { } @Override - public BinaryExpr with(final Expr leftOp, - final Expr rightOp) { + public BinaryExpr with( + final Expr leftOp, final Expr rightOp) { if (leftOp == getLeftOp() && rightOp == getRightOp()) { return this; } else { @@ -82,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final XorExpr that = (XorExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/package-info.java index 29e21a3462..b7cb869343 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/booltype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,21 +16,20 @@ /** * Bool type and its expressions. Use {@link hu.bme.mit.theta.core.type.booltype.BoolExprs} to * create them. - *

- * - {@link hu.bme.mit.theta.core.type.booltype.BoolType}: the actual Boolean type - *

- * - {@link hu.bme.mit.theta.core.type.booltype.TrueExpr}: true literal - - * {@link hu.bme.mit.theta.core.type.booltype.FalseExpr}: false literal - *

- * - {@link hu.bme.mit.theta.core.type.booltype.NotExpr}: negation - - * {@link hu.bme.mit.theta.core.type.booltype.AndExpr}: and (conjunction) - - * {@link hu.bme.mit.theta.core.type.booltype.OrExpr}: or (disjunction) - - * {@link hu.bme.mit.theta.core.type.booltype.ImplyExpr}: implication - - * {@link hu.bme.mit.theta.core.type.booltype.XorExpr}: exclusive or (xor) - - * {@link hu.bme.mit.theta.core.type.booltype.IffExpr}: equivalence (if and only if) - *

- * - {@link hu.bme.mit.theta.core.type.booltype.ExistsExpr}: existential quantifier - - * {@link hu.bme.mit.theta.core.type.booltype.ForallExpr}: universal quantifier + * + *

- {@link hu.bme.mit.theta.core.type.booltype.BoolType}: the actual Boolean type + * + *

- {@link hu.bme.mit.theta.core.type.booltype.TrueExpr}: true literal - {@link + * hu.bme.mit.theta.core.type.booltype.FalseExpr}: false literal + * + *

- {@link hu.bme.mit.theta.core.type.booltype.NotExpr}: negation - {@link + * hu.bme.mit.theta.core.type.booltype.AndExpr}: and (conjunction) - {@link + * hu.bme.mit.theta.core.type.booltype.OrExpr}: or (disjunction) - {@link + * hu.bme.mit.theta.core.type.booltype.ImplyExpr}: implication - {@link + * hu.bme.mit.theta.core.type.booltype.XorExpr}: exclusive or (xor) - {@link + * hu.bme.mit.theta.core.type.booltype.IffExpr}: equivalence (if and only if) + * + *

- {@link hu.bme.mit.theta.core.type.booltype.ExistsExpr}: existential quantifier - {@link + * hu.bme.mit.theta.core.type.booltype.ForallExpr}: universal quantifier */ - -package hu.bme.mit.theta.core.type.booltype; \ No newline at end of file +package hu.bme.mit.theta.core.type.booltype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAddExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAddExpr.java index 04a9bf647d..35e52f87e8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAddExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAddExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.AddExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvAddExpr extends AddExpr { private static final int HASH_SEED = 6586; @@ -53,11 +51,12 @@ public BvType getType() { @Override public BvLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (BvLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.add((BvLitExpr) op2.eval(val))), - BvLitExpr::add - ); + return getOps().stream() + .skip(1) + .reduce( + (BvLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.add((BvLitExpr) op2.eval(val))), + BvLitExpr::add); } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAndExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAndExpr.java index 950ddfddb2..9139a6a705 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAndExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvAndExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.MultiaryExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvAndExpr extends MultiaryExpr { private static final int HASH_SEED = 9125; @@ -52,11 +51,12 @@ public BvType getType() { @Override public BvLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (BvLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.and((BvLitExpr) op2.eval(val))), - BvLitExpr::and - ); + return getOps().stream() + .skip(1) + .reduce( + (BvLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.and((BvLitExpr) op2.eval(val))), + BvLitExpr::and); } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvArithShiftRightExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvArithShiftRightExpr.java index 7fefd7562d..8b7c7130b6 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvArithShiftRightExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvArithShiftRightExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvArithShiftRightExpr extends BinaryExpr { private static final int HASH_SEED = 965; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvArithShiftRightExpr that = (BvArithShiftRightExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -95,4 +95,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } -} \ No newline at end of file +} diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvConcatExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvConcatExpr.java index cc8e14aa7d..c8797e8c4b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvConcatExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvConcatExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; - public final class BvConcatExpr implements Expr { private static final int HASH_SEED = 8264; @@ -63,11 +62,12 @@ public BvType getType() { @Override public BvLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (BvLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.concat((BvLitExpr) op2.eval(val))), - BvLitExpr::concat - ); + return getOps().stream() + .skip(1) + .reduce( + (BvLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.concat((BvLitExpr) op2.eval(val))), + BvLitExpr::concat); } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvEqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvEqExpr.java index 91909853dd..9accdbc1ec 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvEqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvEqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvEqExpr extends EqExpr { private static final int HASH_SEED = 2487; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvEqExpr that = (BvEqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExprs.java index d53008a8ee..56e1358f5d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; - import java.util.List; public final class BvExprs { - private BvExprs() { - - } + private BvExprs() {} public static BvType BvType(final int size, final Boolean signedness) { return BvType.of(size, signedness); @@ -43,13 +39,12 @@ public static BvLitExpr Bv(final boolean[] value) { return Bv(value, null); } - public static BvConcatExpr Concat(final Iterable> ops) { return BvConcatExpr.of(ops); } - public static BvExtractExpr Extract(final Expr bitvec, final IntLitExpr from, - final IntLitExpr until) { + public static BvExtractExpr Extract( + final Expr bitvec, final IntLitExpr from, final IntLitExpr until) { return BvExtractExpr.of(bitvec, from, until); } @@ -121,23 +116,23 @@ public static BvShiftLeftExpr ShiftLeft(final Expr leftOp, final Expr leftOp, - final Expr rightOp) { + public static BvArithShiftRightExpr ArithShiftRight( + final Expr leftOp, final Expr rightOp) { return BvArithShiftRightExpr.of(leftOp, rightOp); } - public static BvLogicShiftRightExpr LogicShiftRight(final Expr leftOp, - final Expr rightOp) { + public static BvLogicShiftRightExpr LogicShiftRight( + final Expr leftOp, final Expr rightOp) { return BvLogicShiftRightExpr.of(leftOp, rightOp); } - public static BvRotateLeftExpr RotateLeft(final Expr leftOp, - final Expr rightOp) { + public static BvRotateLeftExpr RotateLeft( + final Expr leftOp, final Expr rightOp) { return BvRotateLeftExpr.of(leftOp, rightOp); } - public static BvRotateRightExpr RotateRight(final Expr leftOp, - final Expr rightOp) { + public static BvRotateRightExpr RotateRight( + final Expr leftOp, final Expr rightOp) { return BvRotateRightExpr.of(leftOp, rightOp); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExtractExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExtractExpr.java index 1afcdc0f1a..3786d3a35b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExtractExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvExtractExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,25 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; - import java.math.BigInteger; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvExtractExpr implements Expr { private static final int HASH_SEED = 6586; @@ -43,8 +41,8 @@ public final class BvExtractExpr implements Expr { private volatile int hashCode = 0; - private BvExtractExpr(final Expr bitvec, final IntLitExpr from, - final IntLitExpr until) { + private BvExtractExpr( + final Expr bitvec, final IntLitExpr from, final IntLitExpr until) { checkNotNull(bitvec); checkNotNull(from); checkNotNull(until); @@ -57,13 +55,13 @@ private BvExtractExpr(final Expr bitvec, final IntLitExpr from, this.until = until; } - public static BvExtractExpr of(final Expr bitvec, final IntLitExpr from, - final IntLitExpr until) { + public static BvExtractExpr of( + final Expr bitvec, final IntLitExpr from, final IntLitExpr until) { return new BvExtractExpr(bitvec, from, until); } - public static BvExtractExpr create(final Expr bitvec, final Expr from, - final Expr until) { + public static BvExtractExpr create( + final Expr bitvec, final Expr from, final Expr until) { final Expr newBitvec = castBv(bitvec); final IntLitExpr newFrom = (IntLitExpr) cast(from, Int()); final IntLitExpr newUntil = (IntLitExpr) cast(until, Int()); @@ -137,8 +135,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvExtractExpr that = (BvExtractExpr) obj; - return this.getBitvec().equals(that.getBitvec()) && this.getFrom() - .equals(that.getFrom()) + return this.getBitvec().equals(that.getBitvec()) + && this.getFrom().equals(that.getFrom()) && this.getUntil().equals(that.getUntil()); } else { return false; @@ -147,7 +145,11 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(getBitvec()).add(getFrom()) - .add(getUntil()).toString(); + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .add(getBitvec()) + .add(getFrom()) + .add(getUntil()) + .toString(); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLitExpr.java index 55aaed31b7..cdd88db510 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; -import hu.bme.mit.theta.core.model.Valuation; -import hu.bme.mit.theta.core.type.LitExpr; -import hu.bme.mit.theta.core.type.NullaryExpr; -import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; -import hu.bme.mit.theta.core.type.inttype.IntLitExpr; -import hu.bme.mit.theta.core.utils.BvUtils; - -import java.math.BigInteger; -import java.util.Arrays; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; @@ -41,7 +30,17 @@ import static hu.bme.mit.theta.core.utils.BvUtils.signedBvLitExprToBigInteger; import static hu.bme.mit.theta.core.utils.BvUtils.unsignedBvLitExprToBigInteger; -public final class BvLitExpr extends NullaryExpr implements LitExpr, Comparable { +import hu.bme.mit.theta.core.model.Valuation; +import hu.bme.mit.theta.core.type.LitExpr; +import hu.bme.mit.theta.core.type.NullaryExpr; +import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; +import hu.bme.mit.theta.core.type.inttype.IntLitExpr; +import hu.bme.mit.theta.core.utils.BvUtils; +import java.math.BigInteger; +import java.util.Arrays; + +public final class BvLitExpr extends NullaryExpr + implements LitExpr, Comparable { private static final int HASH_SEED = 5624; private volatile int hashCode = 0; @@ -99,7 +98,8 @@ public BvLitExpr extract(final IntLitExpr from, final IntLitExpr until) { boolean[] extracted = new boolean[untilValue - fromValue]; for (int i = 0; i < extracted.length; i++) { - extracted[extracted.length - i - 1] = this.getValue()[this.getValue().length - (fromValue + i) - 1]; + extracted[extracted.length - i - 1] = + this.getValue()[this.getValue().length - (fromValue + i) - 1]; } return Bv(extracted); } @@ -139,14 +139,16 @@ public BvLitExpr add(final BvLitExpr that) { public BvLitExpr sub(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - BigInteger sub = neutralBvLitExprToBigInteger(this).subtract(neutralBvLitExprToBigInteger(that)); + BigInteger sub = + neutralBvLitExprToBigInteger(this).subtract(neutralBvLitExprToBigInteger(that)); sub = fitBigIntegerIntoNeutralDomain(sub, getType().getSize()); return bigIntegerToNeutralBvLitExpr(sub, getType().getSize()); } public BvLitExpr mul(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - BigInteger prod = neutralBvLitExprToBigInteger(this).multiply(neutralBvLitExprToBigInteger(that)); + BigInteger prod = + neutralBvLitExprToBigInteger(this).multiply(neutralBvLitExprToBigInteger(that)); prod = fitBigIntegerIntoNeutralDomain(prod, getType().getSize()); return bigIntegerToNeutralBvLitExpr(prod, getType().getSize()); } @@ -165,14 +167,16 @@ public BvLitExpr neg() { public BvLitExpr udiv(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - BigInteger div = unsignedBvLitExprToBigInteger(this).divide(unsignedBvLitExprToBigInteger(that)); + BigInteger div = + unsignedBvLitExprToBigInteger(this).divide(unsignedBvLitExprToBigInteger(that)); div = fitBigIntegerIntoUnsignedDomain(div, getType().getSize()); return bigIntegerToUnsignedBvLitExpr(div, getType().getSize()); } public BvLitExpr sdiv(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - BigInteger div = signedBvLitExprToBigInteger(this).divide(signedBvLitExprToBigInteger(that)); + BigInteger div = + signedBvLitExprToBigInteger(this).divide(signedBvLitExprToBigInteger(that)); div = fitBigIntegerIntoSignedDomain(div, getType().getSize()); return bigIntegerToSignedBvLitExpr(div, getType().getSize()); } @@ -204,7 +208,9 @@ public BvLitExpr shiftLeft(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); boolean[] shifted = Arrays.copyOf(this.getValue(), this.getValue().length); - for (BigInteger i = BigInteger.ZERO; i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; i = i.add(BigInteger.ONE)) { + for (BigInteger i = BigInteger.ZERO; + i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; + i = i.add(BigInteger.ONE)) { for (int j = 0; j < shifted.length - 1; j++) { shifted[j] = shifted[j + 1]; } @@ -218,7 +224,9 @@ public BvLitExpr arithShiftRight(final BvLitExpr that) { boolean[] shifted = Arrays.copyOf(this.getValue(), this.getValue().length); boolean insert = shifted[0]; - for (BigInteger i = BigInteger.ZERO; i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; i = i.add(BigInteger.ONE)) { + for (BigInteger i = BigInteger.ZERO; + i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; + i = i.add(BigInteger.ONE)) { for (int j = shifted.length - 1; j > 0; j--) { shifted[j] = shifted[j - 1]; } @@ -232,7 +240,9 @@ public BvLitExpr logicShiftRight(final BvLitExpr that) { boolean[] shifted = Arrays.copyOf(this.getValue(), this.getValue().length); boolean insert = false; - for (BigInteger i = BigInteger.ZERO; i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; i = i.add(BigInteger.ONE)) { + for (BigInteger i = BigInteger.ZERO; + i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; + i = i.add(BigInteger.ONE)) { for (int j = shifted.length - 1; j > 0; j--) { shifted[j] = shifted[j - 1]; } @@ -245,7 +255,9 @@ public BvLitExpr rotateLeft(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); boolean[] shifted = Arrays.copyOf(this.getValue(), this.getValue().length); - for (BigInteger i = BigInteger.ZERO; i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; i = i.add(BigInteger.ONE)) { + for (BigInteger i = BigInteger.ZERO; + i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; + i = i.add(BigInteger.ONE)) { boolean rotated = shifted[0]; for (int j = 0; j < shifted.length - 1; j++) { shifted[j] = shifted[j + 1]; @@ -259,7 +271,9 @@ public BvLitExpr rotateRight(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); boolean[] shifted = Arrays.copyOf(this.getValue(), this.getValue().length); - for (BigInteger i = BigInteger.ZERO; i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; i = i.add(BigInteger.ONE)) { + for (BigInteger i = BigInteger.ZERO; + i.compareTo(neutralBvLitExprToBigInteger(that)) < 0; + i = i.add(BigInteger.ONE)) { boolean rotated = shifted[shifted.length - 1]; for (int j = shifted.length - 1; j > 0; j--) { shifted[j] = shifted[j - 1]; @@ -276,7 +290,8 @@ public BvLitExpr smod(final BvLitExpr that) { // 5 mod -3 = 2 // -5 mod 3 = 1 // -5 mod -3 = 1 - BigInteger result = signedBvLitExprToBigInteger(this).mod(signedBvLitExprToBigInteger(that)); + BigInteger result = + signedBvLitExprToBigInteger(this).mod(signedBvLitExprToBigInteger(that)); if (result.compareTo(BigInteger.ZERO) < 0) { result = result.add(signedBvLitExprToBigInteger(that).abs()); } @@ -304,9 +319,11 @@ public BvLitExpr srem(final BvLitExpr that) { BigInteger thatAbs = thatInt.abs(); if (thisInt.compareTo(BigInteger.ZERO) < 0 && thatInt.compareTo(BigInteger.ZERO) < 0) { return bigIntegerToSignedBvLitExpr(thisAbs.mod(thatAbs).negate(), getType().getSize()); - } else if (thisInt.compareTo(BigInteger.ZERO) >= 0 && thatInt.compareTo(BigInteger.ZERO) < 0) { + } else if (thisInt.compareTo(BigInteger.ZERO) >= 0 + && thatInt.compareTo(BigInteger.ZERO) < 0) { return bigIntegerToSignedBvLitExpr(thisAbs.mod(thatAbs), getType().getSize()); - } else if (thisInt.compareTo(BigInteger.ZERO) < 0 && thatInt.compareTo(BigInteger.ZERO) >= 0) { + } else if (thisInt.compareTo(BigInteger.ZERO) < 0 + && thatInt.compareTo(BigInteger.ZERO) >= 0) { return bigIntegerToSignedBvLitExpr(thisAbs.mod(thatAbs).negate(), getType().getSize()); } else { return bigIntegerToSignedBvLitExpr(thisInt.mod(thatInt), getType().getSize()); @@ -325,42 +342,56 @@ public BoolLitExpr neq(final BvLitExpr that) { public BoolLitExpr ult(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) < 0); + return Bool( + unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) + < 0); } public BoolLitExpr ule(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) <= 0); + return Bool( + unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) + <= 0); } public BoolLitExpr ugt(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) > 0); + return Bool( + unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) + > 0); } public BoolLitExpr uge(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) >= 0); + return Bool( + unsignedBvLitExprToBigInteger(this).compareTo(unsignedBvLitExprToBigInteger(that)) + >= 0); } public BoolLitExpr slt(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) < 0); + return Bool( + signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) < 0); } public BoolLitExpr sle(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) <= 0); + return Bool( + signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) + <= 0); } public BoolLitExpr sgt(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) > 0); + return Bool( + signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) > 0); } public BoolLitExpr sge(final BvLitExpr that) { checkArgument(this.getType().equals(that.getType())); - return Bool(signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) >= 0); + return Bool( + signedBvLitExprToBigInteger(this).compareTo(signedBvLitExprToBigInteger(that)) + >= 0); } @Override @@ -389,7 +420,7 @@ public boolean equals(final Object obj) { @Override public String toString() { final StringBuilder sb = new StringBuilder(); -// sb.append(getType().getSize()); + // sb.append(getType().getSize()); sb.append("#b"); for (boolean bit : value) { sb.append(bit ? "1" : "0"); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLogicShiftRightExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLogicShiftRightExpr.java index 0c01ac9968..d4fd45089b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLogicShiftRightExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvLogicShiftRightExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvLogicShiftRightExpr extends BinaryExpr { private static final int HASH_SEED = 962; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvLogicShiftRightExpr that = (BvLogicShiftRightExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -95,4 +95,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } -} \ No newline at end of file +} diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvMulExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvMulExpr.java index ee940f0834..92a12a7599 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvMulExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvMulExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.MulExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvMulExpr extends MulExpr { private static final int HASH_SEED = 9825; @@ -53,11 +51,12 @@ public BvType getType() { @Override public BvLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (BvLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.mul((BvLitExpr) op2.eval(val))), - BvLitExpr::mul - ); + return getOps().stream() + .skip(1) + .reduce( + (BvLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.mul((BvLitExpr) op2.eval(val))), + BvLitExpr::mul); } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNegExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNegExpr.java index 6125a81351..cc1b6de612 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNegExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNegExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NegExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvNegExpr extends NegExpr { private static final int HASH_SEED = 8325; @@ -81,5 +80,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNeqExpr.java index 7f9a6dc759..c9db1875c1 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvNeqExpr extends NeqExpr { private static final int HASH_SEED = 2488; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvNeqExpr that = (BvNeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNotExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNotExpr.java index f8b5968f29..f4132cf51d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNotExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvNotExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvNotExpr extends UnaryExpr { private static final int HASH_SEED = 1527; @@ -80,5 +80,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvOrExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvOrExpr.java index d3b6a1439d..32fd5b8507 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvOrExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvOrExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.MultiaryExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvOrExpr extends MultiaryExpr { private static final int HASH_SEED = 2745; @@ -52,11 +51,12 @@ public BvType getType() { @Override public BvLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (BvLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.or((BvLitExpr) op2.eval(val))), - BvLitExpr::or - ); + return getOps().stream() + .skip(1) + .reduce( + (BvLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.or((BvLitExpr) op2.eval(val))), + BvLitExpr::or); } @Override @@ -90,4 +90,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvPosExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvPosExpr.java index c2f8deca08..8ab76b35bf 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvPosExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvPosExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.PosExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvPosExpr extends PosExpr { private static final int HASH_SEED = 8962; @@ -81,5 +80,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateLeftExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateLeftExpr.java index c2a29b42e8..a61b63aacf 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateLeftExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateLeftExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvRotateLeftExpr extends BinaryExpr { private static final int HASH_SEED = 4282; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvRotateLeftExpr that = (BvRotateLeftExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateRightExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateRightExpr.java index feb0e22594..5aaa5acb4f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateRightExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvRotateRightExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvRotateRightExpr extends BinaryExpr { private static final int HASH_SEED = 2564; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvRotateRightExpr that = (BvRotateRightExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSDivExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSDivExpr.java index f6263f2b71..d562041f00 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSDivExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSDivExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.DivExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSDivExpr extends DivExpr { private static final int HASH_SEED = 9830; @@ -82,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSDivExpr that = (BvSDivExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSExtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSExtExpr.java index dec5b61913..fe0eebe8b0 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSExtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSExtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvSExtExpr implements Expr { private static final int HASH_SEED = 6126; @@ -117,6 +116,10 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(getOp()).add(getType()).toString(); + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .add(getOp()) + .add(getType()) + .toString(); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGeqExpr.java index c61047b7b4..19df57e9ce 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.GeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSGeqExpr extends GeqExpr { private static final int HASH_SEED = 6234; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSGeqExpr that = (BvSGeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGtExpr.java index 2b452303b9..7200247f8d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSGtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.GtExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSGtExpr extends GtExpr { private static final int HASH_SEED = 6231; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSGtExpr that = (BvSGtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLeqExpr.java index ab9a5cefe2..ff70b42471 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.LeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSLeqExpr extends LeqExpr { private static final int HASH_SEED = 1458; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSLeqExpr that = (BvSLeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLtExpr.java index 857e659275..163a9e2aea 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSLtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.LtExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSLtExpr extends LtExpr { private static final int HASH_SEED = 2798; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSLtExpr that = (BvSLtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSModExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSModExpr.java index 2b9ed0683a..207f4b8578 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSModExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSModExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.ModExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSModExpr extends ModExpr { private static final int HASH_SEED = 1451; @@ -80,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSModExpr that = (BvSModExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSRemExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSRemExpr.java index 05b7f60076..9741aa6ae0 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSRemExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSRemExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.RemExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSRemExpr extends RemExpr { private static final int HASH_SEED = 985; @@ -81,8 +80,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSRemExpr that = (BvSRemExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvShiftLeftExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvShiftLeftExpr.java index 5e5dfcc09e..2db425db64 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvShiftLeftExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvShiftLeftExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvShiftLeftExpr extends BinaryExpr { private static final int HASH_SEED = 4288; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvShiftLeftExpr that = (BvShiftLeftExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSignChangeExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSignChangeExpr.java index 443eef2db3..25fd0a207d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSignChangeExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSignChangeExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.PosExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvSignChangeExpr extends PosExpr { private static final int HASH_SEED = 8963; @@ -84,5 +83,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSubExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSubExpr.java index f01a47454e..37a5d75509 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSubExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvSubExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.SubExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvSubExpr extends SubExpr { private static final int HASH_SEED = 2567; @@ -81,8 +80,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvSubExpr that = (BvSubExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +96,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvType.java index 36023bf9ed..0db2f871c5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.FromBv; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.DomainSize; import hu.bme.mit.theta.core.type.Expr; @@ -23,19 +26,18 @@ import hu.bme.mit.theta.core.type.abstracttype.*; import hu.bme.mit.theta.core.type.fptype.FpRoundingMode; import hu.bme.mit.theta.core.type.fptype.FpType; - import java.math.BigInteger; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.FromBv; - -public class BvType implements Additive, Multiplicative, Divisible, - Equational, Ordered, - Castable { +public class BvType + implements Additive, + Multiplicative, + Divisible, + Equational, + Ordered, + Castable { - private final static int HASH_SEED = 5674; - private final static String TYPE_LABEL = "Bv"; + private static final int HASH_SEED = 5674; + private static final String TYPE_LABEL = "Bv"; private final int size; private final Boolean signed; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUDivExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUDivExpr.java index 04e25bc56e..8e2f0ae196 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUDivExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUDivExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.DivExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvUDivExpr extends DivExpr { private static final int HASH_SEED = 9832; @@ -82,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvUDivExpr that = (BvUDivExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGeqExpr.java index f37c02ab23..75e5aa7ac4 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.GeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvUGeqExpr extends GeqExpr { private static final int HASH_SEED = 6234; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvUGeqExpr that = (BvUGeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGtExpr.java index 1723eccb7e..73f475896c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvUGtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.GtExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvUGtExpr extends GtExpr { private static final int HASH_SEED = 6231; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvUGtExpr that = (BvUGtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULeqExpr.java index 72a11cf3b2..4fbf91b875 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.LeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvULeqExpr extends LeqExpr { private static final int HASH_SEED = 1458; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvULeqExpr that = (BvULeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULtExpr.java index 9a1dc679cd..ba97949df5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvULtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.LtExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvULtExpr extends LtExpr { private static final int HASH_SEED = 2798; @@ -83,8 +82,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvULtExpr that = (BvULtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -99,5 +98,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvURemExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvURemExpr.java index 91ec6d102f..784c1eee29 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvURemExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvURemExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.bvtype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.RemExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvURemExpr extends RemExpr { private static final int HASH_SEED = 995; @@ -81,8 +80,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final BvURemExpr that = (BvURemExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvXorExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvXorExpr.java index a8e199c871..a74dbc31d3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvXorExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvXorExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.MultiaryExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class BvXorExpr extends MultiaryExpr { private static final int HASH_SEED = 9457; @@ -52,11 +51,12 @@ public BvType getType() { @Override public BvLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (BvLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.xor((BvLitExpr) op2.eval(val))), - BvLitExpr::xor - ); + return getOps().stream() + .skip(1) + .reduce( + (BvLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.xor((BvLitExpr) op2.eval(val))), + BvLitExpr::xor); } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvZExtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvZExtExpr.java index 459ca34716..caf191202d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvZExtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/BvZExtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.bvtype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; - public final class BvZExtExpr implements Expr { private static final int HASH_SEED = 6526; @@ -117,6 +116,10 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(getOp()).add(getType()).toString(); + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .add(getOp()) + .add(getType()) + .toString(); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/package-info.java index 7241a8d3a4..fe4d4c28d3 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/bvtype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,44 +18,43 @@ * create them. Bitvectors can be used to simulate machine integers that can be signed/unsigned with * a fixed range and wraparound overflow semantics. For example, 255+1 on 8 unsigned bits will * result in 0. - *

- * - {@link hu.bme.mit.theta.core.type.bvtype.BvType}: the actual bitvector type - *

- * - {@link hu.bme.mit.theta.core.type.bvtype.BvLitExpr}: bitvector literal - - * {@link hu.bme.mit.theta.core.type.bvtype.BvConcatExpr}: bitvector concatenation - - * {@link hu.bme.mit.theta.core.type.bvtype.BvExtractExpr}: bitvector extraction - *

- * - {@link hu.bme.mit.theta.core.type.bvtype.BvNegExpr}: unary minus - - * {@link hu.bme.mit.theta.core.type.bvtype.BvPosExpr}: unary plus - - * {@link hu.bme.mit.theta.core.type.bvtype.BvAddExpr}: addition - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSubExpr}: subtraction - - * {@link hu.bme.mit.theta.core.type.bvtype.BvMulExpr}: multiplication - - * {@link hu.bme.mit.theta.core.type.bvtype.BvUDivExpr}: unsigned division - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSDivExpr}: signed division - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSModExpr}: modulus - - * {@link hu.bme.mit.theta.core.type.bvtype.BvURemExpr}: unsigned remainder - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSRemExpr}: signed remainder - *

- * - {@link hu.bme.mit.theta.core.type.bvtype.BvNotExpr}: bitwise not - - * {@link hu.bme.mit.theta.core.type.bvtype.BvAndExpr}: bitwise and - - * {@link hu.bme.mit.theta.core.type.bvtype.BvOrExpr}: bitwise or - - * {@link hu.bme.mit.theta.core.type.bvtype.BvXorExpr}: bitwise xor - - * {@link hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr}: shift left - - * {@link hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr}: arithmetic shift right - - * {@link hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr}: logical shift right - - * {@link hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr}: rotate left - - * {@link hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr}: rotate right - *

- * - {@link hu.bme.mit.theta.core.type.bvtype.BvEqExpr}: equal - - * {@link hu.bme.mit.theta.core.type.bvtype.BvNeqExpr}: not equal - - * {@link hu.bme.mit.theta.core.type.bvtype.BvUGtExpr}: unsigned greater - - * {@link hu.bme.mit.theta.core.type.bvtype.BvULtExpr}: unsigned less - - * {@link hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr}: unsigned greater or equal - - * {@link hu.bme.mit.theta.core.type.bvtype.BvULeqExpr}: unsigned less or equal - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSGtExpr}: signed greater - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSLtExpr}: signed less - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr}: signed greater or equal - - * {@link hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr}: signed less or equal + * + *

- {@link hu.bme.mit.theta.core.type.bvtype.BvType}: the actual bitvector type + * + *

- {@link hu.bme.mit.theta.core.type.bvtype.BvLitExpr}: bitvector literal - {@link + * hu.bme.mit.theta.core.type.bvtype.BvConcatExpr}: bitvector concatenation - {@link + * hu.bme.mit.theta.core.type.bvtype.BvExtractExpr}: bitvector extraction + * + *

- {@link hu.bme.mit.theta.core.type.bvtype.BvNegExpr}: unary minus - {@link + * hu.bme.mit.theta.core.type.bvtype.BvPosExpr}: unary plus - {@link + * hu.bme.mit.theta.core.type.bvtype.BvAddExpr}: addition - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSubExpr}: subtraction - {@link + * hu.bme.mit.theta.core.type.bvtype.BvMulExpr}: multiplication - {@link + * hu.bme.mit.theta.core.type.bvtype.BvUDivExpr}: unsigned division - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSDivExpr}: signed division - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSModExpr}: modulus - {@link + * hu.bme.mit.theta.core.type.bvtype.BvURemExpr}: unsigned remainder - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSRemExpr}: signed remainder + * + *

- {@link hu.bme.mit.theta.core.type.bvtype.BvNotExpr}: bitwise not - {@link + * hu.bme.mit.theta.core.type.bvtype.BvAndExpr}: bitwise and - {@link + * hu.bme.mit.theta.core.type.bvtype.BvOrExpr}: bitwise or - {@link + * hu.bme.mit.theta.core.type.bvtype.BvXorExpr}: bitwise xor - {@link + * hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr}: shift left - {@link + * hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr}: arithmetic shift right - {@link + * hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr}: logical shift right - {@link + * hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr}: rotate left - {@link + * hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr}: rotate right + * + *

- {@link hu.bme.mit.theta.core.type.bvtype.BvEqExpr}: equal - {@link + * hu.bme.mit.theta.core.type.bvtype.BvNeqExpr}: not equal - {@link + * hu.bme.mit.theta.core.type.bvtype.BvUGtExpr}: unsigned greater - {@link + * hu.bme.mit.theta.core.type.bvtype.BvULtExpr}: unsigned less - {@link + * hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr}: unsigned greater or equal - {@link + * hu.bme.mit.theta.core.type.bvtype.BvULeqExpr}: unsigned less or equal - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSGtExpr}: signed greater - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSLtExpr}: signed less - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr}: signed greater or equal - {@link + * hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr}: signed less or equal */ - -package hu.bme.mit.theta.core.type.bvtype; \ No newline at end of file +package hu.bme.mit.theta.core.type.bvtype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumEqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumEqExpr.java index 82e416ab7b..2533ead871 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumEqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumEqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.type.enumtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; @@ -22,8 +24,6 @@ import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public class EnumEqExpr extends EqExpr { private static final int HASH_SEED = 5326; @@ -73,6 +73,7 @@ public BoolType getType() { @Override public LitExpr eval(Valuation val) { - return EnumLitExpr.eq((EnumLitExpr) getLeftOp().eval(val), (EnumLitExpr) getRightOp().eval(val)); + return EnumLitExpr.eq( + (EnumLitExpr) getLeftOp().eval(val), (EnumLitExpr) getRightOp().eval(val)); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumLitExpr.java index e75d5e6c5e..906654db17 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.type.enumtype; +import static com.google.common.base.Preconditions.checkArgument; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import com.google.common.base.Objects; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; -import static com.google.common.base.Preconditions.checkArgument; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public final class EnumLitExpr extends NullaryExpr implements LitExpr { private final EnumType type; @@ -36,7 +36,11 @@ private EnumLitExpr(EnumType type, String value) { public static EnumLitExpr of(EnumType type, String literalName) { String value = EnumType.getShortName(literalName); - checkArgument(type.getValues().contains(value), "Invalid value %s for type %s", value, type.getName()); + checkArgument( + type.getValues().contains(value), + "Invalid value %s for type %s", + value, + type.getName()); return new EnumLitExpr(type, value); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumNeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumNeqExpr.java index f9cd0e1cb1..95ad1357f4 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumNeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumNeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.type.enumtype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; @@ -22,8 +24,6 @@ import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public final class EnumNeqExpr extends NeqExpr { private static final int HASH_SEED = 7212; @@ -73,6 +73,7 @@ public BoolType getType() { @Override public LitExpr eval(Valuation val) { - return EnumLitExpr.neq((EnumLitExpr) getLeftOp().eval(val), (EnumLitExpr) getRightOp().eval(val)); + return EnumLitExpr.neq( + (EnumLitExpr) getLeftOp().eval(val), (EnumLitExpr) getRightOp().eval(val)); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumType.java index b8367c430c..58a1c30b79 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/enumtype/EnumType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAbsExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAbsExpr.java index a6a991066a..ca5e0567a8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAbsExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAbsExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; - public class FpAbsExpr extends UnaryExpr { private static final int HASH_SEED = 6666; @@ -86,4 +86,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAddExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAddExpr.java index 4b62d4eb1e..7793314b71 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAddExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAddExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.AddExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public class FpAddExpr extends AddExpr { private static final int HASH_SEED = 6588; @@ -33,24 +32,24 @@ public class FpAddExpr extends AddExpr { private final FpRoundingMode roundingMode; - private FpAddExpr(final FpRoundingMode roundingMode, - final Iterable> ops) { + private FpAddExpr( + final FpRoundingMode roundingMode, final Iterable> ops) { super(ops); checkAllTypesEqual(ops); checkNotNull(roundingMode); this.roundingMode = roundingMode; } - public static FpAddExpr of(final FpRoundingMode roundingMode, - final Iterable> ops) { + public static FpAddExpr of( + final FpRoundingMode roundingMode, final Iterable> ops) { return new FpAddExpr(roundingMode, ops); } - public static FpAddExpr create(final FpRoundingMode roundingMode, - final List> ops) { + public static FpAddExpr create( + final FpRoundingMode roundingMode, final List> ops) { checkNotNull(ops); - return FpAddExpr.of(roundingMode, - ops.stream().map(TypeUtils::castFp).collect(toImmutableList())); + return FpAddExpr.of( + roundingMode, ops.stream().map(TypeUtils::castFp).collect(toImmutableList())); } public FpRoundingMode getRoundingMode() { @@ -64,11 +63,12 @@ public FpType getType() { @Override public FpLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (FpLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.add(roundingMode, (FpLitExpr) op2.eval(val))), - (op1, op2) -> (op1.add(roundingMode, op2)) - ); + return getOps().stream() + .skip(1) + .reduce( + (FpLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.add(roundingMode, (FpLitExpr) op2.eval(val))), + (op1, op2) -> (op1.add(roundingMode, op2))); } @Override @@ -102,4 +102,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAssignExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAssignExpr.java index 8b797fcb2f..d5cb83f45f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAssignExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpAssignExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpAssignExpr extends EqExpr { private static final int HASH_SEED = 1747; @@ -84,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpAssignExpr that = (FpAssignExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpDivExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpDivExpr.java index 144d5c797a..c3f9f23a97 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpDivExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpDivExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,30 +15,37 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.DivExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpDivExpr extends DivExpr { private static final int HASH_SEED = 1646; private static final String OPERATOR = "fpdiv"; private final FpRoundingMode roundingMode; - private FpDivExpr(final FpRoundingMode roundingMode, final Expr leftOp, final Expr rightOp) { + private FpDivExpr( + final FpRoundingMode roundingMode, + final Expr leftOp, + final Expr rightOp) { super(leftOp, rightOp); checkAllTypesEqual(leftOp, rightOp); this.roundingMode = roundingMode; } - public static FpDivExpr of(final FpRoundingMode roundingMode, final Expr leftOp, final Expr rightOp) { + public static FpDivExpr of( + final FpRoundingMode roundingMode, + final Expr leftOp, + final Expr rightOp) { return new FpDivExpr(roundingMode, leftOp, rightOp); } - public static FpDivExpr create(final FpRoundingMode roundingMode, final Expr leftOp, final Expr rightOp) { + public static FpDivExpr create( + final FpRoundingMode roundingMode, final Expr leftOp, final Expr rightOp) { final Expr newLeftOp = castFp(leftOp); final Expr newRightOp = castFp(rightOp); return FpDivExpr.of(roundingMode, newLeftOp, newRightOp); @@ -86,7 +93,9 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpDivExpr that = (FpDivExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp().equals(that.getRightOp()) && roundingMode == that.roundingMode; + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()) + && roundingMode == that.roundingMode; } else { return false; } @@ -102,4 +111,3 @@ public String getOperatorLabel() { return OPERATOR + "[" + roundingMode.name().toLowerCase() + "]"; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpEqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpEqExpr.java index 1b4391a116..217b01d16e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpEqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpEqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpEqExpr extends EqExpr { private static final int HASH_SEED = 1746; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpEqExpr that = (FpEqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpExprs.java index 785da24959..38c449bf53 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.fptype; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; import hu.bme.mit.theta.core.type.bvtype.BvType; - import java.util.Arrays; public final class FpExprs { - private FpExprs() { - } + private FpExprs() {} public static FpType FpType(final int exponent, final int significand) { return FpType.of(exponent, significand); @@ -80,13 +77,15 @@ public static FpLitExpr NegativeZero(final FpType fpType) { return Fp(true, BvLitExpr.of(exponent), BvLitExpr.of(significand)); } - public static FpAddExpr Add(final FpRoundingMode roundingMode, - final Iterable> ops) { + public static FpAddExpr Add( + final FpRoundingMode roundingMode, final Iterable> ops) { return FpAddExpr.of(roundingMode, ops); } - public static FpSubExpr Sub(final FpRoundingMode roundingMode, final Expr leftOp, - final Expr rightOp) { + public static FpSubExpr Sub( + final FpRoundingMode roundingMode, + final Expr leftOp, + final Expr rightOp) { return FpSubExpr.of(roundingMode, leftOp, rightOp); } @@ -98,13 +97,15 @@ public static FpNegExpr Neg(final Expr op) { return FpNegExpr.of(op); } - public static FpMulExpr Mul(final FpRoundingMode roundingMode, - final Iterable> ops) { + public static FpMulExpr Mul( + final FpRoundingMode roundingMode, final Iterable> ops) { return FpMulExpr.of(roundingMode, ops); } - public static FpDivExpr Div(final FpRoundingMode roundingMode, final Expr leftOp, - final Expr rightOp) { + public static FpDivExpr Div( + final FpRoundingMode roundingMode, + final Expr leftOp, + final Expr rightOp) { return FpDivExpr.of(roundingMode, leftOp, rightOp); } @@ -116,8 +117,11 @@ public static FpAbsExpr Abs(final Expr op) { return FpAbsExpr.of(op); } - public static FpFromBvExpr FromBv(final FpRoundingMode roundingMode, final Expr op, - final FpType fpType, final boolean signed) { + public static FpFromBvExpr FromBv( + final FpRoundingMode roundingMode, + final Expr op, + final FpType fpType, + final boolean signed) { return FpFromBvExpr.of(roundingMode, op, fpType, signed); } @@ -157,8 +161,8 @@ public static FpIsInfiniteExpr IsInfinite(final Expr op) { return FpIsInfiniteExpr.of(op); } - public static FpRoundToIntegralExpr RoundToIntegral(final FpRoundingMode roundingMode, - final Expr op) { + public static FpRoundToIntegralExpr RoundToIntegral( + final FpRoundingMode roundingMode, final Expr op) { return FpRoundToIntegralExpr.of(roundingMode, op); } @@ -174,13 +178,19 @@ public static FpMinExpr Min(final Expr leftOp, final Expr rightO return FpMinExpr.of(leftOp, rightOp); } - public static FpToBvExpr ToBv(final FpRoundingMode roundingMode, final Expr op, - final int size, final boolean sgn) { + public static FpToBvExpr ToBv( + final FpRoundingMode roundingMode, + final Expr op, + final int size, + final boolean sgn) { return FpToBvExpr.of(roundingMode, op, size, sgn); } - public static FpToFpExpr ToFp(final FpRoundingMode roundingMode, final Expr op, - final int exp, final int sig) { + public static FpToFpExpr ToFp( + final FpRoundingMode roundingMode, + final Expr op, + final int exp, + final int sig) { return FpToFpExpr.of(roundingMode, op, exp, sig); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpFromBvExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpFromBvExpr.java index aa4fc710bd..ec213f5af1 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpFromBvExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpFromBvExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; @@ -25,8 +27,6 @@ import org.kframework.mpfr.BigFloat; import org.kframework.mpfr.BinaryMathContext; -import static com.google.common.base.Preconditions.checkNotNull; - public class FpFromBvExpr extends UnaryExpr { private static final int HASH_SEED = 6696; @@ -36,8 +36,11 @@ public class FpFromBvExpr extends UnaryExpr { private final FpType fpType; private final boolean signed; - private FpFromBvExpr(final FpRoundingMode roundingMode, final Expr op, - final FpType fpType, final boolean signed) { + private FpFromBvExpr( + final FpRoundingMode roundingMode, + final Expr op, + final FpType fpType, + final boolean signed) { super(op); this.fpType = fpType; this.signed = signed; @@ -45,13 +48,19 @@ private FpFromBvExpr(final FpRoundingMode roundingMode, final Expr op, this.roundingMode = roundingMode; } - public static FpFromBvExpr of(final FpRoundingMode roundingMode, final Expr op, - final FpType fpType, final boolean signed) { + public static FpFromBvExpr of( + final FpRoundingMode roundingMode, + final Expr op, + final FpType fpType, + final boolean signed) { return new FpFromBvExpr(roundingMode, op, fpType, signed); } - public static FpFromBvExpr create(final FpRoundingMode roundingMode, final Expr op, - final FpType fpType, final boolean signed) { + public static FpFromBvExpr create( + final FpRoundingMode roundingMode, + final Expr op, + final FpType fpType, + final boolean signed) { return FpFromBvExpr.of(roundingMode, op, fpType, signed); } @@ -76,9 +85,13 @@ public FpType getType() { public FpLitExpr eval(Valuation val) { BinaryMathContext mathContext = FpUtils.getMathContext(fpType, roundingMode); BvLitExpr eval = (BvLitExpr) getOp().eval(val); - return FpUtils.bigFloatToFpLitExpr(new BigFloat( - signed ? BvUtils.signedBvLitExprToBigInteger(eval) - : BvUtils.unsignedBvLitExprToBigInteger(eval), mathContext), fpType); + return FpUtils.bigFloatToFpLitExpr( + new BigFloat( + signed + ? BvUtils.signedBvLitExprToBigInteger(eval) + : BvUtils.unsignedBvLitExprToBigInteger(eval), + mathContext), + fpType); } @Override @@ -87,14 +100,14 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && obj.getClass() == this.getClass()) { final FpFromBvExpr that = (FpFromBvExpr) obj; - return this.getOp().equals(that.getOp()) && fpType.equals(that.fpType) + return this.getOp().equals(that.getOp()) + && fpType.equals(that.fpType) && roundingMode.equals(that.roundingMode); } else { return false; } } - @Override public FpFromBvExpr with(Expr op) { return new FpFromBvExpr(roundingMode, op, fpType, signed); @@ -105,7 +118,13 @@ protected int getHashSeed() { } public String getOperatorLabel() { - return OPERATOR_LABEL + "[" + fpType.getExponent() + "," + fpType.getSignificand() + "][" + (isSigned() ? "s" : "u") + "]"; + return OPERATOR_LABEL + + "[" + + fpType.getExponent() + + "," + + fpType.getSignificand() + + "][" + + (isSigned() ? "s" : "u") + + "]"; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGeqExpr.java index 238449ca80..916328d31b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.GeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpGeqExpr extends GeqExpr { private static final int HASH_SEED = 1647; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpGeqExpr that = (FpGeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGtExpr.java index 60ddb7ef5c..7eaca72c4b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpGtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.GtExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpGtExpr extends GtExpr { private static final int HASH_SEED = 1648; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpGtExpr that = (FpGtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsInfiniteExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsInfiniteExpr.java index e92fb7defe..4bbdb7557c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsInfiniteExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsInfiniteExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; @@ -23,11 +27,6 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.booltype.OrExpr; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpIsInfiniteExpr extends UnaryExpr { private static final int HASH_SEED = 1756; @@ -92,4 +91,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsNanExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsNanExpr.java index c5824df3ed..9a95a85d7f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsNanExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpIsNanExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpIsNanExpr extends UnaryExpr { private static final int HASH_SEED = 1786; @@ -87,4 +87,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLeqExpr.java index 1d9cda2467..2576f3fccf 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.LeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpLeqExpr extends LeqExpr { private static final int HASH_SEED = 1649; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpLeqExpr that = (FpLeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLitExpr.java index 062f457a9e..4ca92763e9 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,12 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.FpUtils.bigFloatToFpLitExpr; +import static hu.bme.mit.theta.core.utils.FpUtils.fpLitExprToBigFloat; +import static hu.bme.mit.theta.core.utils.FpUtils.getMathContext; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; @@ -22,15 +28,8 @@ import hu.bme.mit.theta.core.type.booltype.BoolExprs; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; - import java.util.Arrays; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.FpUtils.bigFloatToFpLitExpr; -import static hu.bme.mit.theta.core.utils.FpUtils.fpLitExprToBigFloat; -import static hu.bme.mit.theta.core.utils.FpUtils.getMathContext; - public class FpLitExpr extends NullaryExpr implements LitExpr, Comparable { private static final int HASH_SEED = 4254; private final boolean hidden; @@ -47,7 +46,8 @@ private FpLitExpr(final boolean hidden, final BvLitExpr exponent, final BvLitExp this.significand = significand; } - public static FpLitExpr of(final boolean hidden, final BvLitExpr exponent, final BvLitExpr significand) { + public static FpLitExpr of( + final boolean hidden, final BvLitExpr exponent, final BvLitExpr significand) { return new FpLitExpr(hidden, exponent, significand); } @@ -57,15 +57,17 @@ public static FpLitExpr of(final BvLitExpr value, final FpType fpType) { return new FpLitExpr( literal[0], BvLitExpr.of(Arrays.copyOfRange(literal, 1, fpType.getExponent() + 1)), - BvLitExpr.of(Arrays.copyOfRange(literal, fpType.getExponent() + 1, fpType.getExponent() + fpType.getSignificand() + 1))); + BvLitExpr.of( + Arrays.copyOfRange( + literal, + fpType.getExponent() + 1, + fpType.getExponent() + fpType.getSignificand() + 1))); } - public static FpLitExpr of(final BvLitExpr hidden, final BvLitExpr exponent, final BvLitExpr significand) { + public static FpLitExpr of( + final BvLitExpr hidden, final BvLitExpr exponent, final BvLitExpr significand) { boolean[] hiddenLit = hidden.getValue(); - return new FpLitExpr( - hiddenLit[0], - exponent, - significand); + return new FpLitExpr(hiddenLit[0], exponent, significand); } public boolean getHidden() { @@ -138,13 +140,21 @@ public boolean isPositiveZero() { public FpLitExpr add(final FpRoundingMode roundingMode, final FpLitExpr that) { checkArgument(this.getType().equals(that.getType())); - var sum = fpLitExprToBigFloat(roundingMode, this).add(fpLitExprToBigFloat(roundingMode, that), getMathContext(this.getType(), roundingMode)); + var sum = + fpLitExprToBigFloat(roundingMode, this) + .add( + fpLitExprToBigFloat(roundingMode, that), + getMathContext(this.getType(), roundingMode)); return bigFloatToFpLitExpr(sum, getType()); } public FpLitExpr sub(final FpRoundingMode roundingMode, final FpLitExpr that) { checkArgument(this.getType().equals(that.getType())); - var sub = fpLitExprToBigFloat(roundingMode, this).subtract(fpLitExprToBigFloat(roundingMode, that), getMathContext(this.getType(), roundingMode)); + var sub = + fpLitExprToBigFloat(roundingMode, this) + .subtract( + fpLitExprToBigFloat(roundingMode, that), + getMathContext(this.getType(), roundingMode)); return bigFloatToFpLitExpr(sub, getType()); } @@ -159,13 +169,21 @@ public FpLitExpr neg() { public FpLitExpr mul(final FpRoundingMode roundingMode, final FpLitExpr that) { checkArgument(this.getType().equals(that.getType())); - var sub = fpLitExprToBigFloat(roundingMode, this).multiply(fpLitExprToBigFloat(roundingMode, that), getMathContext(this.getType(), roundingMode)); + var sub = + fpLitExprToBigFloat(roundingMode, this) + .multiply( + fpLitExprToBigFloat(roundingMode, that), + getMathContext(this.getType(), roundingMode)); return bigFloatToFpLitExpr(sub, getType()); } public FpLitExpr div(final FpRoundingMode roundingMode, final FpLitExpr that) { checkArgument(this.getType().equals(that.getType())); - var sub = fpLitExprToBigFloat(roundingMode, this).divide(fpLitExprToBigFloat(roundingMode, that), getMathContext(this.getType(), roundingMode)); + var sub = + fpLitExprToBigFloat(roundingMode, this) + .divide( + fpLitExprToBigFloat(roundingMode, that), + getMathContext(this.getType(), roundingMode)); return bigFloatToFpLitExpr(sub, getType()); } @@ -176,14 +194,20 @@ public BoolLitExpr eq(final FpLitExpr that) { if (left.isNaN() || right.isNaN()) { return BoolExprs.False(); } - return BoolExprs.Bool(this.hidden == that.hidden && this.exponent.equals(that.exponent) && this.significand.equals(that.significand)); + return BoolExprs.Bool( + this.hidden == that.hidden + && this.exponent.equals(that.exponent) + && this.significand.equals(that.significand)); } public BoolLitExpr assign(final FpLitExpr that) { checkArgument(this.getType().equals(that.getType())); var left = fpLitExprToBigFloat(FpRoundingMode.getDefaultRoundingMode(), this); var right = fpLitExprToBigFloat(FpRoundingMode.getDefaultRoundingMode(), that); - return BoolExprs.Bool(this.hidden == that.hidden && this.exponent.equals(that.exponent) && this.significand.equals(that.significand)); + return BoolExprs.Bool( + this.hidden == that.hidden + && this.exponent.equals(that.exponent) + && this.significand.equals(that.significand)); } public BoolLitExpr gt(final FpLitExpr that) { @@ -249,7 +273,10 @@ public BoolLitExpr neq(final FpLitExpr that) { if (left.isNaN() || right.isNaN()) { return BoolExprs.False(); } - return BoolExprs.Bool(!(this.hidden == that.hidden && this.exponent.equals(that.exponent) && this.significand.equals(that.significand))); + return BoolExprs.Bool( + !(this.hidden == that.hidden + && this.exponent.equals(that.exponent) + && this.significand.equals(that.significand))); } @Override @@ -277,10 +304,12 @@ public int hashCode() { @Override public boolean equals(final Object obj) { - if (obj != null && this.getClass() == obj.getClass() && getType().equals(((FpLitExpr) obj).getType())) { - return this.exponent.equals(((FpLitExpr) obj).exponent) && - this.hidden == ((FpLitExpr) obj).hidden && - this.significand.equals(((FpLitExpr) obj).significand); + if (obj != null + && this.getClass() == obj.getClass() + && getType().equals(((FpLitExpr) obj).getType())) { + return this.exponent.equals(((FpLitExpr) obj).exponent) + && this.hidden == ((FpLitExpr) obj).hidden + && this.significand.equals(((FpLitExpr) obj).significand); } else { return false; } @@ -288,7 +317,10 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(hidden ? "#b1" : "#b0").add(exponent.toString()).add(significand.toString()).toString(); + return Utils.lispStringBuilder(hidden ? "#b1" : "#b0") + .add(exponent.toString()) + .add(significand.toString()) + .toString(); } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLtExpr.java index 81c21c54e5..7e9c2847f9 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpLtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.LtExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpLtExpr extends LtExpr { private static final int HASH_SEED = 1745; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpLtExpr that = (FpLtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMaxExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMaxExpr.java index d57d0ae29f..3e9e97137c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMaxExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMaxExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.utils.FpUtils; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public class FpMaxExpr extends BinaryExpr { private static final int HASH_SEED = 6668; @@ -86,8 +86,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpMaxExpr that = (FpMaxExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -105,4 +105,3 @@ public LitExpr eval(Valuation val) { } } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMinExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMinExpr.java index 98e387d753..f78442635f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMinExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMinExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.utils.FpUtils; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public class FpMinExpr extends BinaryExpr { private static final int HASH_SEED = 6667; @@ -86,8 +86,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpMinExpr that = (FpMinExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -105,4 +105,3 @@ public LitExpr eval(Valuation val) { } } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMulExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMulExpr.java index 7eac2247b1..50ad817027 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMulExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpMulExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.MulExpr; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public class FpMulExpr extends MulExpr { private static final int HASH_SEED = 4276; @@ -33,24 +32,24 @@ public class FpMulExpr extends MulExpr { private final FpRoundingMode roundingMode; - private FpMulExpr(final FpRoundingMode roundingMode, - final Iterable> ops) { + private FpMulExpr( + final FpRoundingMode roundingMode, final Iterable> ops) { super(ops); checkAllTypesEqual(ops); checkNotNull(roundingMode); this.roundingMode = roundingMode; } - public static FpMulExpr of(final FpRoundingMode roundingMode, - final Iterable> ops) { + public static FpMulExpr of( + final FpRoundingMode roundingMode, final Iterable> ops) { return new FpMulExpr(roundingMode, ops); } - public static FpMulExpr create(final FpRoundingMode roundingMode, - final List> ops) { + public static FpMulExpr create( + final FpRoundingMode roundingMode, final List> ops) { checkNotNull(ops); - return FpMulExpr.of(roundingMode, - ops.stream().map(TypeUtils::castFp).collect(toImmutableList())); + return FpMulExpr.of( + roundingMode, ops.stream().map(TypeUtils::castFp).collect(toImmutableList())); } public FpRoundingMode getRoundingMode() { @@ -64,11 +63,12 @@ public FpType getType() { @Override public FpLitExpr eval(final Valuation val) { - return getOps().stream().skip(1).reduce( - (FpLitExpr) getOps().get(0).eval(val), - (op1, op2) -> (op1.mul(roundingMode, (FpLitExpr) op2.eval(val))), - (op1, op2) -> (op1.mul(roundingMode, op2)) - ); + return getOps().stream() + .skip(1) + .reduce( + (FpLitExpr) getOps().get(0).eval(val), + (op1, op2) -> (op1.mul(roundingMode, (FpLitExpr) op2.eval(val))), + (op1, op2) -> (op1.mul(roundingMode, op2))); } @Override @@ -102,4 +102,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNegExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNegExpr.java index dc0174b261..dbe07ef320 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNegExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNegExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NegExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; - public final class FpNegExpr extends NegExpr { private static final int HASH_SEED = 4622; @@ -80,5 +80,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNeqExpr.java index 26ae54cb57..a0cafbd3b1 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpNeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpNeqExpr extends NeqExpr { private static final int HASH_SEED = 7646; @@ -83,8 +83,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpNeqExpr that = (FpNeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpPosExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpPosExpr.java index 50ae422155..5252cfd7b2 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpPosExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpPosExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.PosExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; - public final class FpPosExpr extends PosExpr { private static final int HASH_SEED = 9424; @@ -80,5 +80,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRemExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRemExpr.java index 16e63370ad..d7c00578e2 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRemExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRemExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.utils.FpUtils; import org.kframework.mpfr.BigFloat; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpRemExpr extends BinaryExpr { private static final int HASH_SEED = 6670; @@ -56,14 +56,13 @@ public FpLitExpr eval(final Valuation val) { final FpLitExpr rightOpVal = (FpLitExpr) getRightOp().eval(val); BigFloat leftFloat = FpUtils.fpLitExprToBigFloat(null, leftOpVal); BigFloat rightFloat = FpUtils.fpLitExprToBigFloat(null, rightOpVal); - BigFloat remainder = leftFloat.remainder(rightFloat, - FpUtils.getMathContext(this.getType(), null)); + BigFloat remainder = + leftFloat.remainder(rightFloat, FpUtils.getMathContext(this.getType(), null)); return FpUtils.bigFloatToFpLitExpr(remainder, this.getType()); } @Override - public FpRemExpr with(final Expr leftOp, final Expr rightOp) { if (leftOp == getLeftOp() && rightOp == getRightOp()) { return this; @@ -88,8 +87,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpRemExpr that = (FpRemExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -104,6 +103,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundToIntegralExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundToIntegralExpr.java index 7b327b4a85..491c621864 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundToIntegralExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundToIntegralExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; import hu.bme.mit.theta.core.utils.FpUtils; +import java.math.BigInteger; import org.kframework.mpfr.BigFloat; import org.kframework.mpfr.BinaryMathContext; -import java.math.BigInteger; - -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; - public class FpRoundToIntegralExpr extends UnaryExpr { // round to integral private static final int HASH_SEED = 6671; @@ -63,9 +62,12 @@ public FpLitExpr eval(Valuation val) { final FpLitExpr opVal = (FpLitExpr) getOp().eval(val); BigFloat value = FpUtils.fpLitExprToBigFloat(roundingMode, opVal); BigInteger bigInteger = value.toBigInteger(); - BigFloat round = value.round( - new BinaryMathContext(bigInteger.bitLength(), opVal.getType().getExponent(), - FpUtils.getMathContextRoundingMode(roundingMode))); + BigFloat round = + value.round( + new BinaryMathContext( + bigInteger.bitLength(), + opVal.getType().getExponent(), + FpUtils.getMathContextRoundingMode(roundingMode))); round = round.round(FpUtils.getMathContext(getType(), roundingMode)); FpLitExpr fpLitExpr = FpUtils.bigFloatToFpLitExpr(round, this.getType()); return fpLitExpr; @@ -102,4 +104,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL + "[" + roundingMode.toString() + "]"; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundingMode.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundingMode.java index 72e51e4e34..fc0b568c1d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundingMode.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpRoundingMode.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,4 +26,3 @@ public static FpRoundingMode getDefaultRoundingMode() { return RNE; /* Default because it is default in the C standard */ } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSqrtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSqrtExpr.java index 7234390072..4deb866ccb 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSqrtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSqrtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; @@ -22,9 +25,6 @@ import hu.bme.mit.theta.core.utils.FpUtils; import org.kframework.mpfr.BigFloat; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; - public class FpSqrtExpr extends UnaryExpr { private static final int HASH_SEED = 6669; @@ -59,8 +59,9 @@ public FpType getType() { @Override public LitExpr eval(Valuation val) { final FpLitExpr opVal = (FpLitExpr) getOp().eval(val); - BigFloat sqrt = FpUtils.fpLitExprToBigFloat(roundingMode, opVal) - .sqrt(FpUtils.getMathContext(getType(), roundingMode)); + BigFloat sqrt = + FpUtils.fpLitExprToBigFloat(roundingMode, opVal) + .sqrt(FpUtils.getMathContext(getType(), roundingMode)); return FpUtils.bigFloatToFpLitExpr(sqrt, getType()); } @@ -95,4 +96,3 @@ public String getOperatorLabel() { return OPERATOR_LABEL; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSubExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSubExpr.java index 6570a4865a..0109195ac7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSubExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpSubExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; +import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.SubExpr; -import static hu.bme.mit.theta.core.utils.TypeUtils.castFp; -import static hu.bme.mit.theta.core.utils.TypeUtils.checkAllTypesEqual; - public final class FpSubExpr extends SubExpr { private static final int HASH_SEED = 2498; @@ -29,20 +29,24 @@ public final class FpSubExpr extends SubExpr { private final FpRoundingMode roundingMode; - private FpSubExpr(final FpRoundingMode roundingMode, final Expr leftOp, - final Expr rightOp) { + private FpSubExpr( + final FpRoundingMode roundingMode, + final Expr leftOp, + final Expr rightOp) { super(leftOp, rightOp); checkAllTypesEqual(leftOp, rightOp); this.roundingMode = roundingMode; } - public static FpSubExpr of(final FpRoundingMode roundingMode, final Expr leftOp, - final Expr rightOp) { + public static FpSubExpr of( + final FpRoundingMode roundingMode, + final Expr leftOp, + final Expr rightOp) { return new FpSubExpr(roundingMode, leftOp, rightOp); } - public static FpSubExpr create(final FpRoundingMode roundingMode, final Expr leftOp, - final Expr rightOp) { + public static FpSubExpr create( + final FpRoundingMode roundingMode, final Expr leftOp, final Expr rightOp) { final Expr newLeftOp = castFp(leftOp); final Expr newRightOp = castFp(rightOp); return FpSubExpr.of(roundingMode, newLeftOp, newRightOp); @@ -90,8 +94,9 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpSubExpr that = (FpSubExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()) && roundingMode == that.roundingMode; + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()) + && roundingMode == that.roundingMode; } else { return false; } @@ -107,4 +112,3 @@ public String getOperatorLabel() { return OPERATOR; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToBvExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToBvExpr.java index 0a22631eb2..2ff4baa121 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToBvExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToBvExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; @@ -22,14 +24,9 @@ import hu.bme.mit.theta.core.type.bvtype.BvType; import hu.bme.mit.theta.core.utils.BvUtils; import hu.bme.mit.theta.core.utils.FpUtils; - import java.math.BigInteger; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Sign and significand is presumed to be unsigned Exponent is presumed to be signed - */ +/** Sign and significand is presumed to be unsigned Exponent is presumed to be signed */ public class FpToBvExpr extends UnaryExpr { private static final int HASH_SEED = 6796; @@ -41,8 +38,11 @@ public class FpToBvExpr extends UnaryExpr { private final FpRoundingMode roundingMode; - private FpToBvExpr(final FpRoundingMode roundingMode, final Expr op, final int size, - final boolean sgn) { + private FpToBvExpr( + final FpRoundingMode roundingMode, + final Expr op, + final int size, + final boolean sgn) { super(op); checkNotNull(op); this.op = op; @@ -54,13 +54,19 @@ private FpToBvExpr(final FpRoundingMode roundingMode, final Expr op, fin this.roundingMode = roundingMode; } - public static FpToBvExpr of(final FpRoundingMode roundingMode, final Expr op, - final int size, final boolean sgn) { + public static FpToBvExpr of( + final FpRoundingMode roundingMode, + final Expr op, + final int size, + final boolean sgn) { return new FpToBvExpr(roundingMode, op, size, sgn); } - public static FpToBvExpr create(final FpRoundingMode roundingMode, final Expr op, - final int size, final boolean sgn) { + public static FpToBvExpr create( + final FpRoundingMode roundingMode, + final Expr op, + final int size, + final boolean sgn) { return FpToBvExpr.of(roundingMode, op, size, sgn); } @@ -104,7 +110,9 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpToBvExpr that = (FpToBvExpr) obj; - return this.getOp().equals(that.getOp()) && size == that.size && sgn == that.sgn + return this.getOp().equals(that.getOp()) + && size == that.size + && sgn == that.sgn && roundingMode.equals(that.roundingMode); } else { return false; @@ -120,7 +128,13 @@ public FpRoundingMode getRoundingMode() { } public String getOperatorLabel() { - return OPERATOR_LABEL + "[" + size + "'" + (sgn ? "s" : "u") + "][" + roundingMode.name() + "]"; + return OPERATOR_LABEL + + "[" + + size + + "'" + + (sgn ? "s" : "u") + + "][" + + roundingMode.name() + + "]"; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToFpExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToFpExpr.java index 64271976d6..1406cb86be 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToFpExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpToFpExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; import hu.bme.mit.theta.core.utils.FpUtils; import org.kframework.mpfr.BigFloat; -import static com.google.common.base.Preconditions.checkNotNull; - public class FpToFpExpr extends UnaryExpr { private static final int HASH_SEED = 6799; @@ -34,8 +34,11 @@ public class FpToFpExpr extends UnaryExpr { private final FpRoundingMode roundingMode; - private FpToFpExpr(final FpRoundingMode roundingMode, final Expr op, final int expBits, - final int signBits) { + private FpToFpExpr( + final FpRoundingMode roundingMode, + final Expr op, + final int expBits, + final int signBits) { super(op); checkNotNull(op); this.op = op; @@ -47,13 +50,19 @@ private FpToFpExpr(final FpRoundingMode roundingMode, final Expr op, fin this.roundingMode = roundingMode; } - public static FpToFpExpr of(final FpRoundingMode roundingMode, final Expr op, - final int exp, final int signBits) { + public static FpToFpExpr of( + final FpRoundingMode roundingMode, + final Expr op, + final int exp, + final int signBits) { return new FpToFpExpr(roundingMode, op, exp, signBits); } - public static FpToFpExpr create(final FpRoundingMode roundingMode, final Expr op, - final int exp, final int signBits) { + public static FpToFpExpr create( + final FpRoundingMode roundingMode, + final Expr op, + final int exp, + final int signBits) { return FpToFpExpr.of(roundingMode, op, exp, signBits); } @@ -93,8 +102,10 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FpToFpExpr that = (FpToFpExpr) obj; - return this.getOp().equals(that.getOp()) && expBits == that.expBits - && signBits == that.signBits && roundingMode.equals(that.roundingMode); + return this.getOp().equals(that.getOp()) + && expBits == that.expBits + && signBits == that.signBits + && roundingMode.equals(that.roundingMode); } else { return false; } @@ -112,4 +123,3 @@ public FpRoundingMode getRoundingMode() { return roundingMode; } } - diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpType.java index 5a9d50518c..0095fa1bcd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/fptype/FpType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.core.type.fptype; +import static com.google.common.base.Preconditions.checkArgument; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.DomainSize; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.*; - import java.math.BigInteger; -import static com.google.common.base.Preconditions.checkArgument; - -public class FpType implements Equational, Additive, Multiplicative, - Ordered { +public class FpType + implements Equational, Additive, Multiplicative, Ordered { - private final static int HASH_SEED = 5424; - private final static String TYPE_LABEL = "Fp"; + private static final int HASH_SEED = 5424; + private static final String TYPE_LABEL = "Fp"; private final int exponent; private final int significand; @@ -146,6 +145,7 @@ public GeqExpr Geq(Expr leftOp, Expr rightOp) { @Override public DomainSize getDomainSize() { - return DomainSize.of(BigInteger.TWO.pow(significand).multiply(BigInteger.TWO.pow(exponent))); + return DomainSize.of( + BigInteger.TWO.pow(significand).multiply(BigInteger.TWO.pow(exponent))); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncAppExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncAppExpr.java index 2fceca7444..516cbabcd4 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncAppExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncAppExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.core.type.functype; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - -public final class FuncAppExpr implements - Expr { +public final class FuncAppExpr + implements Expr { private static final int HASH_SEED = 7951; @@ -37,21 +36,23 @@ public final class FuncAppExpr private volatile int hashCode = 0; - private FuncAppExpr(final Expr> func, - final Expr param) { + private FuncAppExpr( + final Expr> func, final Expr param) { this.func = checkNotNull(func); this.param = checkNotNull(param); } - public static FuncAppExpr of( - final Expr> func, final Expr param) { + public static + FuncAppExpr of( + final Expr> func, final Expr param) { return new FuncAppExpr<>(func, param); } public static FuncAppExpr create( - final Expr func, - final Expr param) { - @SuppressWarnings("unchecked") final FuncType funcType = (FuncType) func.getType(); + final Expr func, final Expr param) { + @SuppressWarnings("unchecked") + final FuncType funcType = + (FuncType) func.getType(); final Expr> newFunc = cast(func, funcType); final Expr newParam = cast(param, funcType.getParamType()); return FuncAppExpr.of(newFunc, newParam); @@ -91,8 +92,8 @@ public Expr withOps(final List> ops) { return cast(create(ops.get(0), ops.get(1)), getType()); } - public FuncAppExpr with(final Expr> func, - final Expr param) { + public FuncAppExpr with( + final Expr> func, final Expr param) { if (this.func == func && this.param == param) { return this; } else { @@ -137,5 +138,4 @@ public boolean equals(final Object obj) { public String toString() { return Utils.lispStringBuilder().add(func).body().add(param).toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncExprs.java index c6fbfdf480..0c69f9b49f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,37 +15,41 @@ */ package hu.bme.mit.theta.core.type.functype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - public final class FuncExprs { - private FuncExprs() { - } + private FuncExprs() {} - public static FuncType Func( - final ParamType paramType, final ResultType resultType) { + public static + FuncType Func( + final ParamType paramType, final ResultType resultType) { return FuncType.of(paramType, resultType); } - public static FuncLitExpr Func( - final ParamDecl paramDecl, final Expr result) { + public static + FuncLitExpr Func( + final ParamDecl paramDecl, final Expr result) { return FuncLitExpr.of(paramDecl, result); } - public static FuncAppExpr App( - final Expr> func, final Expr param) { + public static + FuncAppExpr App( + final Expr> func, final Expr param) { return FuncAppExpr.of(func, param); } - private static FuncAppExpr App( - final Expr> func, final Expr paramHead, final List paramTail) { + private static + FuncAppExpr App( + final Expr> func, + final Expr paramHead, + final List paramTail) { if (!paramTail.isEmpty()) { final var newParamHead = paramTail.get(paramTail.size() - 1); final var newParamTail = paramTail.subList(0, paramTail.size() - 1); @@ -55,23 +59,34 @@ private static FuncAppExpr FuncAppExpr App( - final Expr> func, final List params) { + public static + FuncAppExpr App( + final Expr> func, final List params) { checkArgument(!params.isEmpty()); final var paramHead = params.get(params.size() - 1); final var paramTail = params.subList(0, params.size() - 1); return App(func, paramHead, paramTail); } - public static Expr UnsafeApp(final Expr func, final Expr param) { - checkState(func.getType() instanceof FuncType fFunc && fFunc.getParamType().equals(param.getType()), "Parameter of type " + param.getType() + " is not suitable for function of type " + func.getType()); + public static Expr UnsafeApp( + final Expr func, final Expr param) { + checkState( + func.getType() instanceof FuncType fFunc + && fFunc.getParamType().equals(param.getType()), + "Parameter of type " + + param.getType() + + " is not suitable for function of type " + + func.getType()); final Expr> funcTyped = (Expr>) func; final Expr paramTyped = (Expr) param; return App(funcTyped, paramTyped); } - public static Expr UnsafeApp(final Expr func, final List> param) { - checkState(func.getType() instanceof FuncType fFunc, "Supposed function is of type " + func.getType()); + public static Expr UnsafeApp( + final Expr func, final List> param) { + checkState( + func.getType() instanceof FuncType fFunc, + "Supposed function is of type " + func.getType()); final Expr> funcTyped = (Expr>) func; return App(funcTyped, param.stream().map(it -> (Expr) it).toList()); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncLitExpr.java index b9837046d4..3aaab9f791 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.core.type.functype; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.ParamDecl; @@ -23,13 +27,8 @@ import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.utils.TypeUtils; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; - public final class FuncLitExpr implements LitExpr> { @@ -46,8 +45,9 @@ private FuncLitExpr(final ParamDecl param, final Expr res this.result = checkNotNull(result); } - public static FuncLitExpr of( - final ParamDecl param, final Expr result) { + public static + FuncLitExpr of( + final ParamDecl param, final Expr result) { return new FuncLitExpr<>(param, result); } @@ -113,8 +113,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FuncLitExpr that = (FuncLitExpr) obj; - return this.getParam().equals(that.getParam()) && this.getResult() - .equals(that.getResult()); + return this.getParam().equals(that.getParam()) + && this.getResult().equals(that.getResult()); } else { return false; } @@ -123,7 +123,10 @@ public boolean equals(final Object obj) { @Override public String toString() { final String paramString = String.format("(%s %s)", param.getName(), param.getType()); - return Utils.lispStringBuilder(OPERATOR_LABEL).body().add(paramString).add(result).toString(); + return Utils.lispStringBuilder(OPERATOR_LABEL) + .body() + .add(paramString) + .add(result) + .toString(); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncType.java index a1f2d7becd..0f61b026cc 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/functype/FuncType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.functype; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.DomainSize; import hu.bme.mit.theta.core.type.Type; -import static com.google.common.base.Preconditions.checkNotNull; - public final class FuncType implements Type { - private final static int HASH_SEED = 3931; - private final static String TYPE_LABEL = "Func"; + private static final int HASH_SEED = 3931; + private static final String TYPE_LABEL = "Func"; private final ParamType paramType; private final ResultType resultType; @@ -36,8 +36,9 @@ private FuncType(final ParamType paramType, final ResultType resultType) { this.resultType = checkNotNull(resultType); } - public static FuncType of( - final ParamType paramType, final ResultType resultType) { + public static + FuncType of( + final ParamType paramType, final ResultType resultType) { return new FuncType<>(paramType, resultType); } @@ -67,8 +68,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final FuncType that = (FuncType) obj; - return this.getParamType().equals(that.getParamType()) && this.getResultType() - .equals(that.getResultType()); + return this.getParamType().equals(that.getParamType()) + && this.getResultType().equals(that.getResultType()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntAddExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntAddExpr.java index c815158a5b..0302063837 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntAddExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntAddExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.AddExpr; - import java.math.BigInteger; import java.util.List; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntAddExpr extends AddExpr { private static final int HASH_SEED = 5653; @@ -88,5 +87,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntDivExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntDivExpr.java index c3835e5629..ea68a4f0ef 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntDivExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntDivExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.DivExpr; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntDivExpr extends DivExpr { private static final int HASH_SEED = 79; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntDivExpr that = (IntDivExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -95,5 +95,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntEqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntEqExpr.java index ea893fa818..825f429f46 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntEqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntEqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntEqExpr extends EqExpr { private static final int HASH_SEED = 2777; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntEqExpr that = (IntEqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntExprs.java index 02b53782ef..1ef69c8cf5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,15 +16,12 @@ package hu.bme.mit.theta.core.type.inttype; import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.core.type.Expr; - import java.math.BigInteger; public final class IntExprs { - private IntExprs() { - } + private IntExprs() {} public static IntType Int() { return IntType.getInstance(); @@ -110,20 +107,25 @@ public static IntAddExpr Add(final Expr op1, final Expr op2) { return IntAddExpr.of(ImmutableList.of(op1, op2)); } - public static IntAddExpr Add(final Expr op1, final Expr op2, - final Expr op3) { + public static IntAddExpr Add( + final Expr op1, final Expr op2, final Expr op3) { return IntAddExpr.of(ImmutableList.of(op1, op2, op3)); } - public static IntAddExpr Add(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static IntAddExpr Add( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return IntAddExpr.of(ImmutableList.of(op1, op2, op3, op4)); } - public static IntAddExpr Add(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static IntAddExpr Add( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return IntAddExpr.of(ImmutableList.of(op1, op2, op3, op4, op5)); } @@ -133,21 +135,25 @@ public static IntMulExpr Mul(final Expr op1, final Expr op2) { return IntMulExpr.of(ImmutableList.of(op1, op2)); } - public static IntMulExpr Mul(final Expr op1, final Expr op2, - final Expr op3) { + public static IntMulExpr Mul( + final Expr op1, final Expr op2, final Expr op3) { return IntMulExpr.of(ImmutableList.of(op1, op2, op3)); } - public static IntMulExpr Mul(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static IntMulExpr Mul( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return IntMulExpr.of(ImmutableList.of(op1, op2, op3, op4)); } - public static IntMulExpr Mul(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static IntMulExpr Mul( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return IntMulExpr.of(ImmutableList.of(op1, op2, op3, op4, op5)); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGeqExpr.java index a6001e8a3b..92f24c78de 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.GeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntGeqExpr extends GeqExpr { private static final int HASH_SEED = 7649; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntGeqExpr that = (IntGeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGtExpr.java index 4993417ed0..fa6ff21239 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntGtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.GtExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntGtExpr extends GtExpr { private static final int HASH_SEED = 7349; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntGtExpr that = (IntGtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLeqExpr.java index 3a0e22c569..0f20b63c49 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.LeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntLeqExpr extends LeqExpr { private static final int HASH_SEED = 4673; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntLeqExpr that = (IntLeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLitExpr.java index 049939d35b..ddb5e064c9 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.rattype.RatLitExpr; - import java.math.BigInteger; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - -public final class IntLitExpr extends NullaryExpr implements LitExpr, - Comparable { +public final class IntLitExpr extends NullaryExpr + implements LitExpr, Comparable { private static final int HASH_SEED = 4111; private volatile int hashCode = 0; @@ -84,7 +83,8 @@ public IntLitExpr div(final IntLitExpr that) { // -5 div 3 = -2 // -5 div -3 = 2 var result = this.value.divide(that.value); - if (this.value.compareTo(BigInteger.ZERO) < 0 && this.value.mod(that.value.abs()).compareTo(BigInteger.ZERO) != 0) { + if (this.value.compareTo(BigInteger.ZERO) < 0 + && this.value.mod(that.value.abs()).compareTo(BigInteger.ZERO) != 0) { result = result.subtract(BigInteger.valueOf(that.value.signum())); } return IntLitExpr.of(result); @@ -190,5 +190,4 @@ public String toString() { public int compareTo(final IntLitExpr that) { return this.getValue().compareTo(that.getValue()); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLtExpr.java index 571bcd4aff..a1bd3fbe07 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntLtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.abstracttype.LtExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntLtExpr extends LtExpr { private static final int HASH_SEED = 9431; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntLtExpr that = (IntLtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntModExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntModExpr.java index 3d138e0dcc..f2b1d17948 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntModExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntModExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.ModExpr; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntModExpr extends ModExpr { private static final int HASH_SEED = 109; @@ -78,8 +78,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntModExpr that = (IntModExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -94,5 +94,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntMulExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntMulExpr.java index 2fee66cf9e..ff29c783fd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntMulExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntMulExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.MulExpr; - import java.math.BigInteger; import java.util.List; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntMulExpr extends MulExpr { private static final int HASH_SEED = 2707; @@ -88,5 +87,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNegExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNegExpr.java index 58d521438a..9f7166ef8a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNegExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNegExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NegExpr; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntNegExpr extends NegExpr { private static final int HASH_SEED = 3359; @@ -81,5 +81,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNeqExpr.java index bf84371c69..f9706e01d5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntNeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntNeqExpr extends NeqExpr { private static final int HASH_SEED = 9397; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntNeqExpr that = (IntNeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntPosExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntPosExpr.java index 034703f195..223199a3bb 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntPosExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntPosExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.PosExpr; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntPosExpr extends PosExpr { private static final int HASH_SEED = 3547; @@ -81,5 +81,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntRemExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntRemExpr.java index 79524440f5..ee807b4e83 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntRemExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntRemExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.RemExpr; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntRemExpr extends RemExpr { private static final int HASH_SEED = 199; @@ -79,8 +79,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntRemExpr that = (IntRemExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -95,5 +95,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntSubExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntSubExpr.java index d6543261bf..42d109340a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntSubExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntSubExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.SubExpr; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntSubExpr extends SubExpr { private static final int HASH_SEED = 4547; @@ -78,8 +78,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final IntSubExpr that = (IntSubExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -94,5 +94,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntToRatExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntToRatExpr.java index 25d6f15989..b5f58ad689 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntToRatExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntToRatExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.inttype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.CastExpr; import hu.bme.mit.theta.core.type.rattype.RatLitExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class IntToRatExpr extends CastExpr { private static final int HASH_SEED = 1627; @@ -84,5 +84,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntType.java index 15567f0fb9..9dd4ff99fd 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/IntType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,16 +28,19 @@ import hu.bme.mit.theta.core.type.abstracttype.RemExpr; import hu.bme.mit.theta.core.type.rattype.RatType; -public final class IntType implements Additive, Multiplicative, - Divisible, Equational, Ordered, - Castable { +public final class IntType + implements Additive, + Multiplicative, + Divisible, + Equational, + Ordered, + Castable { private static final IntType INSTANCE = new IntType(); private static final int HASH_SEED = 222670; private static final String TYPE_LABEL = "Int"; - private IntType() { - } + private IntType() {} public static IntType getInstance() { return INSTANCE; @@ -131,11 +134,11 @@ public IntGeqExpr Geq(final Expr leftOp, final Expr rightOp) { } @Override - public Expr Cast(final Expr op, - final TargetType type) { + public Expr Cast( + final Expr op, final TargetType type) { if (type instanceof RatType) { - @SuppressWarnings("unchecked") final Expr result = (Expr) IntExprs.ToRat( - op); + @SuppressWarnings("unchecked") + final Expr result = (Expr) IntExprs.ToRat(op); return result; } else { throw new ClassCastException("Int cannot be cast to " + type); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/package-info.java index f45f9e379c..01892d1e7c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/inttype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,28 +17,27 @@ * Integer type and its expressions. Use {@link hu.bme.mit.theta.core.type.inttype.IntExprs} to * create them. Note that this is a (mathematical) SMT integer, with an unbounded range (long in the * implementation) and no overflows. - *

- * - {@link hu.bme.mit.theta.core.type.inttype.IntType}: the actual integer type. - *

- * - {@link hu.bme.mit.theta.core.type.inttype.IntLitExpr}: integer literal - *

- * - {@link hu.bme.mit.theta.core.type.inttype.IntNegExpr}: unary minus - - * {@link hu.bme.mit.theta.core.type.inttype.IntPosExpr}: unary plus - - * {@link hu.bme.mit.theta.core.type.inttype.IntAddExpr}: addition - - * {@link hu.bme.mit.theta.core.type.inttype.IntSubExpr}: subtraction - - * {@link hu.bme.mit.theta.core.type.inttype.IntMulExpr}: multiplication - - * {@link hu.bme.mit.theta.core.type.inttype.IntDivExpr}: integer division - - * {@link hu.bme.mit.theta.core.type.inttype.IntModExpr}: modulus - - * {@link hu.bme.mit.theta.core.type.inttype.IntRemExpr}: remainder - *

- * - {@link hu.bme.mit.theta.core.type.inttype.IntEqExpr}: equal - - * {@link hu.bme.mit.theta.core.type.inttype.IntNegExpr}: not equal - - * {@link hu.bme.mit.theta.core.type.inttype.IntGtExpr}: greater - - * {@link hu.bme.mit.theta.core.type.inttype.IntLtExpr}: less - - * {@link hu.bme.mit.theta.core.type.inttype.IntGeqExpr}: greater or equal - - * {@link hu.bme.mit.theta.core.type.inttype.IntLeqExpr}: less or equal - *

- * - {@link hu.bme.mit.theta.core.type.inttype.IntToRatExpr}: cast to rational + * + *

- {@link hu.bme.mit.theta.core.type.inttype.IntType}: the actual integer type. + * + *

- {@link hu.bme.mit.theta.core.type.inttype.IntLitExpr}: integer literal + * + *

- {@link hu.bme.mit.theta.core.type.inttype.IntNegExpr}: unary minus - {@link + * hu.bme.mit.theta.core.type.inttype.IntPosExpr}: unary plus - {@link + * hu.bme.mit.theta.core.type.inttype.IntAddExpr}: addition - {@link + * hu.bme.mit.theta.core.type.inttype.IntSubExpr}: subtraction - {@link + * hu.bme.mit.theta.core.type.inttype.IntMulExpr}: multiplication - {@link + * hu.bme.mit.theta.core.type.inttype.IntDivExpr}: integer division - {@link + * hu.bme.mit.theta.core.type.inttype.IntModExpr}: modulus - {@link + * hu.bme.mit.theta.core.type.inttype.IntRemExpr}: remainder + * + *

- {@link hu.bme.mit.theta.core.type.inttype.IntEqExpr}: equal - {@link + * hu.bme.mit.theta.core.type.inttype.IntNegExpr}: not equal - {@link + * hu.bme.mit.theta.core.type.inttype.IntGtExpr}: greater - {@link + * hu.bme.mit.theta.core.type.inttype.IntLtExpr}: less - {@link + * hu.bme.mit.theta.core.type.inttype.IntGeqExpr}: greater or equal - {@link + * hu.bme.mit.theta.core.type.inttype.IntLeqExpr}: less or equal + * + *

- {@link hu.bme.mit.theta.core.type.inttype.IntToRatExpr}: cast to rational */ - -package hu.bme.mit.theta.core.type.inttype; \ No newline at end of file +package hu.bme.mit.theta.core.type.inttype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/package-info.java index dab1cf903c..c6dd8f7007 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,19 +17,18 @@ * This package contains types (e.g., Boolean, integer) and expressions operating over them (e.g., * Boolean connectives, arithmetic operations), grouped into subpackages. Constructors of the types * and expressions are usually package private. Use the factory classes instead. - *

- * - {@link hu.bme.mit.theta.core.type.Expr} is the main interface for expressions. - *

- * - {@link hu.bme.mit.theta.core.type.anytype} and {@link hu.bme.mit.theta.core.type.abstracttype} - * are expressions for multiple types (e.g., conditional). - - * {@link hu.bme.mit.theta.core.type.booltype} contains the Boolean type and expressions (e.g., and, - * or). - {@link hu.bme.mit.theta.core.type.bvtype} contains the (SMT) bitvector type and + * + *

- {@link hu.bme.mit.theta.core.type.Expr} is the main interface for expressions. + * + *

- {@link hu.bme.mit.theta.core.type.anytype} and {@link + * hu.bme.mit.theta.core.type.abstracttype} are expressions for multiple types (e.g., conditional). + * - {@link hu.bme.mit.theta.core.type.booltype} contains the Boolean type and expressions (e.g., + * and, or). - {@link hu.bme.mit.theta.core.type.bvtype} contains the (SMT) bitvector type and * expressions (e.g., bitwise and, shifts). - {@link hu.bme.mit.theta.core.type.inttype} contains - * the mathematical (SMT) integer type and expressions (e.g., add, multiply). - - * {@link hu.bme.mit.theta.core.type.rattype} contains the rational type and expression (e.g., - * division). - {@link hu.bme.mit.theta.core.type.arraytype} contains the SMT array type - * (associative mapping from a key type to a value type) and expressions (e.g., read, write). - - * {@link hu.bme.mit.theta.core.type.functype} contains the function type and expressions. + * the mathematical (SMT) integer type and expressions (e.g., add, multiply). - {@link + * hu.bme.mit.theta.core.type.rattype} contains the rational type and expression (e.g., division). - + * {@link hu.bme.mit.theta.core.type.arraytype} contains the SMT array type (associative mapping + * from a key type to a value type) and expressions (e.g., read, write). - {@link + * hu.bme.mit.theta.core.type.functype} contains the function type and expressions. */ - -package hu.bme.mit.theta.core.type; \ No newline at end of file +package hu.bme.mit.theta.core.type; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatAddExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatAddExpr.java index e4d4cc4109..217a7b3b38 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatAddExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatAddExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.AddExpr; - import java.math.BigInteger; import java.util.List; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatAddExpr extends AddExpr { private static final int HASH_SEED = 4909; @@ -94,5 +93,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatDivExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatDivExpr.java index cd6ae86f60..3ea6f47448 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatDivExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatDivExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.DivExpr; import hu.bme.mit.theta.core.type.inttype.IntToRatExpr; import hu.bme.mit.theta.core.type.inttype.IntType; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatDivExpr extends DivExpr { private static final int HASH_SEED = 139; @@ -97,8 +97,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatDivExpr that = (RatDivExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -113,5 +113,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatEqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatEqExpr.java index 20e92910f6..06caf929ba 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatEqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatEqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatEqExpr extends EqExpr { private static final int HASH_SEED = 3709; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatEqExpr that = (RatEqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatExprs.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatExprs.java index dac299d24d..ac20b0388e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatExprs.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatExprs.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,15 +16,12 @@ package hu.bme.mit.theta.core.type.rattype; import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.core.type.Expr; - import java.math.BigInteger; public final class RatExprs { - private RatExprs() { - } + private RatExprs() {} public static RatType Rat() { return RatType.getInstance(); @@ -122,20 +119,25 @@ public static RatAddExpr Add(final Expr op1, final Expr op2) { return RatAddExpr.of(ImmutableList.of(op1, op2)); } - public static RatAddExpr Add(final Expr op1, final Expr op2, - final Expr op3) { + public static RatAddExpr Add( + final Expr op1, final Expr op2, final Expr op3) { return RatAddExpr.of(ImmutableList.of(op1, op2, op3)); } - public static RatAddExpr Add(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static RatAddExpr Add( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return RatAddExpr.of(ImmutableList.of(op1, op2, op3, op4)); } - public static RatAddExpr Add(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static RatAddExpr Add( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return RatAddExpr.of(ImmutableList.of(op1, op2, op3, op4, op5)); } @@ -145,20 +147,25 @@ public static RatMulExpr Mul(final Expr op1, final Expr op2) { return RatMulExpr.of(ImmutableList.of(op1, op2)); } - public static RatMulExpr Mul(final Expr op1, final Expr op2, - final Expr op3) { + public static RatMulExpr Mul( + final Expr op1, final Expr op2, final Expr op3) { return RatMulExpr.of(ImmutableList.of(op1, op2, op3)); } - public static RatMulExpr Mul(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4) { + public static RatMulExpr Mul( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4) { return RatMulExpr.of(ImmutableList.of(op1, op2, op3, op4)); } - public static RatMulExpr Mul(final Expr op1, final Expr op2, - final Expr op3, - final Expr op4, final Expr op5) { + public static RatMulExpr Mul( + final Expr op1, + final Expr op2, + final Expr op3, + final Expr op4, + final Expr op5) { return RatMulExpr.of(ImmutableList.of(op1, op2, op3, op4, op5)); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGeqExpr.java index f7d77da129..fd85a817de 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.GeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatGeqExpr extends GeqExpr { private static final int HASH_SEED = 6101; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatGeqExpr that = (RatGeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGtExpr.java index d5a14cbec6..f82cbd198c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatGtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.GtExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatGtExpr extends GtExpr { private static final int HASH_SEED = 8161; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatGtExpr that = (RatGtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLeqExpr.java index daf9b662e1..11ac8d3c7d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.LeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatLeqExpr extends LeqExpr { private static final int HASH_SEED = 5479; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatLeqExpr that = (RatLeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLitExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLitExpr.java index 26a7bec745..7cc6540a0d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLitExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLitExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static com.google.common.base.Preconditions.checkArgument; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; - import java.math.BigInteger; -import static com.google.common.base.Preconditions.checkArgument; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - -public final class RatLitExpr extends NullaryExpr implements LitExpr, - Comparable { +public final class RatLitExpr extends NullaryExpr + implements LitExpr, Comparable { private static final int HASH_SEED = 149; @@ -94,12 +93,16 @@ public BigInteger ceil() { public RatLitExpr add(final RatLitExpr that) { return RatLitExpr.of( - this.getNum().multiply(that.getDenom()).add(this.getDenom().multiply(that.getNum())), + this.getNum() + .multiply(that.getDenom()) + .add(this.getDenom().multiply(that.getNum())), this.getDenom().multiply(that.getDenom())); } public RatLitExpr sub(final RatLitExpr that) { - return RatLitExpr.of(this.getNum().multiply(that.getDenom()) + return RatLitExpr.of( + this.getNum() + .multiply(that.getDenom()) .subtract(this.getDenom().multiply(that.getNum())), this.getDenom().multiply(that.getDenom())); } @@ -113,43 +116,57 @@ public RatLitExpr neg() { } public RatLitExpr mul(final RatLitExpr that) { - return RatLitExpr.of(this.getNum().multiply(that.getNum()), - this.getDenom().multiply(that.getDenom())); + return RatLitExpr.of( + this.getNum().multiply(that.getNum()), this.getDenom().multiply(that.getDenom())); } public RatLitExpr div(final RatLitExpr that) { - return RatLitExpr.of(this.getNum().multiply(that.getDenom()), - this.getDenom().multiply(that.getNum())); + return RatLitExpr.of( + this.getNum().multiply(that.getDenom()), this.getDenom().multiply(that.getNum())); } public BoolLitExpr eq(final RatLitExpr that) { - return Bool(this.getNum().compareTo(that.getNum()) == 0 - && this.getDenom().compareTo(that.getDenom()) == 0); + return Bool( + this.getNum().compareTo(that.getNum()) == 0 + && this.getDenom().compareTo(that.getDenom()) == 0); } public BoolLitExpr neq(final RatLitExpr that) { - return Bool(this.getNum().compareTo(that.getNum()) != 0 - || this.getDenom().compareTo(that.getDenom()) != 0); + return Bool( + this.getNum().compareTo(that.getNum()) != 0 + || this.getDenom().compareTo(that.getDenom()) != 0); } public BoolLitExpr lt(final RatLitExpr that) { - return Bool(this.getNum().multiply(that.getDenom()) - .compareTo(this.getDenom().multiply(that.getNum())) < 0); + return Bool( + this.getNum() + .multiply(that.getDenom()) + .compareTo(this.getDenom().multiply(that.getNum())) + < 0); } public BoolLitExpr leq(final RatLitExpr that) { - return Bool(this.getNum().multiply(that.getDenom()) - .compareTo(this.getDenom().multiply(that.getNum())) <= 0); + return Bool( + this.getNum() + .multiply(that.getDenom()) + .compareTo(this.getDenom().multiply(that.getNum())) + <= 0); } public BoolLitExpr gt(final RatLitExpr that) { - return Bool(this.getNum().multiply(that.getDenom()) - .compareTo(this.getDenom().multiply(that.getNum())) > 0); + return Bool( + this.getNum() + .multiply(that.getDenom()) + .compareTo(this.getDenom().multiply(that.getNum())) + > 0); } public BoolLitExpr geq(final RatLitExpr that) { - return Bool(this.getNum().multiply(that.getDenom()) - .compareTo(this.getDenom().multiply(that.getNum())) >= 0); + return Bool( + this.getNum() + .multiply(that.getDenom()) + .compareTo(this.getDenom().multiply(that.getNum())) + >= 0); } public RatLitExpr abs() { @@ -196,7 +213,8 @@ public String toString() { @Override public int compareTo(final RatLitExpr that) { - return this.getNum().multiply(that.getDenom()) + return this.getNum() + .multiply(that.getDenom()) .compareTo(this.getDenom().multiply(that.getNum())); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLtExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLtExpr.java index a708bea637..b8bdf550fa 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLtExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatLtExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.LtExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatLtExpr extends LtExpr { private static final int HASH_SEED = 6311; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatLtExpr that = (RatLtExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatMulExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatMulExpr.java index d69a384e9e..9663c45b12 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatMulExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatMulExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.MulExpr; - import java.math.BigInteger; import java.util.List; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatMulExpr extends MulExpr { private static final int HASH_SEED = 9479; @@ -90,5 +89,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNegExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNegExpr.java index 91b0896bc3..d6ffa6537f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNegExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNegExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NegExpr; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatNegExpr extends NegExpr { private static final int HASH_SEED = 4127; @@ -81,5 +81,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNeqExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNeqExpr.java index 93c5107a13..974061e667 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNeqExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatNeqExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.NeqExpr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatNeqExpr extends NeqExpr { private static final int HASH_SEED = 1997; @@ -81,8 +81,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatNeqExpr that = (RatNeqExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -97,5 +97,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatPosExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatPosExpr.java index 0732d27b0a..62192436c7 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatPosExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatPosExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.PosExpr; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatPosExpr extends PosExpr { private static final int HASH_SEED = 4827; @@ -81,5 +81,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatSubExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatSubExpr.java index e43b56dde4..805670f434 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatSubExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatSubExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.SubExpr; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatSubExpr extends SubExpr { private static final int HASH_SEED = 6287; @@ -78,8 +78,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final RatSubExpr that = (RatSubExpr) obj; - return this.getLeftOp().equals(that.getLeftOp()) && this.getRightOp() - .equals(that.getRightOp()); + return this.getLeftOp().equals(that.getLeftOp()) + && this.getRightOp().equals(that.getRightOp()); } else { return false; } @@ -94,5 +94,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatToIntExpr.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatToIntExpr.java index 698626b36a..90648969c4 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatToIntExpr.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatToIntExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,16 @@ */ package hu.bme.mit.theta.core.type.rattype; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.UnaryExpr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; import hu.bme.mit.theta.core.type.inttype.IntType; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public final class RatToIntExpr extends UnaryExpr { private static final int HASH_SEED = 4828; @@ -84,5 +84,4 @@ protected int getHashSeed() { public String getOperatorLabel() { return OPERATOR_LABEL; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatType.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatType.java index 92a00b2880..5495c56d3e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatType.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/RatType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,14 +23,16 @@ import hu.bme.mit.theta.core.type.abstracttype.Ordered; public final class RatType - implements Additive, Multiplicative, Equational, Ordered { + implements Additive, + Multiplicative, + Equational, + Ordered { private static final RatType INSTANCE = new RatType(); private static final int HASH_SEED = 385863; private static final String TYPE_LABEL = "Rat"; - private RatType() { - } + private RatType() {} public static RatType getInstance() { return INSTANCE; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/package-info.java index c01bf143b2..d5e34a2156 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/type/rattype/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,24 +16,23 @@ /** * Rational type and its expressions. Use {@link hu.bme.mit.theta.core.type.rattype.RatExprs} to * create them. - *

- * - {@link hu.bme.mit.theta.core.type.rattype.RatType}: the actual rational type - *

- * - {@link hu.bme.mit.theta.core.type.rattype.RatLitExpr}: rational literal, e.g., 1%2 is 0.5 - *

- * - {@link hu.bme.mit.theta.core.type.rattype.RatNegExpr}: unary minus - - * {@link hu.bme.mit.theta.core.type.rattype.RatPosExpr}: unary plus - - * {@link hu.bme.mit.theta.core.type.rattype.RatAddExpr}: addition - - * {@link hu.bme.mit.theta.core.type.rattype.RatSubExpr}: subtraction - - * {@link hu.bme.mit.theta.core.type.rattype.RatMulExpr}: multiplication - - * {@link hu.bme.mit.theta.core.type.rattype.RatDivExpr}: rational division - *

- * - {@link hu.bme.mit.theta.core.type.rattype.RatEqExpr}: equal - - * {@link hu.bme.mit.theta.core.type.rattype.RatNeqExpr}: not equal - - * {@link hu.bme.mit.theta.core.type.rattype.RatGtExpr}: greater - - * {@link hu.bme.mit.theta.core.type.rattype.RatLtExpr}: less - - * {@link hu.bme.mit.theta.core.type.rattype.RatGeqExpr}: greater or equal - - * {@link hu.bme.mit.theta.core.type.rattype.RatLeqExpr}: less or equal + * + *

- {@link hu.bme.mit.theta.core.type.rattype.RatType}: the actual rational type + * + *

- {@link hu.bme.mit.theta.core.type.rattype.RatLitExpr}: rational literal, e.g., 1%2 is 0.5 + * + *

- {@link hu.bme.mit.theta.core.type.rattype.RatNegExpr}: unary minus - {@link + * hu.bme.mit.theta.core.type.rattype.RatPosExpr}: unary plus - {@link + * hu.bme.mit.theta.core.type.rattype.RatAddExpr}: addition - {@link + * hu.bme.mit.theta.core.type.rattype.RatSubExpr}: subtraction - {@link + * hu.bme.mit.theta.core.type.rattype.RatMulExpr}: multiplication - {@link + * hu.bme.mit.theta.core.type.rattype.RatDivExpr}: rational division + * + *

- {@link hu.bme.mit.theta.core.type.rattype.RatEqExpr}: equal - {@link + * hu.bme.mit.theta.core.type.rattype.RatNeqExpr}: not equal - {@link + * hu.bme.mit.theta.core.type.rattype.RatGtExpr}: greater - {@link + * hu.bme.mit.theta.core.type.rattype.RatLtExpr}: less - {@link + * hu.bme.mit.theta.core.type.rattype.RatGeqExpr}: greater or equal - {@link + * hu.bme.mit.theta.core.type.rattype.RatLeqExpr}: less or equal */ - -package hu.bme.mit.theta.core.type.rattype; \ No newline at end of file +package hu.bme.mit.theta.core.type.rattype; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/BvUtils.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/BvUtils.java index cde6781908..d995e3fe14 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/BvUtils.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/BvUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprAtomCollector.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprAtomCollector.java index a6eca8dd64..85f621316a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprAtomCollector.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprAtomCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.anytype.Dereference; @@ -25,37 +27,27 @@ import hu.bme.mit.theta.core.type.booltype.ImplyExpr; import hu.bme.mit.theta.core.type.booltype.NotExpr; import hu.bme.mit.theta.core.type.booltype.OrExpr; - import java.util.Collection; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - final class ExprAtomCollector { - private static final Collection> CONNECTIVES = ImmutableSet.>builder() - - .add(NotExpr.class) - - .add(ImplyExpr.class) + private static final Collection> CONNECTIVES = + ImmutableSet.>builder() + .add(NotExpr.class) + .add(ImplyExpr.class) + .add(IffExpr.class) + .add(AndExpr.class) + .add(OrExpr.class) - .add(IffExpr.class) + // .add(IteExpr.class) + .add(Dereference.class) + .add(PrimeExpr.class) + .build(); - .add(AndExpr.class) - - .add(OrExpr.class) - - // .add(IteExpr.class) - .add(Dereference.class) - - .add(PrimeExpr.class) - - .build(); - - private ExprAtomCollector() { - } + private ExprAtomCollector() {} - static void collectAtoms(final Expr expr, - final Collection> collectTo) { + static void collectAtoms( + final Expr expr, final Collection> collectTo) { if (CONNECTIVES.contains(expr.getClass())) { expr.getOps().stream() .forEach(op -> collectAtoms(TypeUtils.cast(op, Bool()), collectTo)); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCanonizer.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCanonizer.java index 1377383849..64af50631a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCanonizer.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCanonizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCloser.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCloser.java index f9aa59b6a5..68b17c1f8e 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCloser.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCloser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,31 +18,31 @@ import static hu.bme.mit.theta.core.decl.Decls.Param; import static java.lang.String.format; -import java.util.Map; - import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.anytype.RefExpr; +import java.util.Map; final class ExprCloser { private static final String PARAM_NAME_FORMAT = "_%s_p"; - private ExprCloser() { - } + private ExprCloser() {} - static Expr close(final Expr expr, - final Map, ParamDecl> mapping) { + static Expr close( + final Expr expr, final Map, ParamDecl> mapping) { if (expr instanceof RefExpr) { final RefExpr ref = (RefExpr) expr; final Decl decl = ref.getDecl(); if (decl instanceof VarDecl) { final VarDecl varDecl = (VarDecl) decl; - final ParamDecl param = mapping.computeIfAbsent(varDecl, - v -> Param(format(PARAM_NAME_FORMAT, v.getName()), v.getType())); + final ParamDecl param = + mapping.computeIfAbsent( + varDecl, + v -> Param(format(PARAM_NAME_FORMAT, v.getName()), v.getType())); final Expr paramRef = TypeUtils.cast(param.getRef(), expr.getType()); return paramRef; } @@ -50,5 +50,4 @@ static Expr close(final Expr expr, return expr.map(op -> close(op, mapping)); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfChecker.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfChecker.java index 060f1a8420..3ad5f2973d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfChecker.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -30,7 +30,10 @@ final class ExprCnfChecker { private enum CnfStatus { - START(0), INSIDE_AND(1), INSIDE_OR(2), INSIDE_NOT(3); + START(0), + INSIDE_AND(1), + INSIDE_OR(2), + INSIDE_NOT(3); final int value; private CnfStatus(final int value) { @@ -38,8 +41,7 @@ private CnfStatus(final int value) { } } - private ExprCnfChecker() { - } + private ExprCnfChecker() {} static boolean isExprCnf(final Expr expr) { return isExprCnf(expr, CnfStatus.START); diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfTransformer.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfTransformer.java index 1bb3b22e15..01a13123c1 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfTransformer.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprCnfTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,13 +20,7 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import java.util.ArrayList; -import java.util.Collection; - import hu.bme.mit.theta.common.container.Containers; - -import java.util.Map; - import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; @@ -36,6 +30,9 @@ import hu.bme.mit.theta.core.type.booltype.ImplyExpr; import hu.bme.mit.theta.core.type.booltype.NotExpr; import hu.bme.mit.theta.core.type.booltype.OrExpr; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; final class ExprCnfTransformer { @@ -63,8 +60,8 @@ private CnfTransformationHelper() { representatives = Containers.createMap(); } - public Expr transform(final Expr expr, - final Collection> encoding) { + public Expr transform( + final Expr expr, final Collection> encoding) { if (expr instanceof NotExpr) { return encodeNot((NotExpr) expr, encoding); } else if (expr instanceof ImplyExpr) { @@ -90,8 +87,8 @@ private Expr getRep(final Expr expr) { //// - private Expr encodeNot(final NotExpr expr, - final Collection> encoding) { + private Expr encodeNot( + final NotExpr expr, final Collection> encoding) { if (representatives.containsKey(expr)) { return representatives.get(expr).getRef(); } @@ -101,8 +98,8 @@ private Expr encodeNot(final NotExpr expr, return rep; } - private Expr encodeImply(final ImplyExpr expr, - final Collection> encoding) { + private Expr encodeImply( + final ImplyExpr expr, final Collection> encoding) { if (representatives.containsKey(expr)) { return representatives.get(expr).getRef(); } @@ -113,22 +110,25 @@ private Expr encodeImply(final ImplyExpr expr, return rep; } - private Expr encodeIff(final IffExpr expr, - final Collection> encoding) { + private Expr encodeIff( + final IffExpr expr, final Collection> encoding) { if (representatives.containsKey(expr)) { return representatives.get(expr).getRef(); } final Expr rep = getRep(expr); final Expr op1 = transform(expr.getLeftOp(), encoding); final Expr op2 = transform(expr.getRightOp(), encoding); - encoding.add(And(Or(Not(rep), Not(op1), op2), Or(Not(rep), op1, Not(op2)), - Or(rep, Not(op1), Not(op2)), - Or(rep, op1, op2))); + encoding.add( + And( + Or(Not(rep), Not(op1), op2), + Or(Not(rep), op1, Not(op2)), + Or(rep, Not(op1), Not(op2)), + Or(rep, op1, op2))); return rep; } - private Expr encodeAnd(final AndExpr expr, - final Collection> encoding) { + private Expr encodeAnd( + final AndExpr expr, final Collection> encoding) { if (representatives.containsKey(expr)) { return representatives.get(expr).getRef(); } @@ -149,8 +149,8 @@ private Expr encodeAnd(final AndExpr expr, return rep; } - private Expr encodeOr(final OrExpr expr, - final Collection> encoding) { + private Expr encodeOr( + final OrExpr expr, final Collection> encoding) { if (representatives.containsKey(expr)) { return representatives.get(expr).getRef(); } @@ -170,6 +170,5 @@ private Expr encodeOr(final OrExpr expr, encoding.add(And(en)); return rep; } - } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollector.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollector.java index 91c0b86503..498158435c 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollector.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,8 +22,7 @@ final class ExprIndexedVarCollector { - private ExprIndexedVarCollector() { - } + private ExprIndexedVarCollector() {} static void collectIndexedVars(final Expr expr, final IndexedVars.Builder builder) { if (expr instanceof RefExpr) { @@ -38,5 +37,4 @@ static void collectIndexedVars(final Expr expr, final IndexedVars.Builder bui expr.getOps().stream().forEach(op -> collectIndexedVars(op, builder)); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIteEliminator.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIteEliminator.java index 6516a10b3c..c4bad9b586 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIteEliminator.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprIteEliminator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,19 +21,17 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.anytype.IteExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; final class ExprIteEliminator { - private ExprIteEliminator() { - } + private ExprIteEliminator() {} static Expr eliminateIte(final Expr expr) { return removeIte(propagateIte(expr)); @@ -50,8 +48,8 @@ private static Expr removeIte(final Expr expr) { final Expr cond = removeIte(iteExpr.getCond()); final Expr then = TypeUtils.cast(removeIte(iteExpr.getThen()), Bool()); final Expr elze = TypeUtils.cast(removeIte(iteExpr.getElse()), Bool()); - @SuppressWarnings("unchecked") final Expr result = (Expr) And( - Or(Not(cond), then), Or(cond, elze)); + @SuppressWarnings("unchecked") + final Expr result = (Expr) And(Or(Not(cond), then), Or(cond, elze)); return result; } else { return expr; @@ -82,8 +80,8 @@ private static Expr pushIte(final Expr expr) { final List> ops = expr.getOps(); // Get the first operand that is an ITE - final Optional> optIte = ops.stream().filter(op -> op instanceof IteExpr) - .findFirst(); + final Optional> optIte = + ops.stream().filter(op -> op instanceof IteExpr).findFirst(); // Nothing to do if none of the operands are ITE if (!optIte.isPresent()) { @@ -112,5 +110,4 @@ private static Expr pushIte(final Expr expr) { return Ite(ite.getCond(), pushIte(expr.withOps(thenOps)), pushIte(expr.withOps(elseOps))); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprPrimeApplier.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprPrimeApplier.java index bc5d53b7a9..60b9706d61 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprPrimeApplier.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprPrimeApplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; + import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; @@ -22,12 +24,9 @@ import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; -import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; - final class ExprPrimeApplier { - private ExprPrimeApplier() { - } + private ExprPrimeApplier() {} static Expr applyPrimes(final Expr expr, final VarIndexing indexing) { if (expr instanceof RefExpr) { @@ -46,5 +45,4 @@ static Expr applyPrimes(final Expr expr, final VarIndexin return expr.map(op -> applyPrimes(op, indexing)); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprReverser.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprReverser.java index d69449e845..4841cdfaea 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprReverser.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprReverser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprSimplifier.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprSimplifier.java index 86cbd9659a..958b63e4d2 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprSimplifier.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprSimplifier.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprUtils.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprUtils.java index e429afb05e..198d48f9ca 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprUtils.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/ExprUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/FpUtils.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/FpUtils.java index 4df83977c9..97e9fa024d 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/FpUtils.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/FpUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,26 +15,24 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.NaN; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.NegativeInfinity; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.PositiveInfinity; + import hu.bme.mit.theta.core.type.fptype.FpLitExpr; import hu.bme.mit.theta.core.type.fptype.FpRoundingMode; import hu.bme.mit.theta.core.type.fptype.FpType; -import org.kframework.mpfr.BigFloat; -import org.kframework.mpfr.BinaryMathContext; - import java.math.BigInteger; import java.math.RoundingMode; - -import static hu.bme.mit.theta.core.type.fptype.FpExprs.NaN; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.NegativeInfinity; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.PositiveInfinity; +import org.kframework.mpfr.BigFloat; +import org.kframework.mpfr.BinaryMathContext; public final class FpUtils { - private FpUtils() { - } + private FpUtils() {} - public static BigFloat fpLitExprToBigFloat(final FpRoundingMode roundingMode, - final FpLitExpr expr) { + public static BigFloat fpLitExprToBigFloat( + final FpRoundingMode roundingMode, final FpLitExpr expr) { if (expr.isNaN()) { return BigFloat.NaN(expr.getType().getSignificand()); } else if (expr.isPositiveInfinity()) { @@ -48,12 +46,17 @@ public static BigFloat fpLitExprToBigFloat(final FpRoundingMode roundingMode, } else { final var maxExponent = (1L << (expr.getType().getExponent() - 1)) - 1; - final var exponent = BvUtils.neutralBvLitExprToBigInteger(expr.getExponent()) - .subtract(BigInteger.valueOf(maxExponent)); - final var significand = BvUtils.neutralBvLitExprToBigInteger(expr.getSignificand()) - .add(BigInteger.TWO.pow(expr.getType().getSignificand() - 1)); + final var exponent = + BvUtils.neutralBvLitExprToBigInteger(expr.getExponent()) + .subtract(BigInteger.valueOf(maxExponent)); + final var significand = + BvUtils.neutralBvLitExprToBigInteger(expr.getSignificand()) + .add(BigInteger.TWO.pow(expr.getType().getSignificand() - 1)); - return new BigFloat(expr.getHidden(), significand, exponent.longValue(), + return new BigFloat( + expr.getHidden(), + significand, + exponent.longValue(), getMathContext(expr.getType(), roundingMode)); } } @@ -61,26 +64,26 @@ public static BigFloat fpLitExprToBigFloat(final FpRoundingMode roundingMode, public static FpLitExpr bigFloatToFpLitExpr(final BigFloat bigFloat, final FpType type) { if (bigFloat.isNaN()) { return NaN(type); - } else if (bigFloat.isInfinite() && bigFloat.greaterThan( - BigFloat.zero(type.getSignificand()))) { + } else if (bigFloat.isInfinite() + && bigFloat.greaterThan(BigFloat.zero(type.getSignificand()))) { return PositiveInfinity(type); - } else if (bigFloat.isInfinite() && bigFloat.lessThan( - BigFloat.zero(type.getSignificand()))) { + } else if (bigFloat.isInfinite() + && bigFloat.lessThan(BigFloat.zero(type.getSignificand()))) { return NegativeInfinity(type); } else { final var minExponent = -(1L << (type.getExponent() - 1)) + 2; final var maxExponent = (1L << (type.getExponent() - 1)) - 1; final var round = bigFloat.round(getMathContext(type, FpRoundingMode.RNE)); - final var exponent = BigInteger.valueOf(round.exponent(minExponent, maxExponent)) - .add(BigInteger.valueOf(maxExponent)); + final var exponent = + BigInteger.valueOf(round.exponent(minExponent, maxExponent)) + .add(BigInteger.valueOf(maxExponent)); final var significand = round.significand(minExponent, maxExponent); return FpLitExpr.of( bigFloat.sign(), BvUtils.bigIntegerToNeutralBvLitExpr(exponent, type.getExponent()), - BvUtils.bigIntegerToNeutralBvLitExpr(significand, type.getSignificand() - 1) - ); + BvUtils.bigIntegerToNeutralBvLitExpr(significand, type.getSignificand() - 1)); } } @@ -105,18 +108,18 @@ public static RoundingMode getMathContextRoundingMode(final FpRoundingMode round } } - public static BinaryMathContext getMathContext(final FpType type, - final FpRoundingMode roundingMode) { - return new BinaryMathContext(type.getSignificand(), type.getExponent(), + public static BinaryMathContext getMathContext( + final FpType type, final FpRoundingMode roundingMode) { + return new BinaryMathContext( + type.getSignificand(), + type.getExponent(), getMathContextRoundingMode(roundingMode)); } public static FpLitExpr fromString(final String value, final FpType type) { - return bigFloatToFpLitExpr(new BigFloat( - value, - new BinaryMathContext( - type.getSignificand(), - type.getExponent())), + return bigFloatToFpLitExpr( + new BigFloat( + value, new BinaryMathContext(type.getSignificand(), type.getExponent())), type); } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/IndexedVars.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/IndexedVars.java index 91bb4c7356..5d2623780b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/IndexedVars.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/IndexedVars.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,22 +17,19 @@ import static com.google.common.base.Preconditions.checkState; +import hu.bme.mit.theta.common.LispStringBuilder; +import hu.bme.mit.theta.common.Utils; +import hu.bme.mit.theta.common.container.Containers; +import hu.bme.mit.theta.core.decl.IndexedConstDecl; +import hu.bme.mit.theta.core.decl.VarDecl; import java.util.Collection; import java.util.Collections; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.StringJoiner; import java.util.stream.Collectors; -import hu.bme.mit.theta.common.LispStringBuilder; -import hu.bme.mit.theta.common.Utils; -import hu.bme.mit.theta.core.decl.IndexedConstDecl; -import hu.bme.mit.theta.core.decl.VarDecl; - /** * Represents an immutable mapping, where each integer index can be associated with a set of * variables. Use the inner builder class to create a new instance. @@ -83,21 +80,17 @@ public boolean isEmpty() { * @return Set of variables */ public Set> getAllVars() { - final Set> allVars = varSets.values().stream().flatMap(Collection::stream) - .collect(Collectors.toSet()); + final Set> allVars = + varSets.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); return Collections.unmodifiableSet(allVars); } - /** - * Create a new builder instance. - */ + /** Create a new builder instance. */ public static Builder builder() { return new Builder(); } - /** - * Helper class for building a new instance. - */ + /** Helper class for building a new instance. */ public static final class Builder { private final Map>> varSets; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/Lens.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/Lens.java index d4f0d4d4f4..8fc9738297 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/Lens.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/Lens.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ public interface Lens { E get(T t); T set(T t, E e); - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PathUtils.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PathUtils.java index 779d64e43c..d285cf7894 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PathUtils.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PathUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.core.utils; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.IndexedConstDecl; @@ -28,21 +32,13 @@ import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; - import java.util.Collection; import java.util.Optional; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime; - -/** - * Utility functions related to paths. - */ +/** Utility functions related to paths. */ public class PathUtils { - private PathUtils() { - } + private PathUtils() {} //// @@ -55,7 +51,7 @@ public static VarIndexing countPrimes(final Expr expr) { /** * Transform an expression by substituting variables with indexed constants. * - * @param expr Original expression + * @param expr Original expression * @param indexing Indexing for the variables * @return Transformed expression */ @@ -66,7 +62,8 @@ public static Expr unfold(final Expr expr, final VarIndex return helper.unfold(expr, 0); } - public static Expr unfoldReverse(final Expr expr, final VarIndexing indexing) { + public static Expr unfoldReverse( + final Expr expr, final VarIndexing indexing) { checkNotNull(expr); checkNotNull(indexing); final VarIndexing primes = countPrimes(expr); @@ -78,7 +75,7 @@ public static Expr unfoldReverse(final Expr expr, final V * Transform an expression by substituting variables with indexed constants. * * @param expr Original expression - * @param i Index + * @param i Index * @return Transformed expression */ public static Expr unfold(final Expr expr, final int i) { @@ -89,7 +86,7 @@ public static Expr unfold(final Expr expr, final int i) { /** * Transform an expression by substituting indexed constants with variables. * - * @param expr Original expression + * @param expr Original expression * @param indexing Indexing for the variables * @return Transformed expression */ @@ -104,7 +101,7 @@ public static Expr foldin(final Expr expr, final VarIndex * Transform an expression by substituting indexed constants with variables. * * @param expr Original expression - * @param i Index + * @param i Index * @return Transformed expression */ public static Expr foldin(final Expr expr, final int i) { @@ -113,11 +110,10 @@ public static Expr foldin(final Expr expr, final int i) { } /** - * Extract values from a model for a given indexing. If you know the set of - * variables to be extracted, use that overload because it is more - * efficient. + * Extract values from a model for a given indexing. If you know the set of variables to be + * extracted, use that overload because it is more efficient. * - * @param model Model + * @param model Model * @param indexing Indexing * @return Values */ @@ -137,12 +133,11 @@ public static Valuation extractValuation(final Valuation model, final VarIndexin } /** - * Extract values from a model for a given index. If you know the set of - * variables to be extracted, use that overload because it is more - * efficient. + * Extract values from a model for a given index. If you know the set of variables to be + * extracted, use that overload because it is more efficient. * * @param model Model - * @param i Index + * @param i Index * @return Values */ public static Valuation extractValuation(final Valuation model, final int i) { @@ -151,16 +146,17 @@ public static Valuation extractValuation(final Valuation model, final int i) { } /** - * Extract values from a model for a given indexing and given variables. If - * a variable has no value in the model, it will not be included in the - * return value. + * Extract values from a model for a given indexing and given variables. If a variable has no + * value in the model, it will not be included in the return value. * - * @param model Model + * @param model Model * @param indexing Indexing * @return Values */ - public static Valuation extractValuation(final Valuation model, final VarIndexing indexing, - final Collection> varDecls) { + public static Valuation extractValuation( + final Valuation model, + final VarIndexing indexing, + final Collection> varDecls) { final ImmutableValuation.Builder builder = ImmutableValuation.builder(); for (final VarDecl varDecl : varDecls) { final int index = indexing.get(varDecl); @@ -174,16 +170,15 @@ public static Valuation extractValuation(final Valuation model, final VarIndexin } /** - * Extract values from a model for a given index and given variables. If a - * variable has no value in the model, it will not be included in the return - * value. + * Extract values from a model for a given index and given variables. If a variable has no value + * in the model, it will not be included in the return value. * * @param model Model - * @param i Index + * @param i Index * @return Values */ - public static Valuation extractValuation(final Valuation model, final int i, - final Collection> varDecls) { + public static Valuation extractValuation( + final Valuation model, final int i, final Collection> varDecls) { checkArgument(i >= 0); return extractValuation(model, VarIndexingFactory.indexing(i), varDecls); } @@ -226,7 +221,8 @@ private static final class ReverseUnfoldHelper { private final VarIndexing indexing; private final VarIndexing primes; - private ReverseUnfoldHelper(final VarIndexing indexing, final VarIndexing primes) { + private ReverseUnfoldHelper( + final VarIndexing indexing, final VarIndexing primes) { this.indexing = indexing; this.primes = primes; } @@ -286,5 +282,4 @@ public Expr foldin(final Expr expr) { return expr.map(this::foldin); } } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PrimeCounter.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PrimeCounter.java index 9ab8930aff..782ee4193f 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PrimeCounter.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/PrimeCounter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,20 +23,18 @@ import hu.bme.mit.theta.core.utils.indexings.BasicVarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; - import java.util.List; final class PrimeCounter { - private PrimeCounter() { - } + private PrimeCounter() {} static VarIndexing countPrimes(final Expr expr) { return collectPrimes(expr, 0).build(); } - private static BasicVarIndexing.BasicVarIndexingBuilder collectPrimes(final Expr expr, - final int nPrimes) { + private static BasicVarIndexing.BasicVarIndexingBuilder collectPrimes( + final Expr expr, final int nPrimes) { if (expr instanceof RefExpr) { final RefExpr ref = (RefExpr) expr; final Decl decl = ref.getDecl(); @@ -53,9 +51,10 @@ private static BasicVarIndexing.BasicVarIndexingBuilder collectPrimes(final Expr } final List> ops = expr.getOps(); - return ops.stream().map(op -> collectPrimes(op, nPrimes)) - .reduce(VarIndexingFactory.basicIndexingBuilder(0), + return ops.stream() + .map(op -> collectPrimes(op, nPrimes)) + .reduce( + VarIndexingFactory.basicIndexingBuilder(0), BasicVarIndexing.BasicVarIndexingBuilder::join); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SimplifierLevel.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SimplifierLevel.java index b30b5ca6a3..0e2a79e7f5 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SimplifierLevel.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SimplifierLevel.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,6 @@ package hu.bme.mit.theta.core.utils; public enum SimplifierLevel { - FULL, LITERAL_ONLY + FULL, + LITERAL_ONLY } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SpState.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SpState.java index f271a0f752..aaa9013095 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SpState.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/SpState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.BasicSubstitution; @@ -36,12 +41,6 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; - public class SpState { private static final int HASH_SEED = 2029; @@ -109,15 +108,15 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).add(expr) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .add(expr) .add(Integer.valueOf(constCount)) .toString(); } private static final class SpVisitor implements StmtVisitor { - private SpVisitor() { - } + private SpVisitor() {} private static class LazyHolder { @@ -134,8 +133,8 @@ public SpState visit(final SkipStmt stmt, final SpState state) { } @Override - public SpState visit(final AssignStmt stmt, - final SpState state) { + public SpState visit( + final AssignStmt stmt, final SpState state) { final VarDecl varDecl = stmt.getVarDecl(); final int constCount = state.constCount + 1; final String valName = String.format("_sp_%d", constCount); @@ -149,13 +148,14 @@ public SpState visit(final AssignStmt stmt, } @Override - public SpState visit(MemoryAssignStmt stmt, SpState param) { + public SpState visit( + MemoryAssignStmt stmt, SpState param) { throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); } @Override - public SpState visit(final HavocStmt stmt, - final SpState state) { + public SpState visit( + final HavocStmt stmt, final SpState state) { final VarDecl varDecl = stmt.getVarDecl(); final int constCount = state.constCount + 1; final String valName = String.format("_sp_%d", constCount); @@ -192,7 +192,6 @@ public SpState visit(LoopStmt stmt, SpState param) { throw new UnsupportedOperationException(); } - public SpState visit(IfStmt stmt, SpState param) { throw new UnsupportedOperationException(); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtAtomCollector.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtAtomCollector.java index d064a1549d..50b070964b 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtAtomCollector.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtAtomCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils; import hu.bme.mit.theta.common.container.Containers; @@ -33,7 +32,6 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Set; public class StmtAtomCollector { @@ -44,8 +42,8 @@ public static Set> collectAtoms(final Stmt stmt) { return atoms; } - private static class AllAssumesAndAssignsCollector implements - StmtVisitor>, Void> { + private static class AllAssumesAndAssignsCollector + implements StmtVisitor>, Void> { @Override public Void visit(SkipStmt stmt, Set> atoms) { @@ -59,23 +57,24 @@ public Void visit(AssumeStmt stmt, Set> atoms) { } @Override - public Void visit(AssignStmt stmt, - Set> atoms) { + public Void visit( + AssignStmt stmt, Set> atoms) { final Expr eq = EqExpr.create2(stmt.getVarDecl().getRef(), stmt.getExpr()); atoms.addAll(ExprUtils.getAtoms(eq)); return null; } @Override - public Void visit(MemoryAssignStmt stmt, Set> atoms) { + public Void visit( + MemoryAssignStmt stmt, Set> atoms) { final Expr eq = EqExpr.create2(stmt.getDeref(), stmt.getExpr()); atoms.addAll(ExprUtils.getAtoms(eq)); return null; } @Override - public Void visit(HavocStmt stmt, - Set> atoms) { + public Void visit( + HavocStmt stmt, Set> atoms) { return null; } @@ -109,5 +108,4 @@ public Void visit(IfStmt stmt, Set> atoms) { return null; } } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtCounterVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtCounterVisitor.java index ce78170227..f933f987f8 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtCounterVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtCounterVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils; import hu.bme.mit.theta.core.stmt.AssignStmt; @@ -33,11 +32,10 @@ public class StmtCounterVisitor implements StmtVisitor { private static final class LazyHolder { - private final static StmtCounterVisitor INSTANCE = new StmtCounterVisitor(); + private static final StmtCounterVisitor INSTANCE = new StmtCounterVisitor(); } - private StmtCounterVisitor() { - } + private StmtCounterVisitor() {} public static StmtCounterVisitor getInstance() { return StmtCounterVisitor.LazyHolder.INSTANCE; @@ -59,7 +57,8 @@ public Integer visit(AssignStmt stmt, Void par } @Override - public Integer visit(MemoryAssignStmt stmt, Void param) { + public Integer visit( + MemoryAssignStmt stmt, Void param) { return 1; } @@ -102,8 +101,6 @@ public Integer visit(OrtStmt stmt, Void param) { @Override public Integer visit(IfStmt stmt, Void param) { - return stmt.getThen().accept(this, null) - + stmt.getElze().accept(this, null) - + 1; + return stmt.getThen().accept(this, null) + stmt.getElze().accept(this, null) + 1; } } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtSimplifier.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtSimplifier.java index 5ef35a2789..de8f52daf9 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtSimplifier.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtSimplifier.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; @@ -42,16 +45,11 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; - import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class StmtSimplifier { public static Stmt simplifyStmt(final Valuation valuation, final Stmt stmt) { @@ -61,7 +59,8 @@ public static Stmt simplifyStmt(final Valuation valuation, final Stmt stmt) { } private enum SimplifyStatus { - SUCCESS, BOTTOM + SUCCESS, + BOTTOM } public static class SimplifyResult { @@ -87,8 +86,8 @@ public SimplifyStatus getStatus() { } } - public static class StmtSimplifierVisitor implements - StmtVisitor { + public static class StmtSimplifierVisitor + implements StmtVisitor { @Override public SimplifyResult visit(final SkipStmt stmt, final MutableValuation valuation) { @@ -109,8 +108,8 @@ public SimplifyResult visit(final AssumeStmt stmt, final MutableValuation valuat } @Override - public SimplifyResult visit(final AssignStmt stmt, - final MutableValuation valuation) { + public SimplifyResult visit( + final AssignStmt stmt, final MutableValuation valuation) { final VarDecl varDecl = stmt.getVarDecl(); final Expr expr = ExprUtils.simplify(stmt.getExpr(), valuation); if (expr instanceof LitExpr) { @@ -123,19 +122,30 @@ public SimplifyResult visit(final AssignStmt s } @Override - public SimplifyResult visit(MemoryAssignStmt stmt, MutableValuation valuation) { + public + SimplifyResult visit( + MemoryAssignStmt stmt, + MutableValuation valuation) { final Expr expr = ExprUtils.simplify(stmt.getExpr(), valuation); - final Dereference deref = (Dereference) ExprUtils.simplify(stmt.getDeref(), valuation); + final Dereference deref = + (Dereference) + ExprUtils.simplify(stmt.getDeref(), valuation); - if (expr instanceof LitExpr litExpr && deref.getOffset() instanceof LitExpr litOffset && deref.getArray() instanceof RefExpr ref) { + if (expr instanceof LitExpr litExpr + && deref.getOffset() instanceof LitExpr litOffset + && deref.getArray() instanceof RefExpr ref) { if (litOffset instanceof IntLitExpr) { IntLitExpr intLitOffset = (IntLitExpr) litOffset; VarDecl varDecl = (VarDecl) ref.getDecl(); - valuation.put(varDecl.getConstDecl(intLitOffset.getValue().intValue()), litExpr); + valuation.put( + varDecl.getConstDecl(intLitOffset.getValue().intValue()), litExpr); } else if (litOffset instanceof BvLitExpr) { BvLitExpr bvLitExpr = (BvLitExpr) litOffset; VarDecl varDecl = (VarDecl) ref.getDecl(); - valuation.put(varDecl.getConstDecl(BvUtils.neutralBvLitExprToBigInteger(bvLitExpr).intValue()), litExpr); + valuation.put( + varDecl.getConstDecl( + BvUtils.neutralBvLitExprToBigInteger(bvLitExpr).intValue()), + litExpr); } } @@ -143,8 +153,8 @@ public Si } @Override - public SimplifyResult visit(final HavocStmt stmt, - final MutableValuation valuation) { + public SimplifyResult visit( + final HavocStmt stmt, final MutableValuation valuation) { final VarDecl varDecl = stmt.getVarDecl(); valuation.remove(varDecl); return SimplifyResult.of(stmt, SimplifyStatus.SUCCESS); @@ -152,13 +162,18 @@ public SimplifyResult visit(final HavocStmt st @Override public SimplifyResult visit(final SequenceStmt stmt, final MutableValuation valuation) { - final var subStmtsUnrolled = stmt.getStmts().stream() - .map(subStmt -> subStmt.accept(this, valuation)).collect(Collectors.toList()); - final var simplifiedStmt = SequenceStmt.of( - subStmtsUnrolled.stream().map(result -> result.stmt) - .collect(Collectors.toList())); - final boolean anyBottom = subStmtsUnrolled.stream() - .anyMatch(result -> result.status == SimplifyStatus.BOTTOM); + final var subStmtsUnrolled = + stmt.getStmts().stream() + .map(subStmt -> subStmt.accept(this, valuation)) + .collect(Collectors.toList()); + final var simplifiedStmt = + SequenceStmt.of( + subStmtsUnrolled.stream() + .map(result -> result.stmt) + .collect(Collectors.toList())); + final boolean anyBottom = + subStmtsUnrolled.stream() + .anyMatch(result -> result.status == SimplifyStatus.BOTTOM); if (anyBottom) { return SimplifyResult.of(AssumeStmt.of(False()), SimplifyStatus.BOTTOM); } else { @@ -199,7 +214,6 @@ public SimplifyResult visit(final NonDetStmt stmt, final MutableValuation valuat } return SimplifyResult.of(NonDetStmt.of(successfulSubStmts), SimplifyStatus.SUCCESS); } - } @Override @@ -217,18 +231,18 @@ public SimplifyResult visit(final LoopStmt stmt, final MutableValuation valuatio var fromValue = ((IntLitExpr) fromUnrolled).getValue(); var toValue = ((IntLitExpr) toUnrolled).getValue(); var stmts = new ArrayList(); - for (BigInteger bi = fromValue; bi.compareTo(toValue) < 0; - bi = bi.add(BigInteger.ONE)) { + for (BigInteger bi = fromValue; + bi.compareTo(toValue) < 0; + bi = bi.add(BigInteger.ONE)) { var assignToLoopVar = AssignStmt.of(stmt.getLoopVariable(), Int(bi)); - var loopVarIncAndSubStmt = SequenceStmt.of( - ImmutableList.of(assignToLoopVar, stmt.getStmt())); + var loopVarIncAndSubStmt = + SequenceStmt.of(ImmutableList.of(assignToLoopVar, stmt.getStmt())); var result = loopVarIncAndSubStmt.accept(this, valuation); if (result.status == SimplifyStatus.SUCCESS) { stmts.add(result.stmt); } else { return SimplifyResult.of(AssumeStmt.of(False()), SimplifyStatus.BOTTOM); } - } return SimplifyResult.of(SequenceStmt.of(stmts), SimplifyStatus.SUCCESS); } @@ -261,30 +275,30 @@ public SimplifyResult visit(IfStmt stmt, MutableValuation valuation) { if (thenResult.status == SimplifyStatus.SUCCESS && elzeResult.status == SimplifyStatus.BOTTOM) { final AssumeStmt assume = AssumeStmt.of(cond); - final SequenceStmt assumeAndThen = SequenceStmt.of( - ImmutableList.of(assume, stmt.getThen())); + final SequenceStmt assumeAndThen = + SequenceStmt.of(ImmutableList.of(assume, stmt.getThen())); return assumeAndThen.accept(this, valuation); } if (thenResult.status == SimplifyStatus.BOTTOM && elzeResult.status == SimplifyStatus.SUCCESS) { final AssumeStmt assumeNot = AssumeStmt.of(Not(cond)); - final SequenceStmt assumeAndElze = SequenceStmt.of( - ImmutableList.of(assumeNot, stmt.getElze())); + final SequenceStmt assumeAndElze = + SequenceStmt.of(ImmutableList.of(assumeNot, stmt.getElze())); return assumeAndElze.accept(this, valuation); } stmt.getThen().accept(this, valuation); - var toRemove = valuation.getDecls().stream() - .filter(it -> !valuation.eval(it).equals(elzeVal.eval(it))) - .collect(Collectors.toSet()); + var toRemove = + valuation.getDecls().stream() + .filter(it -> !valuation.eval(it).equals(elzeVal.eval(it))) + .collect(Collectors.toSet()); for (Decl decl : toRemove) { valuation.remove(decl); } - return SimplifyResult.of(IfStmt.of(cond, thenResult.stmt, elzeResult.stmt), - SimplifyStatus.SUCCESS); + return SimplifyResult.of( + IfStmt.of(cond, thenResult.stmt, elzeResult.stmt), SimplifyStatus.SUCCESS); } } } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtToExprTransformer.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtToExprTransformer.java index f278fa5009..8444d30d26 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtToExprTransformer.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtToExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUnfoldResult.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUnfoldResult.java index 22fad7cbbf..e81cb58047 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUnfoldResult.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUnfoldResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; - import java.util.Collection; public final class StmtUnfoldResult { @@ -27,14 +26,14 @@ public final class StmtUnfoldResult { final Collection> exprs; final VarIndexing indexing; - private StmtUnfoldResult(final Iterable> exprs, - final VarIndexing indexing) { + private StmtUnfoldResult( + final Iterable> exprs, final VarIndexing indexing) { this.exprs = ImmutableList.copyOf(exprs); this.indexing = indexing; } - public static StmtUnfoldResult of(final Iterable> exprs, - final VarIndexing indexing) { + public static StmtUnfoldResult of( + final Iterable> exprs, final VarIndexing indexing) { return new StmtUnfoldResult(exprs, indexing); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUtils.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUtils.java index a136c44d94..3889296aa1 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUtils.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/StmtUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,19 +19,15 @@ import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; - import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -/** - * Utility functions related to statements. - */ +/** Utility functions related to statements. */ public final class StmtUtils { - private StmtUtils() { - } + private StmtUtils() {} /** * Get variables appearing in a statement @@ -60,7 +56,7 @@ public static Set> getVars(final Iterable stmts) { /** * Unfold a statement into expressions with a given indexing * - * @param stmt Statement + * @param stmt Statement * @param indexing Indexing * @return Expressions and new indexing */ @@ -71,12 +67,12 @@ public static StmtUnfoldResult toExpr(final Stmt stmt, final VarIndexing indexin /** * Unfold statements into expressions with a given indexing * - * @param stmts Statements + * @param stmts Statements * @param indexing Indexing * @return Expressions and new indexing */ - public static StmtUnfoldResult toExpr(final List stmts, - final VarIndexing indexing) { + public static StmtUnfoldResult toExpr( + final List stmts, final VarIndexing indexing) { return StmtToExprTransformer.toExpr(stmts, indexing); } @@ -85,5 +81,4 @@ public static Stmt changeVars(final Stmt stmt, final Iterable> varDec varDecls.forEach(varDecl -> map.put(varDecl.getName(), varDecl)); return VarChangerUtilsKt.changeVars(stmt, map); } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/TypeUtils.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/TypeUtils.java index 942741f860..91b2020470 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/TypeUtils.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/TypeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.core.utils; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; @@ -28,21 +31,14 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatExprs; import hu.bme.mit.theta.core.type.rattype.RatType; -import org.kframework.mpfr.BigFloat; - import java.math.BigInteger; import java.util.Iterator; +import org.kframework.mpfr.BigFloat; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Utility functions related to types. - */ +/** Utility functions related to types. */ public final class TypeUtils { - private TypeUtils() { - } + private TypeUtils() {} /** * Cast a declaration to a given type. @@ -56,7 +52,8 @@ public static Decl cast(final Decl decl, final T type) { checkNotNull(type); if (decl.getType().equals(type)) { - @SuppressWarnings("unchecked") final Decl result = (Decl) decl; + @SuppressWarnings("unchecked") + final Decl result = (Decl) decl; return result; } else { throw new ClassCastException( @@ -76,7 +73,8 @@ public static VarDecl cast(final VarDecl decl, final T ty checkNotNull(type); if (decl.getType().equals(type)) { - @SuppressWarnings("unchecked") final VarDecl result = (VarDecl) decl; + @SuppressWarnings("unchecked") + final VarDecl result = (VarDecl) decl; return result; } else { throw new ClassCastException( @@ -96,11 +94,17 @@ public static Expr cast(final Expr expr, final T type) { checkNotNull(type); if (expr.getType().equals(type)) { - @SuppressWarnings("unchecked") final Expr result = (Expr) expr; + @SuppressWarnings("unchecked") + final Expr result = (Expr) expr; return result; } else { throw new ClassCastException( - "The type of expression " + expr + " is not of type " + type + ", but " + expr.getType()); + "The type of expression " + + expr + + " is not of type " + + type + + ", but " + + expr.getType()); } } @@ -114,7 +118,8 @@ public static Expr castBv(final Expr expr) { checkNotNull(expr); if (expr.getType() instanceof BvType) { - @SuppressWarnings("unchecked") final Expr result = (Expr) expr; + @SuppressWarnings("unchecked") + final Expr result = (Expr) expr; return result; } else { throw new ClassCastException( @@ -132,7 +137,8 @@ public static Expr castFp(final Expr expr) { checkNotNull(expr); if (expr.getType() instanceof FpType) { - @SuppressWarnings("unchecked") final Expr result = (Expr) expr; + @SuppressWarnings("unchecked") + final Expr result = (Expr) expr; return result; } else { throw new ClassCastException( @@ -187,12 +193,19 @@ public static LitExpr getDefaultValue(final T type) { } else if (type instanceof RatType) { return (LitExpr) cast(RatExprs.Rat(0, 1), type); } else if (type instanceof BvType) { - return (LitExpr) cast(BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.ZERO, ((BvType) type).getSize()), type); + return (LitExpr) + cast( + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.ZERO, ((BvType) type).getSize()), + type); } else if (type instanceof FpType) { - return (LitExpr) cast(FpUtils.bigFloatToFpLitExpr(BigFloat.zero(((FpType) type).getSignificand()), (FpType) type), type); + return (LitExpr) + cast( + FpUtils.bigFloatToFpLitExpr( + BigFloat.zero(((FpType) type).getSignificand()), (FpType) type), + type); } else { throw new AssertionError(); } } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitor.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitor.java index 7a1acbef33..f6268a4905 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitor.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,18 +29,16 @@ import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.stmt.StmtVisitor; import hu.bme.mit.theta.core.type.Type; - import java.util.Collection; final class VarCollectorStmtVisitor implements StmtVisitor>, Void> { private static final class LazyHolder { - private final static VarCollectorStmtVisitor INSTANCE = new VarCollectorStmtVisitor(); + private static final VarCollectorStmtVisitor INSTANCE = new VarCollectorStmtVisitor(); } - private VarCollectorStmtVisitor() { - } + private VarCollectorStmtVisitor() {} static VarCollectorStmtVisitor getInstance() { return LazyHolder.INSTANCE; @@ -58,23 +56,24 @@ public Void visit(final AssumeStmt stmt, final Collection> vars) { } @Override - public Void visit(final AssignStmt stmt, - final Collection> vars) { + public Void visit( + final AssignStmt stmt, final Collection> vars) { vars.add(stmt.getVarDecl()); ExprUtils.collectVars(stmt.getExpr(), vars); return null; } @Override - public Void visit(MemoryAssignStmt stmt, Collection> vars) { + public Void visit( + MemoryAssignStmt stmt, Collection> vars) { ExprUtils.collectVars(stmt.getDeref(), vars); ExprUtils.collectVars(stmt.getExpr(), vars); return null; } @Override - public Void visit(final HavocStmt stmt, - final Collection> vars) { + public Void visit( + final HavocStmt stmt, final Collection> vars) { vars.add(stmt.getVarDecl()); return null; } @@ -117,5 +116,4 @@ public Void visit(IfStmt stmt, Collection> vars) { stmt.getElze().accept(VarCollectorStmtVisitor.getInstance(), vars); return null; } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarPoolUtil.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarPoolUtil.java index cc52117b32..4deb7a3e71 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarPoolUtil.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/VarPoolUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,18 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.inttype.IntType; - import java.util.ArrayDeque; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class VarPoolUtil { - private VarPoolUtil() { - } + private VarPoolUtil() {} - private final static ArrayDeque> intPool = new ArrayDeque>(); + private static final ArrayDeque> intPool = new ArrayDeque>(); private static int counter = 0; public static VarDecl requestInt() { @@ -44,5 +42,4 @@ public static void returnInt(VarDecl var) { intPool.addFirst(var); } } - } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/WpState.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/WpState.java index f396c5ad93..70f1dd0ddb 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/WpState.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/WpState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,12 @@ */ package hu.bme.mit.theta.core.utils; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Imply; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.BasicSubstitution; @@ -35,12 +41,6 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Imply; - public final class WpState { private static final int HASH_SEED = 2029; @@ -118,15 +118,15 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).add(expr) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .add(expr) .add(Integer.valueOf(constCount)) .toString(); } private static final class WpVisitor implements StmtVisitor { - private WpVisitor() { - } + private WpVisitor() {} private static class LazyHolder { @@ -143,24 +143,25 @@ public WpState visit(final SkipStmt stmt, final WpState state) { } @Override - public WpState visit(final AssignStmt stmt, - final WpState state) { + public WpState visit( + final AssignStmt stmt, final WpState state) { final VarDecl varDecl = stmt.getVarDecl(); - final Substitution sub = BasicSubstitution.builder().put(varDecl, stmt.getExpr()) - .build(); + final Substitution sub = + BasicSubstitution.builder().put(varDecl, stmt.getExpr()).build(); final Expr expr = sub.apply(state.getExpr()); final int constCount = state.constCount; return new WpState(expr, constCount); } @Override - public WpState visit(MemoryAssignStmt stmt, WpState param) { + public WpState visit( + MemoryAssignStmt stmt, WpState param) { throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); } @Override - public WpState visit(final HavocStmt stmt, - final WpState state) { + public WpState visit( + final HavocStmt stmt, final WpState state) { final VarDecl varDecl = stmt.getVarDecl(); final int constCount = state.constCount + 1; final String valName = String.format("_wp_%d", constCount); @@ -204,8 +205,7 @@ public WpState visit(final AssumeStmt stmt, final WpState state) { private static final class WepVisitor implements StmtVisitor { - private WepVisitor() { - } + private WepVisitor() {} private static class LazyHolder { @@ -222,19 +222,20 @@ public WpState visit(final SkipStmt stmt, final WpState state) { } @Override - public WpState visit(final AssignStmt stmt, - final WpState state) { + public WpState visit( + final AssignStmt stmt, final WpState state) { return WpVisitor.getInstance().visit(stmt, state); } @Override - public WpState visit(MemoryAssignStmt stmt, WpState param) { + public WpState visit( + MemoryAssignStmt stmt, WpState param) { throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); } @Override - public WpState visit(final HavocStmt stmt, - final WpState state) { + public WpState visit( + final HavocStmt stmt, final WpState state) { return WpVisitor.getInstance().visit(stmt, state); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/BasicVarIndexing.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/BasicVarIndexing.java index 7877380ac0..3ddbfa9777 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/BasicVarIndexing.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/BasicVarIndexing.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,24 @@ */ package hu.bme.mit.theta.core.utils.indexings; +import static com.google.common.base.Preconditions.*; +import static java.lang.Math.max; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Map; import java.util.Set; import java.util.StringJoiner; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.google.common.base.Preconditions.*; -import static java.lang.Math.max; - /** - * Represents an immutable mapping, where each variable is associated with an - * index. The inner builder class can also be used to create a new instance. + * Represents an immutable mapping, where each variable is associated with an index. The inner + * builder class can also be used to create a new instance. */ public class BasicVarIndexing implements VarIndexing { @@ -91,7 +90,7 @@ public BasicVarIndexingBuilder transform() { * Increment the index of a given variable with a given amount * * @param varDecl Variable to increment - * @param n Amount to increment + * @param n Amount to increment * @return Transformed indexing */ public BasicVarIndexing inc(final VarDecl varDecl, final int n) { @@ -201,14 +200,17 @@ public BasicVarIndexingBuilder incAll() { @Override public BasicVarIndexingBuilder add(final VarIndexingBuilder genericThat) { checkNotNull(genericThat); - checkArgument(genericThat instanceof BasicVarIndexingBuilder, "Only builders of the same type can be added together!"); + checkArgument( + genericThat instanceof BasicVarIndexingBuilder, + "Only builders of the same type can be added together!"); BasicVarIndexingBuilder that = (BasicVarIndexingBuilder) genericThat; final int newDefaultIndex = this.defaultIndex + that.defaultIndex; final Map, Integer> newVarToOffset = Containers.createMap(); - final Set> varDecls = Sets.union(this.varToOffset.keySet(), that.varToOffset.keySet()); + final Set> varDecls = + Sets.union(this.varToOffset.keySet(), that.varToOffset.keySet()); for (final VarDecl varDecl : varDecls) { final int index1 = this.get(varDecl); final int index2 = that.get(varDecl); @@ -228,7 +230,9 @@ public BasicVarIndexingBuilder add(final VarIndexingBuilder genericThat) { @Override public BasicVarIndexingBuilder sub(final VarIndexingBuilder genericThat) { checkNotNull(genericThat); - checkArgument(genericThat instanceof BasicVarIndexingBuilder, "Only builders of the same type can be subtracted!"); + checkArgument( + genericThat instanceof BasicVarIndexingBuilder, + "Only builders of the same type can be subtracted!"); BasicVarIndexingBuilder that = (BasicVarIndexingBuilder) genericThat; @@ -236,7 +240,8 @@ public BasicVarIndexingBuilder sub(final VarIndexingBuilder genericThat) { checkArgument(newDefaultIndex >= 0, "Negative default index"); final Map, Integer> newVarToOffset = Containers.createMap(); - final Set> varDecls = Sets.union(this.varToOffset.keySet(), that.varToOffset.keySet()); + final Set> varDecls = + Sets.union(this.varToOffset.keySet(), that.varToOffset.keySet()); for (final VarDecl varDecl : varDecls) { final int index1 = this.get(varDecl); final int index2 = that.get(varDecl); @@ -256,14 +261,17 @@ public BasicVarIndexingBuilder sub(final VarIndexingBuilder genericThat) { @Override public BasicVarIndexingBuilder join(final VarIndexingBuilder genericThat) { checkNotNull(genericThat); - checkArgument(genericThat instanceof BasicVarIndexingBuilder, "Only builders of the same type can be joined!"); + checkArgument( + genericThat instanceof BasicVarIndexingBuilder, + "Only builders of the same type can be joined!"); BasicVarIndexingBuilder that = (BasicVarIndexingBuilder) genericThat; final int newDefaultIndex = max(this.defaultIndex, that.defaultIndex); final Map, Integer> newVarToOffset = Containers.createMap(); - final Set> varDecls = Sets.union(this.varToOffset.keySet(), that.varToOffset.keySet()); + final Set> varDecls = + Sets.union(this.varToOffset.keySet(), that.varToOffset.keySet()); for (final VarDecl varDecl : varDecls) { final int index1 = this.get(varDecl); final int index2 = that.get(varDecl); @@ -289,12 +297,15 @@ public int get(final VarDecl varDecl) { @Override public VarIndexingBuilder copyVars(Map, VarDecl> decls) { checkNotNull(decls); - decls.forEach((varDecl, varDecl2) -> { - if (varToOffset.containsKey(varDecl)) { - checkState(!varToOffset.containsKey(varDecl2), "Cannot copy, as new decl already in map."); - varToOffset.put(varDecl2, varToOffset.get(varDecl)); - } - }); + decls.forEach( + (varDecl, varDecl2) -> { + if (varToOffset.containsKey(varDecl)) { + checkState( + !varToOffset.containsKey(varDecl2), + "Cannot copy, as new decl already in map."); + varToOffset.put(varDecl2, varToOffset.get(varDecl)); + } + }); return this; } @@ -302,7 +313,6 @@ public VarIndexingBuilder copyVars(Map, VarDecl> decls) { public BasicVarIndexing build() { return new BasicVarIndexing(this); } - } @Override diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexing.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexing.java index e85025f19e..b55e108814 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexing.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexing.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils.indexings; import hu.bme.mit.theta.core.decl.VarDecl; diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingBuilder.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingBuilder.java index 7fdad90eb2..957a6aee08 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingBuilder.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils.indexings; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Map; public interface VarIndexingBuilder { diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingFactory.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingFactory.java index 5893141c08..419958765a 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingFactory.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/indexings/VarIndexingFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils.indexings; public class VarIndexingFactory { - public static BasicVarIndexing basicVarIndexing(final int defaultOffset) { return BasicVarIndexing.all(defaultOffset); } diff --git a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/package-info.java b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/package-info.java index 00a9716331..0f4f906362 100644 --- a/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/package-info.java +++ b/subprojects/common/core/src/main/java/hu/bme/mit/theta/core/utils/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,5 +22,4 @@ * @see hu.bme.mit.theta.core.utils.StmtUtils * @see hu.bme.mit.theta.core.utils.TypeUtils */ - -package hu.bme.mit.theta.core.utils; \ No newline at end of file +package hu.bme.mit.theta.core.utils; diff --git a/subprojects/common/core/src/main/kotlin/hu/bme/mit/theta/core/utils/VarChangerUtils.kt b/subprojects/common/core/src/main/kotlin/hu/bme/mit/theta/core/utils/VarChangerUtils.kt index 31838601b9..b3aa4461a7 100644 --- a/subprojects/common/core/src/main/kotlin/hu/bme/mit/theta/core/utils/VarChangerUtils.kt +++ b/subprojects/common/core/src/main/kotlin/hu/bme/mit/theta/core/utils/VarChangerUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils import hu.bme.mit.theta.core.decl.VarDecl @@ -24,43 +23,48 @@ import hu.bme.mit.theta.core.type.anytype.RefExpr import hu.bme.mit.theta.core.utils.TypeUtils.cast fun Stmt.changeVars(variableMapping: Map>): Stmt { - return when (this) { - is AssignStmt<*> -> AssignStmt.of( - cast(varDecl.changeVars(variableMapping), varDecl.type), - cast(expr.changeVars(variableMapping), varDecl.type) - ) + return when (this) { + is AssignStmt<*> -> + AssignStmt.of( + cast(varDecl.changeVars(variableMapping), varDecl.type), + cast(expr.changeVars(variableMapping), varDecl.type), + ) - is HavocStmt<*> -> HavocStmt.of(varDecl.changeVars(variableMapping)) - is AssumeStmt -> AssumeStmt.of(cond.changeVars(variableMapping)) - is SequenceStmt -> SequenceStmt.of(stmts.map { it.changeVars(variableMapping) }) - is SkipStmt -> this - is NonDetStmt -> NonDetStmt.of(stmts.map { it.changeVars(variableMapping) }) - is LoopStmt -> LoopStmt.of( - stmt.changeVars(variableMapping), loopVariable.changeVars(variableMapping), - from.changeVars(variableMapping), to.changeVars(variableMapping) - ) + is HavocStmt<*> -> HavocStmt.of(varDecl.changeVars(variableMapping)) + is AssumeStmt -> AssumeStmt.of(cond.changeVars(variableMapping)) + is SequenceStmt -> SequenceStmt.of(stmts.map { it.changeVars(variableMapping) }) + is SkipStmt -> this + is NonDetStmt -> NonDetStmt.of(stmts.map { it.changeVars(variableMapping) }) + is LoopStmt -> + LoopStmt.of( + stmt.changeVars(variableMapping), + loopVariable.changeVars(variableMapping), + from.changeVars(variableMapping), + to.changeVars(variableMapping), + ) - is IfStmt -> IfStmt.of( - cond.changeVars(variableMapping), then.changeVars(variableMapping), - elze.changeVars(variableMapping) - ) + is IfStmt -> + IfStmt.of( + cond.changeVars(variableMapping), + then.changeVars(variableMapping), + elze.changeVars(variableMapping), + ) - else -> TODO("Not yet implemented") - } + else -> TODO("Not yet implemented") + } } fun Expr.changeVars(variableMapping: Map>): Expr = - if (this is RefExpr) { - when (this.decl) { - is VarDecl -> (this.decl as VarDecl).changeVars(variableMapping).ref - else -> this - } - } else this.withOps(this.ops.map { it.changeVars(variableMapping) }) + if (this is RefExpr) { + when (this.decl) { + is VarDecl -> (this.decl as VarDecl).changeVars(variableMapping).ref + else -> this + } + } else this.withOps(this.ops.map { it.changeVars(variableMapping) }) @SuppressWarnings("kotlin:S6530") fun VarDecl.changeVars(variableMapping: Map>): VarDecl { - val swap = variableMapping[this.name] ?: return this - if (swap.type != this.type) - throw RuntimeException("Can't change variable to different type") - return swap as VarDecl -} \ No newline at end of file + val swap = variableMapping[this.name] ?: return this + if (swap.type != this.type) throw RuntimeException("Can't change variable to different type") + return swap as VarDecl +} diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprDslTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprDslTest.java index 034bc1ef2e..322833e91c 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprDslTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprDslTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -38,9 +38,11 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import hu.bme.mit.theta.core.decl.Decl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,10 +50,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; - @RunWith(Parameterized.class) public class ExprDslTest { @@ -66,27 +64,36 @@ public class ExprDslTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"true or false and not 1%2 > 2%3", - Or(True(), And(False(), Not(Gt(Rat(1, 2), Rat(2, 3))))), null}, - - {"true or (false and not 1 < 2)", Or(True(), And(False(), Not(Lt(Int(1), Int(2))))), - null}, - - {"(true or false) and not - 5 = 4 - 1", - And(Or(True(), False()), Not(Eq(Neg(Int(5)), Sub(Int(4), Int(1))))), null}, - - {"true iff false imply true", Iff(True(), Imply(False(), True())), null}, - - {"1 * 2 * 3 /= 4 - 1", Neq(Mul(Int(1), Int(2), Int(3)), Sub(Int(4), Int(1))), null}, - - {"(1 mod 2) <= 4 / 5", Leq(Mod(Int(1), Int(2)), Div(Int(4), Int(5))), null}, - - {"if 1 >= 2 then 1 rem 2 else 3 mod 5", - Ite(Geq(Int(1), Int(2)), Rem(Int(1), Int(2)), Mod(Int(3), Int(5))), null}, - - }); + return Arrays.asList( + new Object[][] { + { + "true or false and not 1%2 > 2%3", + Or(True(), And(False(), Not(Gt(Rat(1, 2), Rat(2, 3))))), + null + }, + { + "true or (false and not 1 < 2)", + Or(True(), And(False(), Not(Lt(Int(1), Int(2))))), + null + }, + { + "(true or false) and not - 5 = 4 - 1", + And(Or(True(), False()), Not(Eq(Neg(Int(5)), Sub(Int(4), Int(1))))), + null + }, + {"true iff false imply true", Iff(True(), Imply(False(), True())), null}, + { + "1 * 2 * 3 /= 4 - 1", + Neq(Mul(Int(1), Int(2), Int(3)), Sub(Int(4), Int(1))), + null + }, + {"(1 mod 2) <= 4 / 5", Leq(Mod(Int(1), Int(2)), Div(Int(4), Int(5))), null}, + { + "if 1 >= 2 then 1 rem 2 else 3 mod 5", + Ite(Geq(Int(1), Int(2)), Rem(Int(1), Int(2)), Mod(Int(3), Int(5))), + null + }, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprWriteTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprWriteTest.java index cdc5c68a85..a88d1d5b0d 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprWriteTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/ExprWriteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -51,9 +51,15 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; +import hu.bme.mit.theta.core.decl.Decls; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +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.inttype.IntType; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,14 +67,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.Decls; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -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.inttype.IntType; - @RunWith(Parameterized.class) public class ExprWriteTest { @@ -83,43 +81,53 @@ public class ExprWriteTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {And(True(), Or(False(), True(), True())), "true and (false or true or true)"}, - - {Iff(Not(True()), Imply(False(), True())), "(not true) iff (false imply true)"}, - - {Add(Int(1), Sub(Int(2), Int(3)), Int(4), Neg(Int(5))), "1 + (2 - 3) + 4 + (-5)"}, - - {Mul(Int(1), Div(Int(2), Int(3)), Int(4)), "1 * (2 / 3) * 4"}, - - {Mul(Mod(Int(4), Int(3)), Rem(Int(4), Int(3))), "(4 mod 3) * (4 rem 3)"}, - - {And(Eq(Int(1), Int(1)), Lt(Int(1), Int(2)), Gt(Int(2), Int(1))), - "(1 = 1) and (1 < 2) and (2 > 1)"}, - - {And(Neq(Int(1), Int(2)), Leq(Int(1), Int(2)), Geq(Int(2), Int(1))), - "(1 /= 2) and (1 <= 2) and (2 >= 1)"}, - - {Add(Rat(1, 2), Sub(Rat(3, 4), Rat(5, 6)), Rat(7, 8), Neg(Rat(9, 1))), - "1%2 + (3%4 - 5%6) + 7%8 + (-9%1)"}, - - {Mul(Rat(1, 2), Div(Rat(3, 4), Rat(5, 6)), Rat(7, 8)), "1%2 * (3%4 / 5%6) * 7%8"}, - - {And(Eq(Rat(1, 2), Rat(1, 2)), Lt(Rat(1, 2), Rat(3, 4)), Gt(Rat(3, 4), Rat(1, 2))), - "(1%2 = 1%2) and (1%2 < 3%4) and (3%4 > 1%2)"}, - - {And(Neq(Rat(1, 2), Rat(2, 1)), Leq(Rat(1, 2), Rat(3, 4)), Geq(Rat(3, 4), Rat(1, 2))), - "(1%2 /= 2%1) and (1%2 <= 3%4) and (3%4 >= 1%2)"}, - - {And(VX.getRef(), Eq(VY.getRef(), Int(1))), "x and (y = 1)"}, - - {Ite(True(), Int(1), Ite(False(), Int(2), Int(3))), - "if true then 1 else (if false then 2 else 3)"}, - - {Eq(Prime(Prime(VY.getRef())), Prime(VY.getRef())), "((y')') = (y')"} - - }); + return Arrays.asList( + new Object[][] { + {And(True(), Or(False(), True(), True())), "true and (false or true or true)"}, + {Iff(Not(True()), Imply(False(), True())), "(not true) iff (false imply true)"}, + { + Add(Int(1), Sub(Int(2), Int(3)), Int(4), Neg(Int(5))), + "1 + (2 - 3) + 4 + (-5)" + }, + {Mul(Int(1), Div(Int(2), Int(3)), Int(4)), "1 * (2 / 3) * 4"}, + {Mul(Mod(Int(4), Int(3)), Rem(Int(4), Int(3))), "(4 mod 3) * (4 rem 3)"}, + { + And(Eq(Int(1), Int(1)), Lt(Int(1), Int(2)), Gt(Int(2), Int(1))), + "(1 = 1) and (1 < 2) and (2 > 1)" + }, + { + And(Neq(Int(1), Int(2)), Leq(Int(1), Int(2)), Geq(Int(2), Int(1))), + "(1 /= 2) and (1 <= 2) and (2 >= 1)" + }, + { + Add(Rat(1, 2), Sub(Rat(3, 4), Rat(5, 6)), Rat(7, 8), Neg(Rat(9, 1))), + "1%2 + (3%4 - 5%6) + 7%8 + (-9%1)" + }, + { + Mul(Rat(1, 2), Div(Rat(3, 4), Rat(5, 6)), Rat(7, 8)), + "1%2 * (3%4 / 5%6) * 7%8" + }, + { + And( + Eq(Rat(1, 2), Rat(1, 2)), + Lt(Rat(1, 2), Rat(3, 4)), + Gt(Rat(3, 4), Rat(1, 2))), + "(1%2 = 1%2) and (1%2 < 3%4) and (3%4 > 1%2)" + }, + { + And( + Neq(Rat(1, 2), Rat(2, 1)), + Leq(Rat(1, 2), Rat(3, 4)), + Geq(Rat(3, 4), Rat(1, 2))), + "(1%2 /= 2%1) and (1%2 <= 3%4) and (3%4 >= 1%2)" + }, + {And(VX.getRef(), Eq(VY.getRef(), Int(1))), "x and (y = 1)"}, + { + Ite(True(), Int(1), Ite(False(), Int(2), Int(3))), + "if true then 1 else (if false then 2 else 3)" + }, + {Eq(Prime(Prime(VY.getRef())), Prime(VY.getRef())), "((y')') = (y')"} + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtDslTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtDslTest.java index ee2b9181da..2529338a18 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtDslTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtDslTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,24 +15,23 @@ */ package hu.bme.mit.theta.core.dsl; +import static hu.bme.mit.theta.core.stmt.Stmts.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; + import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; - -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; -import static hu.bme.mit.theta.core.stmt.Stmts.*; - @RunWith(Parameterized.class) public class StmtDslTest { @@ -49,15 +48,12 @@ public class StmtDslTest { @Parameterized.Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"assume true", Assume(True()), null}, - - {"x := x + 1", Assign(x, Add(x.getRef(), Int(1))), Collections.singleton(x)}, - - {"havoc x", Havoc(x), Collections.singleton(x)} - - }); + return Arrays.asList( + new Object[][] { + {"assume true", Assume(True()), null}, + {"x := x + 1", Assign(x, Add(x.getRef(), Int(1))), Collections.singleton(x)}, + {"havoc x", Havoc(x), Collections.singleton(x)} + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtWriteTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtWriteTest.java index e03fe196e6..8028dfb6f3 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtWriteTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/StmtWriteTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,15 @@ */ package hu.bme.mit.theta.core.dsl; +import hu.bme.mit.theta.core.decl.Decls; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.stmt.Stmt; +import hu.bme.mit.theta.core.stmt.Stmts; +import hu.bme.mit.theta.core.type.booltype.BoolExprs; +import hu.bme.mit.theta.core.type.inttype.IntExprs; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,14 +31,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.Decls; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.stmt.Stmt; -import hu.bme.mit.theta.core.stmt.Stmts; -import hu.bme.mit.theta.core.type.booltype.BoolExprs; -import hu.bme.mit.theta.core.type.inttype.IntExprs; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public class StmtWriteTest { @@ -46,17 +44,13 @@ public class StmtWriteTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {Stmts.Havoc(VX), "havoc x"}, - - {Stmts.Assume(BoolExprs.False()), "assume false"}, - - {Stmts.Assign(VX, IntExprs.Int(1)), "x := 1"}, - - {Stmts.Skip(), "skip"}, - - }); + return Arrays.asList( + new Object[][] { + {Stmts.Havoc(VX), "havoc x"}, + {Stmts.Assume(BoolExprs.False()), "assume false"}, + {Stmts.Assign(VX, IntExprs.Int(1)), "x := 1"}, + {Stmts.Skip(), "skip"}, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/TypeDslTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/TypeDslTest.java index b86df534ad..3bcbec0e84 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/TypeDslTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/dsl/TypeDslTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,14 +20,13 @@ import hu.bme.mit.theta.core.type.booltype.BoolExprs; import hu.bme.mit.theta.core.type.inttype.IntExprs; import hu.bme.mit.theta.core.type.rattype.RatExprs; +import java.util.Arrays; +import java.util.Collection; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.Arrays; -import java.util.Collection; - @RunWith(Parameterized.class) public class TypeDslTest { @@ -37,30 +36,26 @@ public class TypeDslTest { @Parameterized.Parameter(value = 1) public Type expected; - @Parameterized.Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"int", IntExprs.Int()}, - - {"rat", RatExprs.Rat()}, - - {"bool", BoolExprs.Bool()}, - - {"[int] -> bool", ArrayExprs.Array(IntExprs.Int(), BoolExprs.Bool())}, - - {"[bool] -> rat", ArrayExprs.Array(BoolExprs.Bool(), RatExprs.Rat())}, - - {"[bool] -> [int] -> rat", - ArrayExprs.Array(BoolExprs.Bool(), - ArrayExprs.Array(IntExprs.Int(), RatExprs.Rat()))}, - - {"[[bool] -> int] -> rat", - ArrayExprs.Array(ArrayExprs.Array(BoolExprs.Bool(), IntExprs.Int()), - RatExprs.Rat())}, - - }); + return Arrays.asList( + new Object[][] { + {"int", IntExprs.Int()}, + {"rat", RatExprs.Rat()}, + {"bool", BoolExprs.Bool()}, + {"[int] -> bool", ArrayExprs.Array(IntExprs.Int(), BoolExprs.Bool())}, + {"[bool] -> rat", ArrayExprs.Array(BoolExprs.Bool(), RatExprs.Rat())}, + { + "[bool] -> [int] -> rat", + ArrayExprs.Array( + BoolExprs.Bool(), ArrayExprs.Array(IntExprs.Int(), RatExprs.Rat())) + }, + { + "[[bool] -> int] -> rat", + ArrayExprs.Array( + ArrayExprs.Array(BoolExprs.Bool(), IntExprs.Int()), RatExprs.Rat()) + }, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/EvaluationTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/EvaluationTest.java index 6c8d73f5d3..eaa8a331bb 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/EvaluationTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/EvaluationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,6 @@ */ package hu.bme.mit.theta.core.expr; -import hu.bme.mit.theta.common.Tuple2; -import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.model.ImmutableValuation; -import hu.bme.mit.theta.core.model.Valuation; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.LitExpr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.inttype.IntType; -import org.junit.Test; - -import java.util.ArrayList; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.decl.Decls.Var; import static hu.bme.mit.theta.core.type.anytype.Exprs.Ite; @@ -73,6 +60,18 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.ToInt; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.common.Tuple2; +import hu.bme.mit.theta.core.decl.ConstDecl; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.model.ImmutableValuation; +import hu.bme.mit.theta.core.model.Valuation; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.LitExpr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.ArrayList; +import org.junit.Test; + public class EvaluationTest { private final ConstDecl ca = Const("a", Int()); @@ -84,8 +83,8 @@ private static LitExpr evaluate(final Expr LitExpr evaluate(final Expr expr, - final Valuation val) { + private static LitExpr evaluate( + final Expr expr, final Valuation val) { return expr.eval(val); } @@ -420,7 +419,8 @@ public void testArrayInit() { public void testIte() { assertEquals(Int(1), evaluate(Ite(True(), Int(1), Int(2)))); assertEquals(Int(2), evaluate(Ite(False(), Int(1), Int(2)))); - assertEquals(Int(1), + assertEquals( + Int(1), evaluate(Ite(True(), Ite(True(), Ite(True(), Int(1), Int(2)), Int(3)), Int(4)))); } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/ExprTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/ExprTest.java index c0b32ac48e..c68e602443 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/ExprTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/ExprTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,5 +29,4 @@ public void testPrime() { Assert.assertEquals(Prime(Prime(Int(1))), Prime(Int(1), 2)); Assert.assertEquals(Prime(Prime(Prime(Int(1)))), Prime(Int(1), 3)); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/IdentityTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/IdentityTest.java index 277bec50ef..3f79dcd994 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/IdentityTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/IdentityTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.expr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.utils.ExpressionUtils; +import java.util.Collection; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,8 +25,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import java.util.Collection; - @RunWith(Parameterized.class) public class IdentityTest { @Parameter(value = 0) @@ -35,10 +33,11 @@ public class IdentityTest { @Parameter(value = 1) public Expr expr; - @Parameters(name = "Expression {0}: {1}") public static Collection data() { - return ExpressionUtils.AllExpressions().entrySet().stream().map(e -> new Object[]{e.getKey(), e.getValue()}).toList(); + return ExpressionUtils.AllExpressions().entrySet().stream() + .map(e -> new Object[] {e.getKey(), e.getValue()}) + .toList(); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/RatLitExprTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/RatLitExprTest.java index aabf78d45a..c88a988480 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/RatLitExprTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/RatLitExprTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,10 +18,10 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.type.rattype.RatLitExpr; import java.math.BigInteger; import java.util.Arrays; import java.util.Collection; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,8 +29,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.type.rattype.RatLitExpr; - @RunWith(Parameterized.class) public final class RatLitExprTest { @@ -68,23 +66,16 @@ public void initialize() { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {0, 1, 0, 0, 0, 0, 1}, - - {1, 1, 1, 1, 1, 0, 1}, - - {1, 2, 0, 1, 1, 1, 2}, - - {-1, 2, -1, 0, -1, 1, 2}, - - {-1, 1, -1, -1, -1, 0, 1}, - - {3, 2, 1, 2, 1, 1, 2}, - - {-3, 2, -2, -1, -1, 1, 2} - - }); + return Arrays.asList( + new Object[][] { + {0, 1, 0, 0, 0, 0, 1}, + {1, 1, 1, 1, 1, 0, 1}, + {1, 2, 0, 1, 1, 1, 2}, + {-1, 2, -1, 0, -1, 1, 2}, + {-1, 1, -1, -1, -1, 0, 1}, + {3, 2, 1, 2, 1, 1, 2}, + {-3, 2, -2, -1, -1, 1, 2} + }); } @Test @@ -118,5 +109,4 @@ public void testFrac() { // Assert assertEquals(expectedFrac, actualFrac); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/SmartExprsTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/SmartExprsTest.java index d445b3c7ee..d59540ca39 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/SmartExprsTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/expr/SmartExprsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,10 +23,12 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; import java.util.Arrays; import java.util.Collection; import java.util.Collections; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,10 +36,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; - @RunWith(Parameterized.class) public class SmartExprsTest { @@ -54,46 +52,27 @@ public class SmartExprsTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {True(), SmartBoolExprs.Not(False())}, - - {False(), SmartBoolExprs.Not(True())}, - - {A, SmartBoolExprs.Not(SmartBoolExprs.Not(A))}, - - {Not(A), SmartBoolExprs.Not(SmartBoolExprs.Not(SmartBoolExprs.Not(A)))}, - - {True(), SmartBoolExprs.And(Collections.emptySet())}, - - {A, SmartBoolExprs.And(Collections.singleton(A))}, - - {A, SmartBoolExprs.And(A, True())}, - - {A, SmartBoolExprs.And(A, True(), True())}, - - {False(), SmartBoolExprs.And(A, False(), True())}, - - {True(), SmartBoolExprs.And(True(), True())}, - - {And(A, B, C), SmartBoolExprs.And(A, B, C, True())}, - - {False(), SmartBoolExprs.Or(Collections.emptySet())}, - - {A, SmartBoolExprs.Or(Collections.singleton(A))}, - - {A, SmartBoolExprs.Or(A, False())}, - - {A, SmartBoolExprs.Or(A, False(), False())}, - - {True(), SmartBoolExprs.Or(A, False(), True())}, - - {False(), SmartBoolExprs.Or(False(), False())}, - - {Or(A, B, C), SmartBoolExprs.Or(A, B, C, False())}, - - }); - + return Arrays.asList( + new Object[][] { + {True(), SmartBoolExprs.Not(False())}, + {False(), SmartBoolExprs.Not(True())}, + {A, SmartBoolExprs.Not(SmartBoolExprs.Not(A))}, + {Not(A), SmartBoolExprs.Not(SmartBoolExprs.Not(SmartBoolExprs.Not(A)))}, + {True(), SmartBoolExprs.And(Collections.emptySet())}, + {A, SmartBoolExprs.And(Collections.singleton(A))}, + {A, SmartBoolExprs.And(A, True())}, + {A, SmartBoolExprs.And(A, True(), True())}, + {False(), SmartBoolExprs.And(A, False(), True())}, + {True(), SmartBoolExprs.And(True(), True())}, + {And(A, B, C), SmartBoolExprs.And(A, B, C, True())}, + {False(), SmartBoolExprs.Or(Collections.emptySet())}, + {A, SmartBoolExprs.Or(Collections.singleton(A))}, + {A, SmartBoolExprs.Or(A, False())}, + {A, SmartBoolExprs.Or(A, False(), False())}, + {True(), SmartBoolExprs.Or(A, False(), True())}, + {False(), SmartBoolExprs.Or(False(), False())}, + {Or(A, B, C), SmartBoolExprs.Or(A, B, C, False())}, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionApplyTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionApplyTest.java index 4f7e2707c2..60b296da5d 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionApplyTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionApplyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,20 +21,18 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public class SubstitutionApplyTest { @@ -55,19 +53,25 @@ public class SubstitutionApplyTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {Add(B, Int(3)), BasicSubstitution.builder().build(), Add(B, Int(3))}, - - {Add(B, Int(3)), BasicSubstitution.builder().put(VB, Add(Int(1), Int(2))).build(), - Add(Add(Int(1), Int(2)), Int(3))}, - - {Add(B, Int(3)), BasicSubstitution.builder().put(VB, Add(B, Int(2))).build(), - Add(Add(B, Int(2)), Int(3))}, - - {Div(B, A), BasicSubstitution.builder().put(VB, A).put(VA, B).build(), Div(A, B)}, - - }); + return Arrays.asList( + new Object[][] { + {Add(B, Int(3)), BasicSubstitution.builder().build(), Add(B, Int(3))}, + { + Add(B, Int(3)), + BasicSubstitution.builder().put(VB, Add(Int(1), Int(2))).build(), + Add(Add(Int(1), Int(2)), Int(3)) + }, + { + Add(B, Int(3)), + BasicSubstitution.builder().put(VB, Add(B, Int(2))).build(), + Add(Add(B, Int(2)), Int(3)) + }, + { + Div(B, A), + BasicSubstitution.builder().put(VB, A).put(VA, B).build(), + Div(A, B) + }, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionTest.java index 6721ec8355..58fceff33c 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/SubstitutionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,14 +19,12 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import hu.bme.mit.theta.core.decl.ConstDecl; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Optional; - import org.junit.Assert; import org.junit.Test; -import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.type.inttype.IntType; - public class SubstitutionTest { private final ConstDecl ca = Const("a", Int()); @@ -35,8 +33,8 @@ public class SubstitutionTest { @Test public void testBasic() { - final Substitution sb = BasicSubstitution.builder().put(ca, Add(Int(1), Int(2))) - .put(cb, Int(3)).build(); + final Substitution sb = + BasicSubstitution.builder().put(ca, Add(Int(1), Int(2))).put(cb, Int(3)).build(); Assert.assertEquals(2, sb.getDecls().size()); Assert.assertEquals(Add(Int(1), Int(2)), sb.eval(ca).get()); Assert.assertEquals(Int(3), sb.eval(cb).get()); @@ -45,15 +43,14 @@ public void testBasic() { @Test public void testNested() { - final Substitution sb1 = BasicSubstitution.builder().put(ca, Int(1)).put(cb, Int(2)) - .build(); - final Substitution sb2 = BasicSubstitution.builder().put(ca, Int(3)).put(cc, Int(4)) - .build(); + final Substitution sb1 = + BasicSubstitution.builder().put(ca, Int(1)).put(cb, Int(2)).build(); + final Substitution sb2 = + BasicSubstitution.builder().put(ca, Int(3)).put(cc, Int(4)).build(); final NestedSubstitution sb = NestedSubstitution.create(sb1, sb2); Assert.assertEquals(3, sb.getDecls().size()); Assert.assertEquals(Int(3), sb.eval(ca).get()); Assert.assertEquals(Int(2), sb.eval(cb).get()); Assert.assertEquals(Int(4), sb.eval(cc).get()); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/ValuationTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/ValuationTest.java index 140b69fb23..10e3db90f8 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/ValuationTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/model/ValuationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,11 +21,10 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.inttype.IntType; +import org.junit.Assert; +import org.junit.Test; public class ValuationTest { @@ -106,6 +105,5 @@ public void testEquals() { Assert.assertTrue(v1.equals(v2)); Assert.assertFalse(v1.equals(v3)); Assert.assertFalse(v1.equals(v4)); - } } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/parser/CoreParserTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/parser/CoreParserTest.java index 52ff9ee908..5fa9a93493 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/parser/CoreParserTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/parser/CoreParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -43,11 +43,15 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Sub; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.decl.Decl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.functype.FuncType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.io.Reader; import java.io.StringReader; import java.util.Arrays; import java.util.Collection; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,12 +59,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.functype.FuncType; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public final class CoreParserTest { @@ -90,57 +88,33 @@ public final class CoreParserTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"true", True()}, - - {"false", False()}, - - {"(not x)", Not(X)}, - - {"(and x y z)", And(X, Y, Z)}, - - {"(or x y z)", Or(X, Y, Z)}, - - {"(=> x y)", Imply(X, Y)}, - - {"(iff x y)", Iff(X, Y)}, - - {"(xor x y)", Xor(X, Y)}, - - {"1", Int(1)}, - - {"(+ a b c)", Add(A, B, C)}, - - {"(* a b c)", Mul(A, B, C)}, - - {"(- a b)", Sub(A, B)}, - - {"(/ a b)", Div(A, B)}, - - {"(mod a b)", Mod(A, B)}, - - {"(rem a b)", Rem(A, B)}, - - {"(< a b)", Lt(A, B)}, - - {"(<= a b)", Leq(A, B)}, - - {"(> a b)", Gt(A, B)}, - - {"(>= a b)", Geq(A, B)}, - - {"(= a b)", Eq(A, B)}, - - {"(/= a b)", Neq(A, B)}, - - {"a", A}, - - {"(ite x a b)", Ite(X, A, B)}, - - {"(f a)", App(F, A)} - - }); + return Arrays.asList( + new Object[][] { + {"true", True()}, + {"false", False()}, + {"(not x)", Not(X)}, + {"(and x y z)", And(X, Y, Z)}, + {"(or x y z)", Or(X, Y, Z)}, + {"(=> x y)", Imply(X, Y)}, + {"(iff x y)", Iff(X, Y)}, + {"(xor x y)", Xor(X, Y)}, + {"1", Int(1)}, + {"(+ a b c)", Add(A, B, C)}, + {"(* a b c)", Mul(A, B, C)}, + {"(- a b)", Sub(A, B)}, + {"(/ a b)", Div(A, B)}, + {"(mod a b)", Mod(A, B)}, + {"(rem a b)", Rem(A, B)}, + {"(< a b)", Lt(A, B)}, + {"(<= a b)", Leq(A, B)}, + {"(> a b)", Gt(A, B)}, + {"(>= a b)", Geq(A, B)}, + {"(= a b)", Eq(A, B)}, + {"(/= a b)", Neq(A, B)}, + {"a", A}, + {"(ite x a b)", Ite(X, A, B)}, + {"(f a)", App(F, A)} + }); } @Before @@ -164,5 +138,4 @@ public void test() { // Assert assertEquals(expectedExpr, actualExpr); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/BvTypeTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/BvTypeTest.java index d9ad5110d2..fce8f6675b 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/BvTypeTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/BvTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.core.type; +import static org.junit.Assert.*; + import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.utils.BvTestUtils; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.util.Collection; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static org.junit.Assert.*; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public class BvTypeTest { @@ -43,12 +42,11 @@ public class BvTypeTest { @Parameterized.Parameters(name = "expr: {0}, expected: {1}, actual: {2}") public static Collection operations() { return Stream.concat( - BvTestUtils.BasicOperations().stream(), - Stream.concat( - BvTestUtils.BitvectorOperations().stream(), - BvTestUtils.RelationalOperations().stream() - ) - ).collect(Collectors.toUnmodifiableList()); + BvTestUtils.BasicOperations().stream(), + Stream.concat( + BvTestUtils.BitvectorOperations().stream(), + BvTestUtils.RelationalOperations().stream())) + .collect(Collectors.toUnmodifiableList()); } @Test @@ -60,16 +58,19 @@ public void testBV() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check Valuation val = ImmutableValuation.builder().build(); diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/FpTypeTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/FpTypeTest.java index f5df7bff98..a15e4f2393 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/FpTypeTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/type/FpTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,15 @@ */ package hu.bme.mit.theta.core.type; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.fptype.FpLeqExpr; @@ -22,23 +31,13 @@ import hu.bme.mit.theta.core.type.fptype.FpType; import hu.bme.mit.theta.core.utils.FpTestUtils; import hu.bme.mit.theta.core.utils.FpUtils; +import java.util.Collection; +import java.util.stream.Collectors; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.kframework.mpfr.BigFloat; -import java.util.Collection; -import java.util.stream.Collectors; - -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - @RunWith(Parameterized.class) public class FpTypeTest { @@ -65,16 +64,19 @@ public void testFp() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check Valuation val = ImmutableValuation.builder().build(); @@ -87,11 +89,19 @@ public void testFp() { assertTrue(((FpLitExpr) actual.eval(val)).isPositiveInfinity()); } else { //noinspection unchecked - FpLeqExpr leq = Leq( - Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual.eval(val))), - FpUtils.bigFloatToFpLitExpr(new BigFloat("1e-2", - FpUtils.getMathContext((FpType) actual.getType(), RNE)), - (FpType) actual.getType())); + FpLeqExpr leq = + Leq( + Abs( + Sub( + RNE, + (FpLitExpr) expected, + (Expr) actual.eval(val))), + FpUtils.bigFloatToFpLitExpr( + new BigFloat( + "1e-2", + FpUtils.getMathContext( + (FpType) actual.getType(), RNE)), + (FpType) actual.getType())); assertEquals(Bool(true), leq.eval(val)); } } else { diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprAtomCollectorTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprAtomCollectorTest.java index 71a3390a32..55d98b4775 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprAtomCollectorTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprAtomCollectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,10 +28,12 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Leq; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; import java.util.Set; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,10 +41,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public class ExprAtomCollectorTest { @@ -59,18 +57,16 @@ public class ExprAtomCollectorTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {And(CA, Or(CA, Not(CB))), of(CA, CB)}, - - {Imply(Eq(CX, Int(2)), Not(Leq(CX, CY))), of(Eq(CX, Int(2)), Leq(CX, CY))}, - - {Iff(And(Leq(CX, CY), Eq(CX, CY)), Or(Not(Leq(CX, CY)), CA)), - of(CA, Leq(CX, CY), Eq(CX, CY))}, - - {And(Ite(CA, CA, CB), Not(CA)), of(CA, Ite(CA, CA, CB))}, - - }); + return Arrays.asList( + new Object[][] { + {And(CA, Or(CA, Not(CB))), of(CA, CB)}, + {Imply(Eq(CX, Int(2)), Not(Leq(CX, CY))), of(Eq(CX, Int(2)), Leq(CX, CY))}, + { + Iff(And(Leq(CX, CY), Eq(CX, CY)), Or(Not(Leq(CX, CY)), CA)), + of(CA, Leq(CX, CY), Eq(CX, CY)) + }, + {And(Ite(CA, CA, CB), Not(CA)), of(CA, Ite(CA, CA, CB))}, + }); } @Test @@ -78,5 +74,4 @@ public void test() { final Set> atoms = ExprUtils.getAtoms(expr); Assert.assertEquals(expectedAtoms, atoms); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCanonizerTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCanonizerTest.java index 045f73a36f..bd55c851aa 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCanonizerTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCanonizerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,16 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.anytype.Exprs.Ite; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.*; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.*; +import static hu.bme.mit.theta.core.utils.ExprCanonizer.canonize; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.Expr; @@ -23,25 +33,14 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatExprs; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.anytype.Exprs.Ite; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.*; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.*; -import static hu.bme.mit.theta.core.utils.ExprCanonizer.canonize; -import static org.junit.Assert.assertEquals; - @RunWith(Enclosed.class) public class ExprCanonizerTest { @@ -81,21 +80,13 @@ public static class CommutativeBinaryBoolTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {x, y, - y, x}, - - {x, y, - x, y}, - - {x, True(), - x, True()}, - - {x, True(), - True(), x}, - - }); + return Arrays.asList( + new Object[][] { + {x, y, y, x}, + {x, y, x, y}, + {x, True(), x, True()}, + {x, True(), True(), x}, + }); } @Test @@ -107,7 +98,6 @@ public void testIff() { public void testXor() { assertEquals(canonize(Xor(a1, b1)), canonize(Xor(a2, b2))); } - } @RunWith(Parameterized.class) @@ -127,21 +117,13 @@ public static class CommutativeBinaryIntTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {a, b, - b, a}, - - {a, b, - a, b}, - - {a, Int(1), - a, Int(1)}, - - {a, Int(1), - Int(1), a}, - - }); + return Arrays.asList( + new Object[][] { + {a, b, b, a}, + {a, b, a, b}, + {a, Int(1), a, Int(1)}, + {a, Int(1), Int(1), a}, + }); } @Test @@ -153,7 +135,6 @@ public void testIntEq() { public void testIntNeq() { assertEquals(canonize(IntExprs.Neq(a1, b1)), canonize(IntExprs.Neq(a2, b2))); } - } @RunWith(Parameterized.class) @@ -173,16 +154,11 @@ public static class CommutativeBinaryRatTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {d, d, - d, d}, - - {d, Rat(1, 2), - Rat(1, 2), d}, - - - }); + return Arrays.asList( + new Object[][] { + {d, d, d, d}, + {d, Rat(1, 2), Rat(1, 2), d}, + }); } @Test @@ -194,10 +170,7 @@ public void testRatEq() { public void testRatNeq() { assertEquals(canonize(RatExprs.Neq(a1, b1)), canonize(RatExprs.Neq(a2, b2))); } - - } - } @RunWith(Enclosed.class) @@ -226,22 +199,13 @@ public static class CommutativeMultiaryBoolTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}, {4}, {5}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {x, y, z, - y, x, z}, - - {x, y, z, - x, y, z}, - - {x, True(), x, - x, x, True()}, - - {x, True(), True(), - True(), x, True()}, - - - }); + return Arrays.asList( + new Object[][] { + {x, y, z, y, x, z}, + {x, y, z, x, y, z}, + {x, True(), x, x, x, True()}, + {x, True(), True(), True(), x, True()}, + }); } @Test @@ -253,7 +217,6 @@ public void testAnd() { public void testOr() { assertEquals(canonize(Or(a1, b1, c1)), canonize(Or(a2, b2, c2))); } - } @RunWith(Parameterized.class) @@ -279,35 +242,26 @@ public static class CommutativeMultiaryIntTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}, {4}, {5}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {a, b, b, - b, a, b}, - - {a, b, a, - a, b, a}, - - {a, Int(1), Int(2), - Int(2), a, Int(1)}, - - {a, Int(1), b, - b, Int(1), a}, - - }); + return Arrays.asList( + new Object[][] { + {a, b, b, b, a, b}, + {a, b, a, a, b, a}, + {a, Int(1), Int(2), Int(2), a, Int(1)}, + {a, Int(1), b, b, Int(1), a}, + }); } @Test public void testIntAdd() { - assertEquals(canonize(IntExprs.Add(a1, b1, c1)), - canonize(IntExprs.Add(a2, b2, c2))); + assertEquals( + canonize(IntExprs.Add(a1, b1, c1)), canonize(IntExprs.Add(a2, b2, c2))); } @Test public void testIntMul() { - assertEquals(canonize(IntExprs.Mul(a1, b1, c1)), - canonize(IntExprs.Mul(a2, b2, c2))); + assertEquals( + canonize(IntExprs.Mul(a1, b1, c1)), canonize(IntExprs.Mul(a2, b2, c2))); } - } @RunWith(Parameterized.class) @@ -333,32 +287,25 @@ public static class CommutativeMultiaryRatTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}, {4}, {5}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {d, d, d, - d, d, d}, - - {d, Rat(1, 2), Rat(1, 2), - Rat(1, 2), Rat(1, 2), d}, - - - }); + return Arrays.asList( + new Object[][] { + {d, d, d, d, d, d}, + {d, Rat(1, 2), Rat(1, 2), Rat(1, 2), Rat(1, 2), d}, + }); } @Test public void testRatAdd() { - assertEquals(canonize(RatExprs.Add(a1, b1, c1)), - canonize(RatExprs.Add(a2, b2, c2))); + assertEquals( + canonize(RatExprs.Add(a1, b1, c1)), canonize(RatExprs.Add(a2, b2, c2))); } @Test public void testRatMul() { - assertEquals(canonize(RatExprs.Mul(a1, b1, c1)), - canonize(RatExprs.Mul(a2, b2, c2))); + assertEquals( + canonize(RatExprs.Mul(a1, b1, c1)), canonize(RatExprs.Mul(a2, b2, c2))); } - } - } public static class NonCommutativeTest { @@ -399,21 +346,25 @@ public void testRatDiv() { @Test public void testRatGeq() { - assertEquals(canonize(RatExprs.Geq(Rat(8, 3), Rat(2, 1))), + assertEquals( + canonize(RatExprs.Geq(Rat(8, 3), Rat(2, 1))), canonize(RatExprs.Geq(Rat(8, 3), Rat(2, 1)))); - assertEquals(canonize(RatExprs.Leq(Rat(2, 1), Rat(8, 3))), + assertEquals( + canonize(RatExprs.Leq(Rat(2, 1), Rat(8, 3))), canonize(RatExprs.Geq(Rat(8, 3), Rat(2, 1)))); - assertEquals(canonize(RatExprs.Geq(Rat(8, 4), d)), - canonize(RatExprs.Geq(Rat(8, 4), d))); - assertEquals(canonize(RatExprs.Leq(Rat(2, 1), d)), - canonize(RatExprs.Geq(d, Rat(2, 1)))); + assertEquals( + canonize(RatExprs.Geq(Rat(8, 4), d)), canonize(RatExprs.Geq(Rat(8, 4), d))); + assertEquals( + canonize(RatExprs.Leq(Rat(2, 1), d)), canonize(RatExprs.Geq(d, Rat(2, 1)))); } @Test public void testRatGt() { - assertEquals(canonize(RatExprs.Gt(Rat(8, 3), Rat(2, 1))), + assertEquals( + canonize(RatExprs.Gt(Rat(8, 3), Rat(2, 1))), canonize(RatExprs.Gt(Rat(8, 3), Rat(2, 1)))); - assertEquals(canonize(RatExprs.Lt(Rat(2, 1), Rat(8, 3))), + assertEquals( + canonize(RatExprs.Lt(Rat(2, 1), Rat(8, 3))), canonize(RatExprs.Gt(Rat(8, 3), Rat(2, 1)))); assertEquals(canonize(RatExprs.Gt(Rat(8, 4), d)), canonize(RatExprs.Gt(Rat(8, 4), d))); assertEquals(canonize(RatExprs.Lt(Rat(2, 1), d)), canonize(RatExprs.Gt(d, Rat(2, 1)))); @@ -421,21 +372,25 @@ public void testRatGt() { @Test public void testRatLeq() { - assertEquals(canonize(RatExprs.Leq(Rat(8, 3), Rat(2, 1))), + assertEquals( + canonize(RatExprs.Leq(Rat(8, 3), Rat(2, 1))), canonize(RatExprs.Leq(Rat(8, 3), Rat(2, 1)))); - assertEquals(canonize(RatExprs.Leq(Rat(2, 1), Rat(8, 3))), + assertEquals( + canonize(RatExprs.Leq(Rat(2, 1), Rat(8, 3))), canonize(RatExprs.Geq(Rat(8, 3), Rat(2, 1)))); - assertEquals(canonize(RatExprs.Leq(Rat(8, 4), d)), - canonize(RatExprs.Leq(Rat(8, 4), d))); - assertEquals(canonize(RatExprs.Leq(Rat(2, 1), d)), - canonize(RatExprs.Geq(d, Rat(2, 1)))); + assertEquals( + canonize(RatExprs.Leq(Rat(8, 4), d)), canonize(RatExprs.Leq(Rat(8, 4), d))); + assertEquals( + canonize(RatExprs.Leq(Rat(2, 1), d)), canonize(RatExprs.Geq(d, Rat(2, 1)))); } @Test public void testRatLt() { - assertEquals(canonize(RatExprs.Lt(Rat(8, 3), Rat(2, 1))), + assertEquals( + canonize(RatExprs.Lt(Rat(8, 3), Rat(2, 1))), canonize(RatExprs.Lt(Rat(8, 3), Rat(2, 1)))); - assertEquals(canonize(RatExprs.Lt(Rat(2, 1), Rat(8, 3))), + assertEquals( + canonize(RatExprs.Lt(Rat(2, 1), Rat(8, 3))), canonize(RatExprs.Gt(Rat(8, 3), Rat(2, 1)))); assertEquals(canonize(RatExprs.Lt(Rat(8, 4), d)), canonize(RatExprs.Lt(Rat(8, 4), d))); assertEquals(canonize(RatExprs.Lt(Rat(2, 1), d)), canonize(RatExprs.Gt(d, Rat(2, 1)))); @@ -512,7 +467,8 @@ public void testRef() { public void testIte() { assertEquals(Ite(True(), a, b), canonize(Ite(True(), a, b))); assertEquals(Ite(False(), a, b), canonize(Ite(False(), a, b))); - assertEquals(Ite(True(), Ite(True(), Ite(True(), a, b), b), b), + assertEquals( + Ite(True(), Ite(True(), Ite(True(), a, b), b), b), canonize(Ite(True(), Ite(True(), Ite(True(), a, b), b), b))); } @@ -538,10 +494,9 @@ public void testArrayWrite() { @Test public void testComplex() { - assertEquals(canonize(Iff(Or(False(), x), And(True(), x))), + assertEquals( + canonize(Iff(Or(False(), x), And(True(), x))), canonize(Iff(And(x, True()), Or(x, False())))); } - } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCnfCheckerTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCnfCheckerTest.java index 76963c96b6..2f601a3b46 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCnfCheckerTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprCnfCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,9 +24,10 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; import static hu.bme.mit.theta.core.utils.ExprUtils.isExprCnf; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,9 +35,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; - @RunWith(Parameterized.class) public class ExprCnfCheckerTest { @@ -52,34 +50,35 @@ public class ExprCnfCheckerTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - // A - {A, true}, - // !A - {Not(A), true}, - // !A or B or !C - {Or(Not(A), B, Not(C)), true}, - // !A and B and !C - {And(Not(A), B, Not(C)), true}, - // !A and (B and !C) - {And(Not(A), And(B, Not(C))), true}, - // !A and (B or !C) - {And(Not(A), Or(B, Not(C))), true}, - // !!A - {Not(Not(A)), false}, - // !A and B and !C - {And(Not(A), B, Not(C)), true}, - // !A or (B and !C) - {Or(Not(A), And(B, Not(C))), false}, - // !(A and B) - {Not(And(A, B)), false}, - // !(A or B) - {Not(Or(A, B)), false}, - // A -> B - {Imply(A, B), false}, - // A <-> B - {Iff(A, B), false},}); - + return Arrays.asList( + new Object[][] { + // A + {A, true}, + // !A + {Not(A), true}, + // !A or B or !C + {Or(Not(A), B, Not(C)), true}, + // !A and B and !C + {And(Not(A), B, Not(C)), true}, + // !A and (B and !C) + {And(Not(A), And(B, Not(C))), true}, + // !A and (B or !C) + {And(Not(A), Or(B, Not(C))), true}, + // !!A + {Not(Not(A)), false}, + // !A and B and !C + {And(Not(A), B, Not(C)), true}, + // !A or (B and !C) + {Or(Not(A), And(B, Not(C))), false}, + // !(A and B) + {Not(And(A, B)), false}, + // !(A or B) + {Not(Or(A, B)), false}, + // A -> B + {Imply(A, B), false}, + // A <-> B + {Iff(A, B), false}, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollectorTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollectorTest.java index b0983fd63e..994e5c110c 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollectorTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIndexedVarCollectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,13 +25,19 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import com.google.common.collect.ImmutableMap; +import hu.bme.mit.theta.core.decl.IndexedConstDecl; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,15 +45,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import com.google.common.collect.ImmutableMap; - -import hu.bme.mit.theta.core.decl.IndexedConstDecl; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public class ExprIndexedVarCollectorTest { @@ -68,17 +65,15 @@ public class ExprIndexedVarCollectorTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {And(True(), False(), Eq(Int(1), Int(2))), ImmutableMap.of()}, - - {And(A0.getRef(), Not(A1.getRef())), ImmutableMap.of(0, of(VA), 1, of(VA))}, - - {And(A2.getRef(), A0.getRef(), Eq(B0.getRef(), B1.getRef())), - ImmutableMap.of(0, of(VA, VB), 1, of(VB), 2, of(VA))}, - - }); - + return Arrays.asList( + new Object[][] { + {And(True(), False(), Eq(Int(1), Int(2))), ImmutableMap.of()}, + {And(A0.getRef(), Not(A1.getRef())), ImmutableMap.of(0, of(VA), 1, of(VA))}, + { + And(A2.getRef(), A0.getRef(), Eq(B0.getRef(), B1.getRef())), + ImmutableMap.of(0, of(VA, VB), 1, of(VB), 2, of(VA)) + }, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIteEliminatorTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIteEliminatorTest.java index 02bcc4cdb1..75c9003ff6 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIteEliminatorTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprIteEliminatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -33,16 +33,14 @@ import static hu.bme.mit.theta.core.utils.ExprUtils.eliminateIte; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.ArrayList; import java.util.List; - import org.junit.Before; import org.junit.Test; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; - public class ExprIteEliminatorTest { // Constants for testing @@ -76,7 +74,8 @@ public void testSimple() { assertEquals(eliminateIte(Ite(a, b, c)), And(Or(Not(a), b), Or(a, c))); // if A then (if B then C else D) else E - assertEquals(eliminateIte(Ite(a, Ite(b, c, d), e)), + assertEquals( + eliminateIte(Ite(a, Ite(b, c, d), e)), And(Or(Not(a), And(Or(Not(b), c), Or(b, d))), Or(a, e))); } @@ -99,14 +98,18 @@ public void testBinary() { // (if A then Y else Z) = X assertEquals(eliminateIte(Eq(Ite(a, y, z), x)), And(Or(Not(a), Eq(y, x)), Or(a, Eq(z, x)))); // X = (if A then (if B then Y else Z) else T) - assertEquals(eliminateIte(Eq(x, Ite(a, Ite(b, y, z), t))), + assertEquals( + eliminateIte(Eq(x, Ite(a, Ite(b, y, z), t))), And(Or(Not(a), And(Or(Not(b), Eq(x, y)), Or(b, Eq(x, z)))), Or(a, Eq(x, t)))); // (if A then (if B then Y else Z) else T) = X - assertEquals(eliminateIte(Eq(Ite(a, Ite(b, y, z), t), x)), + assertEquals( + eliminateIte(Eq(Ite(a, Ite(b, y, z), t), x)), And(Or(Not(a), And(Or(Not(b), Eq(y, x)), Or(b, Eq(z, x)))), Or(a, Eq(t, x)))); // (if A then X else Y) = (if B then Z else T) - assertEquals(eliminateIte(Eq(Ite(a, x, y), Ite(b, z, t))), - And(Or(Not(a), And(Or(Not(b), Eq(x, z)), Or(b, Eq(x, t)))), + assertEquals( + eliminateIte(Eq(Ite(a, x, y), Ite(b, z, t))), + And( + Or(Not(a), And(Or(Not(b), Eq(x, z)), Or(b, Eq(x, t)))), Or(a, And(Or(Not(b), Eq(y, z)), Or(b, Eq(y, t)))))); } @@ -115,12 +118,23 @@ public void testMultiary() { // A or B or (if C then D else E) assertEquals(eliminateIte(Or(a, b, Ite(c, d, e))), Or(a, b, And(Or(Not(c), d), Or(c, e)))); // 1 = 2 + (if A then 3 else 4) + 5 - assertEquals(eliminateIte(Eq(i1, Add(i2, Ite(a, i3, i4), i5))), + assertEquals( + eliminateIte(Eq(i1, Add(i2, Ite(a, i3, i4), i5))), And(Or(Not(a), Eq(i1, Add(i2, i3, i5))), Or(a, Eq(i1, Add(i2, i4, i5))))); // 1 = 2 + (if A then 3 else 4) + (if B then X else Y) - assertEquals(eliminateIte(Eq(i1, Add(i2, Ite(a, i3, i4), Ite(b, x, y)))), - And(Or(Not(a), And(Or(Not(b), Eq(i1, Add(i2, i3, x))), Or(b, Eq(i1, Add(i2, i3, y))))), - Or(a, And(Or(Not(b), Eq(i1, Add(i2, i4, x))), Or(b, Eq(i1, Add(i2, i4, y))))))); + assertEquals( + eliminateIte(Eq(i1, Add(i2, Ite(a, i3, i4), Ite(b, x, y)))), + And( + Or( + Not(a), + And( + Or(Not(b), Eq(i1, Add(i2, i3, x))), + Or(b, Eq(i1, Add(i2, i3, y))))), + Or( + a, + And( + Or(Not(b), Eq(i1, Add(i2, i4, x))), + Or(b, Eq(i1, Add(i2, i4, y))))))); } @Test @@ -138,7 +152,8 @@ public void testNothingHappening() { @Test public void testPrime() { // D = (if A then X else Y)' - assertEquals(eliminateIte(Eq(z, Prime(Ite(a, x, y)))), + assertEquals( + eliminateIte(Eq(z, Prime(Ite(a, x, y)))), And(Or(Not(a), Eq(z, Prime(x))), Or(a, Eq(z, Prime(y))))); } } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSimplifierTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSimplifierTest.java index 1d43d4965b..39452ec573 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSimplifierTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSimplifierTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,26 +15,6 @@ */ package hu.bme.mit.theta.core.utils; -import hu.bme.mit.theta.common.Tuple2; -import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.model.ImmutableValuation; -import hu.bme.mit.theta.core.model.Valuation; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.LitExpr; -import hu.bme.mit.theta.core.type.arraytype.ArrayInitExpr; -import hu.bme.mit.theta.core.type.arraytype.ArrayLitExpr; -import hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.bvtype.BvExprs; -import hu.bme.mit.theta.core.type.bvtype.BvType; -import hu.bme.mit.theta.core.type.inttype.IntType; -import hu.bme.mit.theta.core.type.rattype.RatType; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.decl.Decls.Var; import static hu.bme.mit.theta.core.type.anytype.Exprs.Ite; @@ -85,6 +65,25 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import hu.bme.mit.theta.common.Tuple2; +import hu.bme.mit.theta.core.decl.ConstDecl; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.model.ImmutableValuation; +import hu.bme.mit.theta.core.model.Valuation; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.LitExpr; +import hu.bme.mit.theta.core.type.arraytype.ArrayInitExpr; +import hu.bme.mit.theta.core.type.arraytype.ArrayLitExpr; +import hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.bvtype.BvExprs; +import hu.bme.mit.theta.core.type.bvtype.BvType; +import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; + public class ExprSimplifierTest { private final ConstDecl cx = Const("x", Bool()); @@ -264,8 +263,8 @@ public void testIntAdd() { assertEquals(Add(a, Int(4)), simplify(Add(Int(1), Add(a, Int(3))))); assertEquals(a, simplify(Add(Int(-3), a, Int(3)))); assertEquals(Add(a, b, a, b, c), simplify(Add(a, Add(b, Add(a, Add(b, c)))))); - assertEquals(Int("4294967294"), - simplify(Add(Int(Integer.MAX_VALUE), Int(Integer.MAX_VALUE)))); + assertEquals( + Int("4294967294"), simplify(Add(Int(Integer.MAX_VALUE), Int(Integer.MAX_VALUE)))); } @Test @@ -377,339 +376,288 @@ public void testRatToInt() { @Test public void testBvAdd() { assertEquals( - Bv(new boolean[]{false, false, true, true}), - simplify(BvExprs.Add(List.of( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, false, false, true}) - ))) - ); + Bv(new boolean[] {false, false, true, true}), + simplify( + BvExprs.Add( + List.of( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, false, false, true}))))); assertEquals( - BvExprs.Add(List.of( - e, - Bv(new boolean[]{false, false, true, true}) - )), - simplify(BvExprs.Add(List.of( - Bv(new boolean[]{false, false, true, false}), - e, - Bv(new boolean[]{false, false, false, true}) - ))) - ); + BvExprs.Add(List.of(e, Bv(new boolean[] {false, false, true, true}))), + simplify( + BvExprs.Add( + List.of( + Bv(new boolean[] {false, false, true, false}), + e, + Bv(new boolean[] {false, false, false, true}))))); } @Test public void testBvSub() { assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.Sub( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, false, false, true}) - )) - ); + Bv(new boolean[] {false, false, false, true}), + simplify( + BvExprs.Sub( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, false, false, true})))); assertEquals( - BvExprs.Sub( - e, - Bv(new boolean[]{false, false, true, true}) - ), - simplify(BvExprs.Sub( - e, - BvExprs.Add(List.of( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, false, false, true}) - )) - )) - ); + BvExprs.Sub(e, Bv(new boolean[] {false, false, true, true})), + simplify( + BvExprs.Sub( + e, + BvExprs.Add( + List.of( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, false, false, true})))))); } @Test public void testBvNeg() { assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.Neg(Bv(new boolean[]{true, true, true, true}))) - ); + Bv(new boolean[] {false, false, false, true}), + simplify(BvExprs.Neg(Bv(new boolean[] {true, true, true, true})))); assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.Neg(BvExprs.Neg(Bv(new boolean[]{false, false, false, true})))) - ); + Bv(new boolean[] {false, false, false, true}), + simplify(BvExprs.Neg(BvExprs.Neg(Bv(new boolean[] {false, false, false, true}))))); } @Test public void testBvMul() { assertEquals( - Bv(new boolean[]{false, true, true, false}), - simplify(BvExprs.Mul(List.of( - Bv(new boolean[]{false, false, true, true}), - Bv(new boolean[]{false, false, true, false}) - ))) - ); + Bv(new boolean[] {false, true, true, false}), + simplify( + BvExprs.Mul( + List.of( + Bv(new boolean[] {false, false, true, true}), + Bv(new boolean[] {false, false, true, false}))))); assertEquals( - BvExprs.Mul(List.of( - Bv(new boolean[]{false, true, true, false}), - e - )), - simplify(BvExprs.Mul(List.of( - e, - Bv(new boolean[]{false, false, true, true}), - Bv(new boolean[]{false, false, true, false}) - ))) - ); + BvExprs.Mul(List.of(Bv(new boolean[] {false, true, true, false}), e)), + simplify( + BvExprs.Mul( + List.of( + e, + Bv(new boolean[] {false, false, true, true}), + Bv(new boolean[] {false, false, true, false}))))); } @Test public void testBvDiv() { assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.UDiv( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, true}) - )) - ); - assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.UDiv(e, e)) - ); + Bv(new boolean[] {false, false, false, true}), + simplify( + BvExprs.UDiv( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, true})))); + assertEquals(Bv(new boolean[] {false, false, false, true}), simplify(BvExprs.UDiv(e, e))); } @Test public void testBvMod() { assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.SMod( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, true}) - )) - ); - assertEquals( - Bv(new boolean[]{false, false, false, false}), - simplify(BvExprs.SMod(e, e)) - ); + Bv(new boolean[] {false, false, false, true}), + simplify( + BvExprs.SMod( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, true})))); + assertEquals(Bv(new boolean[] {false, false, false, false}), simplify(BvExprs.SMod(e, e))); } @Test public void testBvRem() { assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.URem( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, true}) - )) - ); - assertEquals( - Bv(new boolean[]{false, false, false, false}), - simplify(BvExprs.URem(e, e)) - ); + Bv(new boolean[] {false, false, false, true}), + simplify( + BvExprs.URem( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, true})))); + assertEquals(Bv(new boolean[] {false, false, false, false}), simplify(BvExprs.URem(e, e))); } @Test public void testBvAnd() { assertEquals( - Bv(new boolean[]{false, true, false, false}), - simplify(BvExprs.And(List.of( - Bv(new boolean[]{false, true, false, true}), - Bv(new boolean[]{false, true, true, false}) - ))) - ); + Bv(new boolean[] {false, true, false, false}), + simplify( + BvExprs.And( + List.of( + Bv(new boolean[] {false, true, false, true}), + Bv(new boolean[] {false, true, true, false}))))); assertEquals( - BvExprs.And(List.of( - e, - Bv(new boolean[]{false, true, false, false}) - )), - simplify(BvExprs.And(List.of( - e, - Bv(new boolean[]{false, true, false, true}), - Bv(new boolean[]{false, true, true, false}) - ))) - ); + BvExprs.And(List.of(e, Bv(new boolean[] {false, true, false, false}))), + simplify( + BvExprs.And( + List.of( + e, + Bv(new boolean[] {false, true, false, true}), + Bv(new boolean[] {false, true, true, false}))))); } @Test public void testBvOr() { assertEquals( - Bv(new boolean[]{false, true, true, true}), - simplify(BvExprs.Or(List.of( - Bv(new boolean[]{false, true, false, true}), - Bv(new boolean[]{false, true, true, false}) - ))) - ); + Bv(new boolean[] {false, true, true, true}), + simplify( + BvExprs.Or( + List.of( + Bv(new boolean[] {false, true, false, true}), + Bv(new boolean[] {false, true, true, false}))))); assertEquals( - BvExprs.Or(List.of( - e, - Bv(new boolean[]{false, true, true, true}) - )), - simplify(BvExprs.Or(List.of( - e, - Bv(new boolean[]{false, true, false, true}), - Bv(new boolean[]{false, true, true, false}) - ))) - ); + BvExprs.Or(List.of(e, Bv(new boolean[] {false, true, true, true}))), + simplify( + BvExprs.Or( + List.of( + e, + Bv(new boolean[] {false, true, false, true}), + Bv(new boolean[] {false, true, true, false}))))); } @Test public void testBvXor() { assertEquals( - Bv(new boolean[]{false, false, true, true}), - simplify(BvExprs.Xor(List.of( - Bv(new boolean[]{false, true, false, true}), - Bv(new boolean[]{false, true, true, false}) - ))) - ); + Bv(new boolean[] {false, false, true, true}), + simplify( + BvExprs.Xor( + List.of( + Bv(new boolean[] {false, true, false, true}), + Bv(new boolean[] {false, true, true, false}))))); assertEquals( - BvExprs.Xor(List.of( - e, - Bv(new boolean[]{false, false, true, true}) - )), - simplify(BvExprs.Xor(List.of( - e, - Bv(new boolean[]{false, true, false, true}), - Bv(new boolean[]{false, true, true, false}) - ))) - ); + BvExprs.Xor(List.of(e, Bv(new boolean[] {false, false, true, true}))), + simplify( + BvExprs.Xor( + List.of( + e, + Bv(new boolean[] {false, true, false, true}), + Bv(new boolean[] {false, true, true, false}))))); } @Test public void testBvNot() { assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.Not(Bv(new boolean[]{true, true, true, false}))) - ); + Bv(new boolean[] {false, false, false, true}), + simplify(BvExprs.Not(Bv(new boolean[] {true, true, true, false})))); assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.Not(BvExprs.Not(Bv(new boolean[]{false, false, false, true})))) - ); + Bv(new boolean[] {false, false, false, true}), + simplify(BvExprs.Not(BvExprs.Not(Bv(new boolean[] {false, false, false, true}))))); } @Test public void testBvShift() { assertEquals( - Bv(new boolean[]{false, true, false, false}), - simplify(BvExprs.ShiftLeft( - Bv(new boolean[]{false, false, false, true}), - Bv(new boolean[]{false, false, true, false}) - )) - ); + Bv(new boolean[] {false, true, false, false}), + simplify( + BvExprs.ShiftLeft( + Bv(new boolean[] {false, false, false, true}), + Bv(new boolean[] {false, false, true, false})))); assertEquals( - Bv(new boolean[]{false, false, false, true}), - simplify(BvExprs.ArithShiftRight( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, false}) - )) - ); + Bv(new boolean[] {false, false, false, true}), + simplify( + BvExprs.ArithShiftRight( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, false})))); assertEquals( - Bv(new boolean[]{true, true, true, false}), - simplify(BvExprs.ArithShiftRight( - Bv(new boolean[]{true, true, false, false}), - Bv(new boolean[]{false, false, false, true}) - )) - ); + Bv(new boolean[] {true, true, true, false}), + simplify( + BvExprs.ArithShiftRight( + Bv(new boolean[] {true, true, false, false}), + Bv(new boolean[] {false, false, false, true})))); } @Test public void testBvEq() { assertEquals( True(), - simplify(BvExprs.Eq( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, true, false, false}) - )) - ); + simplify( + BvExprs.Eq( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, true, false, false})))); assertEquals( False(), - simplify(BvExprs.Eq( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, true, false, true}) - )) - ); + simplify( + BvExprs.Eq( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, true, false, true})))); } @Test public void testBvNeq() { assertEquals( False(), - simplify(BvExprs.Neq( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, true, false, false}) - )) - ); + simplify( + BvExprs.Neq( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, true, false, false})))); assertEquals( True(), - simplify(BvExprs.Neq( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, true, false, true}) - )) - ); + simplify( + BvExprs.Neq( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, true, false, true})))); } @Test public void testBvGeq() { assertEquals( True(), - simplify(BvExprs.UGeq( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, false}) - )) - ); + simplify( + BvExprs.UGeq( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, false})))); assertEquals( False(), - simplify(BvExprs.UGeq( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, true, false, true}) - )) - ); + simplify( + BvExprs.UGeq( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, true, false, true})))); } @Test public void testBvGt() { assertEquals( True(), - simplify(BvExprs.UGt( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, false}) - )) - ); + simplify( + BvExprs.UGt( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, false})))); assertEquals( False(), - simplify(BvExprs.UGt( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, true, false, true}) - )) - ); + simplify( + BvExprs.UGt( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, true, false, true})))); } @Test public void testBvLeq() { assertEquals( False(), - simplify(BvExprs.ULeq( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, false}) - )) - ); + simplify( + BvExprs.ULeq( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, false})))); assertEquals( True(), - simplify(BvExprs.ULeq( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, true, false, true}) - )) - ); + simplify( + BvExprs.ULeq( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, true, false, true})))); } @Test public void testBvLt() { assertEquals( False(), - simplify(BvExprs.ULt( - Bv(new boolean[]{false, true, false, false}), - Bv(new boolean[]{false, false, true, false}) - )) - ); + simplify( + BvExprs.ULt( + Bv(new boolean[] {false, true, false, false}), + Bv(new boolean[] {false, false, true, false})))); assertEquals( True(), - simplify(BvExprs.ULt( - Bv(new boolean[]{false, false, true, false}), - Bv(new boolean[]{false, true, false, true}) - )) - ); + simplify( + BvExprs.ULt( + Bv(new boolean[] {false, false, true, false}), + Bv(new boolean[] {false, true, false, true})))); } // Others @@ -766,8 +714,10 @@ public void testArrayInit() { var arr = ArrayInit(elems, Int(100), Array(Int(), Int())); var newArr = simplify(arr); assertTrue(newArr instanceof ArrayInitExpr); - assertEquals(Int(1), - Read(newArr, Int(2)).eval(ImmutableValuation.builder().put(noname, Int(0)).build())); + assertEquals( + Int(1), + Read(newArr, Int(2)) + .eval(ImmutableValuation.builder().put(noname, Int(0)).build())); assertFalse(simplify(Read(newArr, Int(2))) instanceof LitExpr); assertTrue(simplify(Read(newArr, Int(2))) instanceof ArrayReadExpr); } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSizeTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSizeTest.java index b9cb9c3210..6691360b45 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSizeTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprSizeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,21 +25,19 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Sub; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public class ExprSizeTest { @@ -57,21 +55,15 @@ public class ExprSizeTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {True(), 1}, - - {A, 1}, - - {And(A, True()), 3}, - - {And(A, True(), False()), 4}, - - {And(A, And(True(), False())), 5}, - - {Add(B, Sub(Int(1), Int(2)), Int(3)), 6}, - - }); + return Arrays.asList( + new Object[][] { + {True(), 1}, + {A, 1}, + {And(A, True()), 3}, + {And(A, True(), False()), 4}, + {And(A, And(True(), False())), 5}, + {Add(B, Sub(Int(1), Int(2)), Int(3)), 6}, + }); } @Test diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprVarCollectorTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprVarCollectorTest.java index 44ec369782..763f8ca066 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprVarCollectorTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/ExprVarCollectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,23 +29,21 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.core.type.rattype.RatType; import java.util.Arrays; import java.util.Collection; import java.util.Set; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; -import hu.bme.mit.theta.core.type.rattype.RatType; - @RunWith(Parameterized.class) public class ExprVarCollectorTest { @@ -67,15 +65,13 @@ public class ExprVarCollectorTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {And(True(), False(), Eq(Int(1), Int(2))), of()}, - - {And(A, Not(D)), of(VA, VD)}, - - {And(A, Eq(Int(1), B)), of(VA, VB)}, - - {And(Imply(A, D), Eq(C, Rat(2, 3))), of(VA, VC, VD)},}); + return Arrays.asList( + new Object[][] { + {And(True(), False(), Eq(Int(1), Int(2))), of()}, + {And(A, Not(D)), of(VA, VD)}, + {And(A, Eq(Int(1), B)), of(VA, VB)}, + {And(Imply(A, D), Eq(C, Rat(2, 3))), of(VA, VC, VD)}, + }); } @Test @@ -83,5 +79,4 @@ public void test() { final Set> vars = ExprUtils.getVars(expr); assertEquals(expectedVars, vars); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PathUtilsTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PathUtilsTest.java index 15f012efe7..aee9137017 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PathUtilsTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PathUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,18 +20,16 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; -import org.junit.Assert; -import org.junit.Test; - import com.google.common.collect.ImmutableSet; - import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.IndexedConstDecl; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; +import org.junit.Assert; +import org.junit.Test; public class PathUtilsTest { @@ -46,39 +44,57 @@ public class PathUtilsTest { @Test public void testUnfold() { - Assert.assertEquals(Eq(x1.getRef(), Add(y0.getRef(), Int(1))), + Assert.assertEquals( + Eq(x1.getRef(), Add(y0.getRef(), Int(1))), PathUtils.unfold(Eq(Prime(vx.getRef()), Add(vy.getRef(), Int(1))), 0)); - Assert.assertEquals(Eq(x2.getRef(), Add(y1.getRef(), Int(1))), + Assert.assertEquals( + Eq(x2.getRef(), Add(y1.getRef(), Int(1))), PathUtils.unfold(Eq(Prime(vx.getRef()), Add(vy.getRef(), Int(1))), 1)); } @Test public void testUnfoldReversed() { - Assert.assertEquals(Eq(x0.getRef(), Add(x1.getRef(), Int(1))), - PathUtils.unfoldReverse(Eq(Prime(vx.getRef()), Add(vx.getRef(), Int(1))), VarIndexingFactory.indexing(0))); - Assert.assertEquals(Eq(x0.getRef(), Add(x2.getRef(), Int(1))), - PathUtils.unfoldReverse(Eq(Prime(Prime(vx.getRef())), Add(vx.getRef(), Int(1))), VarIndexingFactory.indexing(0))); - Assert.assertEquals(Eq(x0.getRef(), Add(x2.getRef(), x1.getRef())), - PathUtils.unfoldReverse(Eq(Prime(Prime(vx.getRef())), Add(vx.getRef(), Prime(vx.getRef()))), VarIndexingFactory.indexing(0))); + Assert.assertEquals( + Eq(x0.getRef(), Add(x1.getRef(), Int(1))), + PathUtils.unfoldReverse( + Eq(Prime(vx.getRef()), Add(vx.getRef(), Int(1))), + VarIndexingFactory.indexing(0))); + Assert.assertEquals( + Eq(x0.getRef(), Add(x2.getRef(), Int(1))), + PathUtils.unfoldReverse( + Eq(Prime(Prime(vx.getRef())), Add(vx.getRef(), Int(1))), + VarIndexingFactory.indexing(0))); + Assert.assertEquals( + Eq(x0.getRef(), Add(x2.getRef(), x1.getRef())), + PathUtils.unfoldReverse( + Eq(Prime(Prime(vx.getRef())), Add(vx.getRef(), Prime(vx.getRef()))), + VarIndexingFactory.indexing(0))); } @Test public void testFold() { - Assert.assertEquals(Eq(Prime(vx.getRef()), Add(vy.getRef(), Int(1))), + Assert.assertEquals( + Eq(Prime(vx.getRef()), Add(vy.getRef(), Int(1))), PathUtils.foldin(Eq(x1.getRef(), Add(y0.getRef(), Int(1))), 0)); - Assert.assertEquals(Eq(Prime(vx.getRef(), 2), Add(Prime(vy.getRef()), Int(1))), + Assert.assertEquals( + Eq(Prime(vx.getRef(), 2), Add(Prime(vy.getRef()), Int(1))), PathUtils.foldin(Eq(x2.getRef(), Add(y1.getRef(), Int(1))), 0)); - Assert.assertEquals(Eq(Prime(vx.getRef()), Add(vy.getRef(), Int(1))), + Assert.assertEquals( + Eq(Prime(vx.getRef()), Add(vy.getRef(), Int(1))), PathUtils.foldin(Eq(x2.getRef(), Add(y1.getRef(), Int(1))), 1)); } @Test public void testExtractValuation() { - final Valuation valuation = ImmutableValuation.builder().put(x1, Int(1)).put(x2, Int(2)).put(y1, Int(3)) - .build(); + final Valuation valuation = + ImmutableValuation.builder() + .put(x1, Int(1)) + .put(x2, Int(2)) + .put(y1, Int(3)) + .build(); final Valuation extr0 = PathUtils.extractValuation(valuation, 1); Assert.assertEquals(2, extr0.getDecls().size()); diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PonateTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PonateTest.java index 33eb386a7e..5d5108768d 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PonateTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PonateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,12 +20,11 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.inttype.IntType; +import org.junit.Assert; +import org.junit.Test; public class PonateTest { diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PrimeCounterTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PrimeCounterTest.java index d2d8455450..0decde69bb 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PrimeCounterTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/PrimeCounterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,26 +15,25 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Var; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.dsl.CoreDslManager; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; +import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import java.util.Collection; - -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Var; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; - @RunWith(Parameterized.class) public final class PrimeCounterTest { @@ -49,33 +48,21 @@ public final class PrimeCounterTest { @Parameters public static Collection data() { - return asList(new Object[][]{ - - {"true", 0, 0}, - - {"(true)'", 0, 0}, - - {"x", 0, 0}, - - {"not x'", 1, 0}, - - {"x''", 2, 0}, - - {"x' and y", 1, 0}, - - {"(x imply y)'", 1, 1}, - - {"(x' iff y)'", 2, 1}, - - {"a", 0, 0}, - - {"a'", 0, 0}, - - {"x' and a", 1, 0}, - - {"(x' or a)'", 2, 0} - - }); + return asList( + new Object[][] { + {"true", 0, 0}, + {"(true)'", 0, 0}, + {"x", 0, 0}, + {"not x'", 1, 0}, + {"x''", 2, 0}, + {"x' and y", 1, 0}, + {"(x imply y)'", 1, 1}, + {"(x' iff y)'", 2, 1}, + {"a", 0, 0}, + {"a'", 0, 0}, + {"x' and a", 1, 0}, + {"(x' or a)'", 2, 0} + }); } @Test @@ -99,5 +86,4 @@ public void test() { assertEquals(nPrimesOnX, indexing.get(x)); assertEquals(nPrimesOnY, indexing.get(y)); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtSimplifierTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtSimplifierTest.java index d9b1df7e21..e7ea23d4df 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtSimplifierTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtSimplifierTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,33 +20,30 @@ import static hu.bme.mit.theta.core.stmt.Stmts.*; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Gt; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Leq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static org.junit.Assert.assertEquals; -import java.util.Arrays; -import java.util.Collection; -import java.util.Set; - import com.google.common.collect.ImmutableList; -import hu.bme.mit.theta.core.utils.StmtSimplifier; -import hu.bme.mit.theta.core.stmt.NonDetStmt; -import hu.bme.mit.theta.core.stmt.SequenceStmt; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; - import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.MutableValuation; +import hu.bme.mit.theta.core.stmt.NonDetStmt; +import hu.bme.mit.theta.core.stmt.SequenceStmt; import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.inttype.IntType; +import java.util.Arrays; +import java.util.Collection; +import java.util.Set; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public final class StmtSimplifierTest { @@ -70,19 +67,24 @@ public final class StmtSimplifierTest { private static final Stmt ASSIGN_X_1 = Assign(X, Int(1)); private static final Stmt ASSIGN_X_2 = Assign(X, Int(2)); private static final Stmt ASSIGN_X_Y = Assign(X, Y.getRef()); - private static final Stmt SEQ_ASSIGN_X_1_ASSUME_EQ_X_1 = SequenceStmt.of( - ImmutableList.of(ASSIGN_X_1, ASSUME_EQ_X_1)); - private static final Stmt SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0 = SequenceStmt.of( - ImmutableList.of(ASSIGN_X_1, ASSUME_LEQ_X_0)); - private static final Stmt SEQ_ASSIGN_X_1_ASSUME_TRUE = SequenceStmt.of( - ImmutableList.of(ASSIGN_X_1, ASSUME_TRUE)); - private static final Stmt NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0 = NonDetStmt.of( - ImmutableList.of(SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0)); - private static final Stmt NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE = NonDetStmt.of( - ImmutableList.of(SEQ_ASSIGN_X_1_ASSUME_TRUE, SEQ_ASSIGN_X_1_ASSUME_TRUE)); - private static final Stmt NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0_OR_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1 = NonDetStmt.of( - ImmutableList.of(SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0, - SEQ_ASSIGN_X_1_ASSUME_EQ_X_1)); + private static final Stmt SEQ_ASSIGN_X_1_ASSUME_EQ_X_1 = + SequenceStmt.of(ImmutableList.of(ASSIGN_X_1, ASSUME_EQ_X_1)); + private static final Stmt SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0 = + SequenceStmt.of(ImmutableList.of(ASSIGN_X_1, ASSUME_LEQ_X_0)); + private static final Stmt SEQ_ASSIGN_X_1_ASSUME_TRUE = + SequenceStmt.of(ImmutableList.of(ASSIGN_X_1, ASSUME_TRUE)); + private static final Stmt NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0 = + NonDetStmt.of( + ImmutableList.of(SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0)); + private static final Stmt NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE = + NonDetStmt.of(ImmutableList.of(SEQ_ASSIGN_X_1_ASSUME_TRUE, SEQ_ASSIGN_X_1_ASSUME_TRUE)); + private static final Stmt + NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0_OR_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1 = + NonDetStmt.of( + ImmutableList.of( + SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, + SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0, + SEQ_ASSIGN_X_1_ASSUME_EQ_X_1)); @Parameter(0) public Stmt stmt; @@ -95,76 +97,53 @@ public final class StmtSimplifierTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {HAVOC_X, of(X_IS_1), HAVOC_X}, - - {HAVOC_X, of(Y_IS_2), HAVOC_X}, - - {HAVOC_X, of(X_IS_1, Y_IS_2), HAVOC_X}, - - {HAVOC_X, of(), HAVOC_X}, - - {ASSUME_GT_X_0, of(X_IS_1), ASSUME_TRUE}, - - {ASSUME_GT_X_0, of(Y_IS_2), ASSUME_GT_X_0}, - - {ASSUME_GT_X_0, of(X_IS_1, Y_IS_2), ASSUME_TRUE}, - - {ASSUME_GT_X_0, of(), ASSUME_GT_X_0}, - - {ASSUME_LEQ_X_0, of(X_IS_1), ASSUME_FALSE}, - - {ASSUME_LEQ_X_0, of(Y_IS_2), ASSUME_LEQ_X_0}, - - {ASSUME_LEQ_X_0, of(X_IS_1, Y_IS_2), ASSUME_FALSE}, - - {ASSUME_LEQ_X_Y, of(X_IS_1), ASSUME_LEQ_1_Y}, - - {ASSUME_LEQ_X_Y, of(Y_IS_2), ASSUME_LEQ_X_2}, - - {ASSUME_LEQ_X_Y, of(X_IS_1, Y_IS_2), ASSUME_TRUE}, - - {ASSUME_LEQ_X_Y, of(), ASSUME_LEQ_X_Y}, - - {ASSIGN_X_1, of(), ASSIGN_X_1}, - - {ASSIGN_X_1, of(Y_IS_2), ASSIGN_X_1}, - - {ASSIGN_X_1, of(X_IS_1, Y_IS_2), ASSIGN_X_1}, - - {ASSIGN_X_2, of(), ASSIGN_X_2}, - - {ASSIGN_X_2, of(X_IS_1), ASSIGN_X_2}, - - {ASSIGN_X_Y, of(), ASSIGN_X_Y}, - - {ASSIGN_X_Y, of(X_IS_1), ASSIGN_X_Y}, - - {ASSIGN_X_Y, of(X_IS_1), ASSIGN_X_Y}, - - {ASSIGN_X_Y, of(X_IS_1, Y_IS_2), ASSIGN_X_2}, - - {ASSIGN_X_Y, of(Y_IS_2), ASSIGN_X_2}, - - {SKIP, of(X_IS_1), SKIP}, - - {ASSUME_EQ_X_1, of(), ASSUME_EQ_X_1}, - - {SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, of(), SEQ_ASSIGN_X_1_ASSUME_TRUE}, - - {SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0, of(), ASSUME_FALSE}, - - {NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0, of(), - SEQ_ASSIGN_X_1_ASSUME_TRUE}, - - {NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0_OR_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, - of(), NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE}, - - {NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE, of(), - NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE} - - }); + return Arrays.asList( + new Object[][] { + {HAVOC_X, of(X_IS_1), HAVOC_X}, + {HAVOC_X, of(Y_IS_2), HAVOC_X}, + {HAVOC_X, of(X_IS_1, Y_IS_2), HAVOC_X}, + {HAVOC_X, of(), HAVOC_X}, + {ASSUME_GT_X_0, of(X_IS_1), ASSUME_TRUE}, + {ASSUME_GT_X_0, of(Y_IS_2), ASSUME_GT_X_0}, + {ASSUME_GT_X_0, of(X_IS_1, Y_IS_2), ASSUME_TRUE}, + {ASSUME_GT_X_0, of(), ASSUME_GT_X_0}, + {ASSUME_LEQ_X_0, of(X_IS_1), ASSUME_FALSE}, + {ASSUME_LEQ_X_0, of(Y_IS_2), ASSUME_LEQ_X_0}, + {ASSUME_LEQ_X_0, of(X_IS_1, Y_IS_2), ASSUME_FALSE}, + {ASSUME_LEQ_X_Y, of(X_IS_1), ASSUME_LEQ_1_Y}, + {ASSUME_LEQ_X_Y, of(Y_IS_2), ASSUME_LEQ_X_2}, + {ASSUME_LEQ_X_Y, of(X_IS_1, Y_IS_2), ASSUME_TRUE}, + {ASSUME_LEQ_X_Y, of(), ASSUME_LEQ_X_Y}, + {ASSIGN_X_1, of(), ASSIGN_X_1}, + {ASSIGN_X_1, of(Y_IS_2), ASSIGN_X_1}, + {ASSIGN_X_1, of(X_IS_1, Y_IS_2), ASSIGN_X_1}, + {ASSIGN_X_2, of(), ASSIGN_X_2}, + {ASSIGN_X_2, of(X_IS_1), ASSIGN_X_2}, + {ASSIGN_X_Y, of(), ASSIGN_X_Y}, + {ASSIGN_X_Y, of(X_IS_1), ASSIGN_X_Y}, + {ASSIGN_X_Y, of(X_IS_1), ASSIGN_X_Y}, + {ASSIGN_X_Y, of(X_IS_1, Y_IS_2), ASSIGN_X_2}, + {ASSIGN_X_Y, of(Y_IS_2), ASSIGN_X_2}, + {SKIP, of(X_IS_1), SKIP}, + {ASSUME_EQ_X_1, of(), ASSUME_EQ_X_1}, + {SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, of(), SEQ_ASSIGN_X_1_ASSUME_TRUE}, + {SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0, of(), ASSUME_FALSE}, + { + NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0, + of(), + SEQ_ASSIGN_X_1_ASSUME_TRUE + }, + { + NONDET_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1_OR_SEQ_ASSIGN_X_1_ASSUME_LEQ_X_0_OR_SEQ_ASSIGN_X_1_ASSUME_EQ_X_1, + of(), + NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE + }, + { + NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE, + of(), + NONDET_SEQ_ASSIGN_X_1_ASSUME_TRUE_OR_SEQ_ASSIGN_X_1_ASSUME_TRUE + } + }); } @Test @@ -181,5 +160,4 @@ public void test() { // Assert assertEquals(expectedStmt, actualStmt); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtToExprTransformerTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtToExprTransformerTest.java index 9b5c00f6ee..b5bb7885a4 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtToExprTransformerTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/StmtToExprTransformerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitorTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitorTest.java index 4ec07f3a21..e17abf6330 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitorTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarCollectorStmtVisitorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,21 +28,19 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.stmt.Stmt; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; import java.util.Set; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.stmt.Stmt; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public class VarCollectorStmtVisitorTest { @@ -58,23 +56,16 @@ public class VarCollectorStmtVisitorTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {Skip(), of()}, - - {Havoc(VA), of(VA)}, - - {Havoc(VB), of(VB)}, - - {Assign(VB, Int(0)), of(VB)}, - - {Assign(VB, Add(VB.getRef(), VB.getRef())), of(VB)}, - - {Assign(VB, Add(VB.getRef(), VC.getRef())), of(VB, VC)}, - - {Assume(And(VA.getRef(), Eq(VB.getRef(), VC.getRef()))), of(VA, VB, VC)}, - - }); + return Arrays.asList( + new Object[][] { + {Skip(), of()}, + {Havoc(VA), of(VA)}, + {Havoc(VB), of(VB)}, + {Assign(VB, Int(0)), of(VB)}, + {Assign(VB, Add(VB.getRef(), VB.getRef())), of(VB)}, + {Assign(VB, Add(VB.getRef(), VC.getRef())), of(VB, VC)}, + {Assume(And(VA.getRef(), Eq(VB.getRef(), VC.getRef()))), of(VA, VB, VC)}, + }); } @Test @@ -82,5 +73,4 @@ public void test() { final Set> vars = StmtUtils.getVars(stmt); assertEquals(expectedVars, vars); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarIndexingTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarIndexingTest.java index 85cc203fa1..d42aa328ff 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarIndexingTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/VarIndexingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.decl.Decls.Var; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import org.junit.Test; -import static hu.bme.mit.theta.core.decl.Decls.Var; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.junit.Assert.assertEquals; - public class VarIndexingTest { final VarDecl x = Var("x", Int()); @@ -46,8 +46,8 @@ public void testAll() { @Test public void testInc() { - final VarIndexing indexes = VarIndexingFactory.indexingBuilder(0).inc(x).inc(z).inc(x) - .build(); + final VarIndexing indexes = + VarIndexingFactory.indexingBuilder(0).inc(x).inc(z).inc(x).build(); assertEquals(2, indexes.get(x)); assertEquals(0, indexes.get(y)); @@ -56,8 +56,8 @@ public void testInc() { @Test public void testIncNeg() { - final VarIndexing indexes = VarIndexingFactory.basicIndexingBuilder(2).inc(x, -1).inc(z, -1) - .inc(x, -1).build(); + final VarIndexing indexes = + VarIndexingFactory.basicIndexingBuilder(2).inc(x, -1).inc(z, -1).inc(x, -1).build(); assertEquals(0, indexes.get(x)); assertEquals(2, indexes.get(y)); @@ -91,8 +91,8 @@ public void testJoin() { @Test public void testSub() { - final VarIndexing indexes1 = VarIndexingFactory.indexingBuilder(1).inc(x).inc(y).inc(y) - .build(); + final VarIndexing indexes1 = + VarIndexingFactory.indexingBuilder(1).inc(x).inc(y).inc(y).build(); final VarIndexing indexes2 = VarIndexingFactory.indexingBuilder(0).inc(x).inc(z).build(); final VarIndexing sub = indexes1.sub(indexes2); assertEquals(1, sub.get(x)); @@ -113,8 +113,8 @@ public void testSub2() { @Test(expected = IllegalArgumentException.class) public void testSubException() { final VarIndexing indexes1 = VarIndexingFactory.indexingBuilder(1).inc(x).build(); - final VarIndexing indexes2 = VarIndexingFactory.indexingBuilder(0).inc(x).inc(x).inc(x) - .build(); + final VarIndexing indexes2 = + VarIndexingFactory.indexingBuilder(0).inc(x).inc(x).inc(x).build(); indexes1.sub(indexes2); } @@ -124,5 +124,4 @@ public void testSubException2() { final VarIndexing indexes2 = VarIndexingFactory.indexingBuilder(2).build(); indexes1.sub(indexes2); } - } diff --git a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/WpStateTest.java b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/WpStateTest.java index 965b6373b0..0170c276e7 100644 --- a/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/WpStateTest.java +++ b/subprojects/common/core/src/test/java/hu/bme/mit/theta/core/utils/WpStateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,21 +22,19 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.core.decl.VarDecl; +import hu.bme.mit.theta.core.stmt.Stmt; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.inttype.IntType; import java.util.Arrays; import java.util.Collection; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.stmt.Stmt; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.inttype.IntType; - @RunWith(Parameterized.class) public final class WpStateTest { @@ -66,29 +64,19 @@ public final class WpStateTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {TRUE, ASSIGN_X_1, TRUE}, - - {GEQ_X_1, ASSIGN_X_1, TRUE}, - - {GEQ_1_X, ASSIGN_X_1, TRUE}, - - {GEQ_1_Y, ASSIGN_X_1, GEQ_1_Y}, - - {GEQ_X_Y, ASSIGN_X_1, GEQ_1_Y}, - - {TRUE, ASSIGN_Y_X, TRUE}, - - {GEQ_X_1, ASSIGN_Y_X, GEQ_X_1}, - - {GEQ_1_X, ASSIGN_Y_X, GEQ_1_X}, - - {GEQ_1_Y, ASSIGN_Y_X, GEQ_1_X}, - - {GEQ_X_Y, ASSIGN_Y_X, TRUE}, - - }); + return Arrays.asList( + new Object[][] { + {TRUE, ASSIGN_X_1, TRUE}, + {GEQ_X_1, ASSIGN_X_1, TRUE}, + {GEQ_1_X, ASSIGN_X_1, TRUE}, + {GEQ_1_Y, ASSIGN_X_1, GEQ_1_Y}, + {GEQ_X_Y, ASSIGN_X_1, GEQ_1_Y}, + {TRUE, ASSIGN_Y_X, TRUE}, + {GEQ_X_1, ASSIGN_Y_X, GEQ_X_1}, + {GEQ_1_X, ASSIGN_Y_X, GEQ_1_X}, + {GEQ_1_Y, ASSIGN_Y_X, GEQ_1_X}, + {GEQ_X_Y, ASSIGN_Y_X, TRUE}, + }); } @Test @@ -103,5 +91,4 @@ public void test() { // Assert assertEquals(expectedWp, actualWp); } - } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ArrayTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ArrayTestUtils.java index 39eb1e84b9..23ce8f0103 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ArrayTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ArrayTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.type.arraytype.ArrayEqExpr; import hu.bme.mit.theta.core.type.arraytype.ArrayInitExpr; @@ -23,37 +28,61 @@ import hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr; import hu.bme.mit.theta.core.type.arraytype.ArrayType; import hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr; - import java.util.Arrays; import java.util.Collection; import java.util.List; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class ArrayTestUtils { - private ArrayTestUtils() { - } + private ArrayTestUtils() {} public static Collection BasicOperations() { final var c1 = Const("arr", ArrayType.of(Int(), Int())); - return Arrays.asList(new Object[][]{ - - {ArrayReadExpr.class, Int(5), ArrayReadExpr.of(ArrayWriteExpr.of(c1.getRef(), Int(0), Int(5)), Int(0))}, - {ArrayEqExpr.class, True(), ArrayEqExpr.of(c1.getRef(), c1.getRef())}, - {ArrayNeqExpr.class, False(), ArrayNeqExpr.of(c1.getRef(), c1.getRef())}, - - {ArrayReadExpr.class, Int(5), ArrayReadExpr.of(ArrayLitExpr.of(List.of(), Int(5), ArrayType.of(Int(), Int())), Int(42))}, - {ArrayReadExpr.class, Int(5), ArrayReadExpr.of(ArrayInitExpr.of(List.of(), Int(5), ArrayType.of(Int(), Int())), Int(42))}, - - {ArrayReadExpr.class, Int(3), ArrayReadExpr.of(ArrayLitExpr.of(List.of(Tuple2.of(Int(42), Int(3))), Int(5), ArrayType.of(Int(), Int())), Int(42))}, - {ArrayReadExpr.class, Int(3), ArrayReadExpr.of(ArrayInitExpr.of(List.of(Tuple2.of(Int(42), Int(3))), Int(5), ArrayType.of(Int(), Int())), Int(42))}, - }); + return Arrays.asList( + new Object[][] { + { + ArrayReadExpr.class, + Int(5), + ArrayReadExpr.of(ArrayWriteExpr.of(c1.getRef(), Int(0), Int(5)), Int(0)) + }, + {ArrayEqExpr.class, True(), ArrayEqExpr.of(c1.getRef(), c1.getRef())}, + {ArrayNeqExpr.class, False(), ArrayNeqExpr.of(c1.getRef(), c1.getRef())}, + { + ArrayReadExpr.class, + Int(5), + ArrayReadExpr.of( + ArrayLitExpr.of(List.of(), Int(5), ArrayType.of(Int(), Int())), + Int(42)) + }, + { + ArrayReadExpr.class, + Int(5), + ArrayReadExpr.of( + ArrayInitExpr.of(List.of(), Int(5), ArrayType.of(Int(), Int())), + Int(42)) + }, + { + ArrayReadExpr.class, + Int(3), + ArrayReadExpr.of( + ArrayLitExpr.of( + List.of(Tuple2.of(Int(42), Int(3))), + Int(5), + ArrayType.of(Int(), Int())), + Int(42)) + }, + { + ArrayReadExpr.class, + Int(3), + ArrayReadExpr.of( + ArrayInitExpr.of( + List.of(Tuple2.of(Int(42), Int(3))), + Int(5), + ArrayType.of(Int(), Int())), + Int(42)) + }, + }); } - } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BoolTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BoolTestUtils.java index 4d11a5ded7..b9106cfd96 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BoolTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BoolTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,6 @@ */ package hu.bme.mit.theta.core.utils; -import hu.bme.mit.theta.core.type.anytype.IteExpr; -import hu.bme.mit.theta.core.type.booltype.ExistsExpr; -import hu.bme.mit.theta.core.type.booltype.ForallExpr; -import hu.bme.mit.theta.core.type.booltype.ImplyExpr; -import hu.bme.mit.theta.core.type.booltype.OrExpr; -import hu.bme.mit.theta.core.type.booltype.XorExpr; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.decl.Decls.Param; import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq; @@ -42,10 +31,19 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import hu.bme.mit.theta.core.type.anytype.IteExpr; +import hu.bme.mit.theta.core.type.booltype.ExistsExpr; +import hu.bme.mit.theta.core.type.booltype.ForallExpr; +import hu.bme.mit.theta.core.type.booltype.ImplyExpr; +import hu.bme.mit.theta.core.type.booltype.OrExpr; +import hu.bme.mit.theta.core.type.booltype.XorExpr; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + public class BoolTestUtils { - private BoolTestUtils() { - } + private BoolTestUtils() {} public static Collection BasicOperations() { final var p1 = Param("x", Int()); @@ -53,26 +51,42 @@ public static Collection BasicOperations() { final var p3 = Param("z", Int()); final var c1 = Const("c", Int()); - return Arrays.asList(new Object[][]{ - - {IteExpr.class, Ite(Geq(c1.getRef(), Int(0)), Int(1), Int(2)), Ite(Lt(c1.getRef(), Int(0)), Int(2), Int(1))}, - {ImplyExpr.class, False(), Imply(True(), False())}, - {ImplyExpr.class, False(), Imply(True(), False())}, - {XorExpr.class, False(), Xor(True(), True())}, - {OrExpr.class, True(), Or(True(), True())}, - {ExistsExpr.class, True(), Exists(List.of(p1), Eq(p1.getRef(), Int(0)))}, - {ForallExpr.class, False(), Forall(List.of(p1), Eq(p1.getRef(), Int(0)))}, - - {ExistsExpr.class, True(), Exists(List.of(p1), Exists(List.of(p2), Eq(p1.getRef(), p2.getRef())))}, - {ForallExpr.class, False(), Forall(List.of(p1), Forall(List.of(p2), Eq(p1.getRef(), p2.getRef())))}, - - {ExistsExpr.class, False(), Exists(List.of(p1, p2), Exists(List.of(p3), And(List.of( - Lt(p1.getRef(), p2.getRef()), - Lt(p2.getRef(), p3.getRef()), - Lt(p3.getRef(), p1.getRef()) - ))))}, - - }); + return Arrays.asList( + new Object[][] { + { + IteExpr.class, + Ite(Geq(c1.getRef(), Int(0)), Int(1), Int(2)), + Ite(Lt(c1.getRef(), Int(0)), Int(2), Int(1)) + }, + {ImplyExpr.class, False(), Imply(True(), False())}, + {ImplyExpr.class, False(), Imply(True(), False())}, + {XorExpr.class, False(), Xor(True(), True())}, + {OrExpr.class, True(), Or(True(), True())}, + {ExistsExpr.class, True(), Exists(List.of(p1), Eq(p1.getRef(), Int(0)))}, + {ForallExpr.class, False(), Forall(List.of(p1), Eq(p1.getRef(), Int(0)))}, + { + ExistsExpr.class, + True(), + Exists(List.of(p1), Exists(List.of(p2), Eq(p1.getRef(), p2.getRef()))) + }, + { + ForallExpr.class, + False(), + Forall(List.of(p1), Forall(List.of(p2), Eq(p1.getRef(), p2.getRef()))) + }, + { + ExistsExpr.class, + False(), + Exists( + List.of(p1, p2), + Exists( + List.of(p3), + And( + List.of( + Lt(p1.getRef(), p2.getRef()), + Lt(p2.getRef(), p3.getRef()), + Lt(p3.getRef(), p1.getRef()))))) + }, + }); } - } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BvTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BvTestUtils.java index cfb2e00e37..55f94deafd 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BvTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/BvTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,46 +15,6 @@ */ package hu.bme.mit.theta.core.utils; -import hu.bme.mit.theta.core.type.bvtype.BvAddExpr; -import hu.bme.mit.theta.core.type.bvtype.BvAndExpr; -import hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr; -import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr; -import hu.bme.mit.theta.core.type.bvtype.BvEqExpr; -import hu.bme.mit.theta.core.type.bvtype.BvExtractExpr; -import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; -import hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr; -import hu.bme.mit.theta.core.type.bvtype.BvMulExpr; -import hu.bme.mit.theta.core.type.bvtype.BvNegExpr; -import hu.bme.mit.theta.core.type.bvtype.BvNeqExpr; -import hu.bme.mit.theta.core.type.bvtype.BvNotExpr; -import hu.bme.mit.theta.core.type.bvtype.BvOrExpr; -import hu.bme.mit.theta.core.type.bvtype.BvPosExpr; -import hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr; -import hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSExtExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSGtExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSLtExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSModExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr; -import hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr; -import hu.bme.mit.theta.core.type.bvtype.BvSubExpr; -import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr; -import hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr; -import hu.bme.mit.theta.core.type.bvtype.BvUGtExpr; -import hu.bme.mit.theta.core.type.bvtype.BvULeqExpr; -import hu.bme.mit.theta.core.type.bvtype.BvULtExpr; -import hu.bme.mit.theta.core.type.bvtype.BvURemExpr; -import hu.bme.mit.theta.core.type.bvtype.BvXorExpr; -import hu.bme.mit.theta.core.type.bvtype.BvZExtExpr; - -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Add; @@ -96,148 +56,192 @@ import static hu.bme.mit.theta.core.utils.BvUtils.bigIntegerToSignedBvLitExpr; import static hu.bme.mit.theta.core.utils.BvUtils.bigIntegerToUnsignedBvLitExpr; +import hu.bme.mit.theta.core.type.bvtype.BvAddExpr; +import hu.bme.mit.theta.core.type.bvtype.BvAndExpr; +import hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr; +import hu.bme.mit.theta.core.type.bvtype.BvConcatExpr; +import hu.bme.mit.theta.core.type.bvtype.BvEqExpr; +import hu.bme.mit.theta.core.type.bvtype.BvExtractExpr; +import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; +import hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr; +import hu.bme.mit.theta.core.type.bvtype.BvMulExpr; +import hu.bme.mit.theta.core.type.bvtype.BvNegExpr; +import hu.bme.mit.theta.core.type.bvtype.BvNeqExpr; +import hu.bme.mit.theta.core.type.bvtype.BvNotExpr; +import hu.bme.mit.theta.core.type.bvtype.BvOrExpr; +import hu.bme.mit.theta.core.type.bvtype.BvPosExpr; +import hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr; +import hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSDivExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSExtExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSGtExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSLtExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSModExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSRemExpr; +import hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr; +import hu.bme.mit.theta.core.type.bvtype.BvSubExpr; +import hu.bme.mit.theta.core.type.bvtype.BvUDivExpr; +import hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr; +import hu.bme.mit.theta.core.type.bvtype.BvUGtExpr; +import hu.bme.mit.theta.core.type.bvtype.BvULeqExpr; +import hu.bme.mit.theta.core.type.bvtype.BvULtExpr; +import hu.bme.mit.theta.core.type.bvtype.BvURemExpr; +import hu.bme.mit.theta.core.type.bvtype.BvXorExpr; +import hu.bme.mit.theta.core.type.bvtype.BvZExtExpr; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + public class BvTestUtils { - private BvTestUtils() { - } + private BvTestUtils() {} public static Collection BasicOperations() { - return Arrays.asList(new Object[][]{ - /* Unsigned basic operations */ - {BvAddExpr.class, UBv16(4), Add(List.of(UBv16(1), UBv16(3)))}, - {BvSubExpr.class, UBv16(1), Sub(UBv16(4), UBv16(3))}, - {BvMulExpr.class, UBv16(12), Mul(List.of(UBv16(4), UBv16(3)))}, - {BvUDivExpr.class, UBv16(4), UDiv(UBv16(12), UBv16(3))}, - {BvURemExpr.class, UBv16(1), URem(UBv16(13), UBv16(3))}, - - /* Signed basic operations (positive) */ - {BvAddExpr.class, SBv16(4), Add(List.of(SBv16(1), SBv16(3)))}, - {BvSubExpr.class, SBv16(1), Sub(SBv16(4), SBv16(3))}, - {BvMulExpr.class, SBv16(12), Mul(List.of(SBv16(4), SBv16(3)))}, - {BvSDivExpr.class, SBv16(4), SDiv(SBv16(12), SBv16(3))}, - {BvSModExpr.class, SBv16(1), SMod(SBv16(13), SBv16(3))}, - {BvSRemExpr.class, SBv16(1), SRem(SBv16(13), SBv16(3))}, - - /* Signed basic operations (negative) */ - {BvAddExpr.class, SBv16(4), Add(List.of(SBv16(-1), SBv16(5)))}, - {BvSubExpr.class, SBv16(-2), Sub(SBv16(4), SBv16(6))}, - {BvMulExpr.class, SBv16(-12), Mul(List.of(SBv16(-4), SBv16(3)))}, - {BvSDivExpr.class, SBv16(-4), SDiv(SBv16(12), SBv16(-3))}, - {BvSModExpr.class, SBv16(2), SMod(SBv16(-13), SBv16(3))}, - {BvSRemExpr.class, SBv16(1), SRem(SBv16(13), SBv16(3))}, - {BvSRemExpr.class, SBv16(1), SRem(SBv16(13), SBv16(-3))}, - {BvSRemExpr.class, SBv16(-1), SRem(SBv16(-13), SBv16(3))}, - {BvSRemExpr.class, SBv16(-1), SRem(SBv16(-13), SBv16(-3))}, - {BvNegExpr.class, SBv16(-13), Neg(SBv16(13))}, - - /* Signed basic operations (overflow) */ - {BvAddExpr.class, SBv16(-32768), Add(List.of(SBv16(32767), SBv16(1)))}, - {BvSubExpr.class, SBv16(32767), Sub(SBv16(-32768), SBv16(1))}, - {BvMulExpr.class, SBv16(-32768), Mul(List.of(SBv16(16384), SBv16(2)))}, - - {BvPosExpr.class, SBv16(-5), Pos(SBv16(-5))}, - {BvNegExpr.class, SBv16(5), Neg(SBv16(-5))}, - }); + return Arrays.asList( + new Object[][] { + /* Unsigned basic operations */ + {BvAddExpr.class, UBv16(4), Add(List.of(UBv16(1), UBv16(3)))}, + {BvSubExpr.class, UBv16(1), Sub(UBv16(4), UBv16(3))}, + {BvMulExpr.class, UBv16(12), Mul(List.of(UBv16(4), UBv16(3)))}, + {BvUDivExpr.class, UBv16(4), UDiv(UBv16(12), UBv16(3))}, + {BvURemExpr.class, UBv16(1), URem(UBv16(13), UBv16(3))}, + + /* Signed basic operations (positive) */ + {BvAddExpr.class, SBv16(4), Add(List.of(SBv16(1), SBv16(3)))}, + {BvSubExpr.class, SBv16(1), Sub(SBv16(4), SBv16(3))}, + {BvMulExpr.class, SBv16(12), Mul(List.of(SBv16(4), SBv16(3)))}, + {BvSDivExpr.class, SBv16(4), SDiv(SBv16(12), SBv16(3))}, + {BvSModExpr.class, SBv16(1), SMod(SBv16(13), SBv16(3))}, + {BvSRemExpr.class, SBv16(1), SRem(SBv16(13), SBv16(3))}, + + /* Signed basic operations (negative) */ + {BvAddExpr.class, SBv16(4), Add(List.of(SBv16(-1), SBv16(5)))}, + {BvSubExpr.class, SBv16(-2), Sub(SBv16(4), SBv16(6))}, + {BvMulExpr.class, SBv16(-12), Mul(List.of(SBv16(-4), SBv16(3)))}, + {BvSDivExpr.class, SBv16(-4), SDiv(SBv16(12), SBv16(-3))}, + {BvSModExpr.class, SBv16(2), SMod(SBv16(-13), SBv16(3))}, + {BvSRemExpr.class, SBv16(1), SRem(SBv16(13), SBv16(3))}, + {BvSRemExpr.class, SBv16(1), SRem(SBv16(13), SBv16(-3))}, + {BvSRemExpr.class, SBv16(-1), SRem(SBv16(-13), SBv16(3))}, + {BvSRemExpr.class, SBv16(-1), SRem(SBv16(-13), SBv16(-3))}, + {BvNegExpr.class, SBv16(-13), Neg(SBv16(13))}, + + /* Signed basic operations (overflow) */ + {BvAddExpr.class, SBv16(-32768), Add(List.of(SBv16(32767), SBv16(1)))}, + {BvSubExpr.class, SBv16(32767), Sub(SBv16(-32768), SBv16(1))}, + {BvMulExpr.class, SBv16(-32768), Mul(List.of(SBv16(16384), SBv16(2)))}, + {BvPosExpr.class, SBv16(-5), Pos(SBv16(-5))}, + {BvNegExpr.class, SBv16(5), Neg(SBv16(-5))}, + }); } public static Collection BitvectorOperations() { - return Arrays.asList(new Object[][]{ - /* Concat, extract, extend operations */ - { + return Arrays.asList( + new Object[][] { + /* Concat, extract, extend operations */ + { BvConcatExpr.class, - Bv(new boolean[]{true, false, false, true}), - Concat(List.of( - Bv(new boolean[]{true, false}), - Bv(new boolean[]{false, true})) - ) - }, - { + Bv(new boolean[] {true, false, false, true}), + Concat( + List.of( + Bv(new boolean[] {true, false}), + Bv(new boolean[] {false, true}))) + }, + { BvExtractExpr.class, - Bv(new boolean[]{false, false}), - Extract(Bv(new boolean[]{true, false, false, true, false}), Int(2), Int(4)) - }, - { + Bv(new boolean[] {false, false}), + Extract(Bv(new boolean[] {true, false, false, true, false}), Int(2), Int(4)) + }, + { BvZExtExpr.class, - Bv(new boolean[]{false, false, true, false}), - ZExt(Bv(new boolean[]{true, false}), BvType(4)) - }, - { + Bv(new boolean[] {false, false, true, false}), + ZExt(Bv(new boolean[] {true, false}), BvType(4)) + }, + { BvSExtExpr.class, - Bv(new boolean[]{true, true, true, false}), - SExt(Bv(new boolean[]{true, false}), BvType(4)) - }, - - /* Unsigned bitvector specific operations */ - {BvAndExpr.class, UBv16(1), And(List.of(UBv16(7), UBv16(9)))}, - {BvXorExpr.class, UBv16(14), Xor(List.of(UBv16(7), UBv16(9)))}, - {BvOrExpr.class, UBv16(15), Or(List.of(UBv16(7), UBv16(9)))}, - {BvShiftLeftExpr.class, UBv16(56), ShiftLeft(UBv16(7), UBv16(3))}, - {BvArithShiftRightExpr.class, UBv16(3), ArithShiftRight(UBv16(7), UBv16(1))}, - {BvLogicShiftRightExpr.class, UBv16(3), LogicShiftRight(UBv16(7), UBv16(1))}, - {BvRotateLeftExpr.class, UBv16(13), RotateLeft(UBv16(16387), UBv16(2))}, - {BvRotateRightExpr.class, UBv16(16387), RotateRight(UBv16(13), UBv16(2))}, - - /* Signed bitvector specific operations (positive) */ - {BvAndExpr.class, SBv16(1), And(List.of(SBv16(7), SBv16(9)))}, - {BvXorExpr.class, SBv16(14), Xor(List.of(SBv16(7), SBv16(9)))}, - {BvOrExpr.class, SBv16(15), Or(List.of(SBv16(7), SBv16(9)))}, - {BvShiftLeftExpr.class, SBv16(56), ShiftLeft(SBv16(7), SBv16(3))}, - {BvArithShiftRightExpr.class, SBv16(3), ArithShiftRight(SBv16(7), SBv16(1))}, - {BvLogicShiftRightExpr.class, SBv16(3), LogicShiftRight(SBv16(7), SBv16(1))}, - {BvRotateLeftExpr.class, SBv16(13), RotateLeft(SBv16(16387), SBv16(2))}, - {BvRotateRightExpr.class, SBv16(16387), RotateRight(SBv16(13), SBv16(2))}, - - /* Signed bitvector specific operations (negative) */ - {BvAndExpr.class, SBv16(9), And(List.of(SBv16(-7), SBv16(9)))}, - {BvXorExpr.class, SBv16(-16), Xor(List.of(SBv16(-7), SBv16(9)))}, - {BvOrExpr.class, SBv16(-7), Or(List.of(SBv16(-7), SBv16(9)))}, - {BvShiftLeftExpr.class, SBv16(-28), ShiftLeft(SBv16(-7), SBv16(2))}, - {BvArithShiftRightExpr.class, SBv16(-2), ArithShiftRight(SBv16(-7), SBv16(2))}, - {BvLogicShiftRightExpr.class, SBv16(16382), LogicShiftRight(SBv16(-7), SBv16(2))}, - {BvRotateLeftExpr.class, SBv16(14), RotateLeft(SBv16(-32765), SBv16(2))}, - {BvRotateRightExpr.class, SBv16(-32765), RotateRight(SBv16(14), SBv16(2))}, - {BvNotExpr.class, SBv16(-8), Not(SBv16(7))}, - }); + Bv(new boolean[] {true, true, true, false}), + SExt(Bv(new boolean[] {true, false}), BvType(4)) + }, + + /* Unsigned bitvector specific operations */ + {BvAndExpr.class, UBv16(1), And(List.of(UBv16(7), UBv16(9)))}, + {BvXorExpr.class, UBv16(14), Xor(List.of(UBv16(7), UBv16(9)))}, + {BvOrExpr.class, UBv16(15), Or(List.of(UBv16(7), UBv16(9)))}, + {BvShiftLeftExpr.class, UBv16(56), ShiftLeft(UBv16(7), UBv16(3))}, + {BvArithShiftRightExpr.class, UBv16(3), ArithShiftRight(UBv16(7), UBv16(1))}, + {BvLogicShiftRightExpr.class, UBv16(3), LogicShiftRight(UBv16(7), UBv16(1))}, + {BvRotateLeftExpr.class, UBv16(13), RotateLeft(UBv16(16387), UBv16(2))}, + {BvRotateRightExpr.class, UBv16(16387), RotateRight(UBv16(13), UBv16(2))}, + + /* Signed bitvector specific operations (positive) */ + {BvAndExpr.class, SBv16(1), And(List.of(SBv16(7), SBv16(9)))}, + {BvXorExpr.class, SBv16(14), Xor(List.of(SBv16(7), SBv16(9)))}, + {BvOrExpr.class, SBv16(15), Or(List.of(SBv16(7), SBv16(9)))}, + {BvShiftLeftExpr.class, SBv16(56), ShiftLeft(SBv16(7), SBv16(3))}, + {BvArithShiftRightExpr.class, SBv16(3), ArithShiftRight(SBv16(7), SBv16(1))}, + {BvLogicShiftRightExpr.class, SBv16(3), LogicShiftRight(SBv16(7), SBv16(1))}, + {BvRotateLeftExpr.class, SBv16(13), RotateLeft(SBv16(16387), SBv16(2))}, + {BvRotateRightExpr.class, SBv16(16387), RotateRight(SBv16(13), SBv16(2))}, + + /* Signed bitvector specific operations (negative) */ + {BvAndExpr.class, SBv16(9), And(List.of(SBv16(-7), SBv16(9)))}, + {BvXorExpr.class, SBv16(-16), Xor(List.of(SBv16(-7), SBv16(9)))}, + {BvOrExpr.class, SBv16(-7), Or(List.of(SBv16(-7), SBv16(9)))}, + {BvShiftLeftExpr.class, SBv16(-28), ShiftLeft(SBv16(-7), SBv16(2))}, + {BvArithShiftRightExpr.class, SBv16(-2), ArithShiftRight(SBv16(-7), SBv16(2))}, + { + BvLogicShiftRightExpr.class, + SBv16(16382), + LogicShiftRight(SBv16(-7), SBv16(2)) + }, + {BvRotateLeftExpr.class, SBv16(14), RotateLeft(SBv16(-32765), SBv16(2))}, + {BvRotateRightExpr.class, SBv16(-32765), RotateRight(SBv16(14), SBv16(2))}, + {BvNotExpr.class, SBv16(-8), Not(SBv16(7))}, + }); } public static Collection RelationalOperations() { - return Arrays.asList(new Object[][]{ - /* Unsigned relational operations */ - {BvEqExpr.class, True(), Eq(UBv16(4), UBv16(4))}, - {BvEqExpr.class, False(), Eq(UBv16(4), UBv16(5))}, - {BvNeqExpr.class, False(), Neq(UBv16(4), UBv16(4))}, - {BvNeqExpr.class, True(), Neq(UBv16(4), UBv16(5))}, - {BvULtExpr.class, True(), ULt(UBv16(4), UBv16(5))}, - {BvULtExpr.class, False(), ULt(UBv16(4), UBv16(4))}, - {BvULtExpr.class, False(), ULt(UBv16(4), UBv16(3))}, - {BvULeqExpr.class, True(), ULeq(UBv16(4), UBv16(5))}, - {BvULeqExpr.class, True(), ULeq(UBv16(4), UBv16(4))}, - {BvULeqExpr.class, False(), ULeq(UBv16(4), UBv16(3))}, - {BvUGtExpr.class, False(), UGt(UBv16(4), UBv16(5))}, - {BvUGtExpr.class, False(), UGt(UBv16(4), UBv16(4))}, - {BvUGtExpr.class, True(), UGt(UBv16(4), UBv16(3))}, - {BvUGeqExpr.class, False(), UGeq(UBv16(4), UBv16(5))}, - {BvUGeqExpr.class, True(), UGeq(UBv16(4), UBv16(4))}, - {BvUGeqExpr.class, True(), UGeq(UBv16(4), UBv16(3))}, - - /* Signed relational operations */ - {BvEqExpr.class, True(), Eq(SBv16(4), SBv16(4))}, - {BvEqExpr.class, False(), Eq(SBv16(4), SBv16(5))}, - {BvNeqExpr.class, False(), Neq(SBv16(4), SBv16(4))}, - {BvNeqExpr.class, True(), Neq(SBv16(4), SBv16(5))}, - {BvSLtExpr.class, True(), SLt(SBv16(4), SBv16(5))}, - {BvSLtExpr.class, False(), SLt(SBv16(4), SBv16(4))}, - {BvSLtExpr.class, False(), SLt(SBv16(4), SBv16(3))}, - {BvSLeqExpr.class, True(), SLeq(SBv16(4), SBv16(5))}, - {BvSLeqExpr.class, True(), SLeq(SBv16(4), SBv16(4))}, - {BvSLeqExpr.class, False(), SLeq(SBv16(4), SBv16(3))}, - {BvSGtExpr.class, False(), SGt(SBv16(4), SBv16(5))}, - {BvSGtExpr.class, False(), SGt(SBv16(4), SBv16(4))}, - {BvSGtExpr.class, True(), SGt(SBv16(4), SBv16(3))}, - {BvSGeqExpr.class, False(), SGeq(SBv16(4), SBv16(5))}, - {BvSGeqExpr.class, True(), SGeq(SBv16(4), SBv16(4))}, - {BvSGeqExpr.class, True(), SGeq(SBv16(4), SBv16(3))}, - }); + return Arrays.asList( + new Object[][] { + /* Unsigned relational operations */ + {BvEqExpr.class, True(), Eq(UBv16(4), UBv16(4))}, + {BvEqExpr.class, False(), Eq(UBv16(4), UBv16(5))}, + {BvNeqExpr.class, False(), Neq(UBv16(4), UBv16(4))}, + {BvNeqExpr.class, True(), Neq(UBv16(4), UBv16(5))}, + {BvULtExpr.class, True(), ULt(UBv16(4), UBv16(5))}, + {BvULtExpr.class, False(), ULt(UBv16(4), UBv16(4))}, + {BvULtExpr.class, False(), ULt(UBv16(4), UBv16(3))}, + {BvULeqExpr.class, True(), ULeq(UBv16(4), UBv16(5))}, + {BvULeqExpr.class, True(), ULeq(UBv16(4), UBv16(4))}, + {BvULeqExpr.class, False(), ULeq(UBv16(4), UBv16(3))}, + {BvUGtExpr.class, False(), UGt(UBv16(4), UBv16(5))}, + {BvUGtExpr.class, False(), UGt(UBv16(4), UBv16(4))}, + {BvUGtExpr.class, True(), UGt(UBv16(4), UBv16(3))}, + {BvUGeqExpr.class, False(), UGeq(UBv16(4), UBv16(5))}, + {BvUGeqExpr.class, True(), UGeq(UBv16(4), UBv16(4))}, + {BvUGeqExpr.class, True(), UGeq(UBv16(4), UBv16(3))}, + + /* Signed relational operations */ + {BvEqExpr.class, True(), Eq(SBv16(4), SBv16(4))}, + {BvEqExpr.class, False(), Eq(SBv16(4), SBv16(5))}, + {BvNeqExpr.class, False(), Neq(SBv16(4), SBv16(4))}, + {BvNeqExpr.class, True(), Neq(SBv16(4), SBv16(5))}, + {BvSLtExpr.class, True(), SLt(SBv16(4), SBv16(5))}, + {BvSLtExpr.class, False(), SLt(SBv16(4), SBv16(4))}, + {BvSLtExpr.class, False(), SLt(SBv16(4), SBv16(3))}, + {BvSLeqExpr.class, True(), SLeq(SBv16(4), SBv16(5))}, + {BvSLeqExpr.class, True(), SLeq(SBv16(4), SBv16(4))}, + {BvSLeqExpr.class, False(), SLeq(SBv16(4), SBv16(3))}, + {BvSGtExpr.class, False(), SGt(SBv16(4), SBv16(5))}, + {BvSGtExpr.class, False(), SGt(SBv16(4), SBv16(4))}, + {BvSGtExpr.class, True(), SGt(SBv16(4), SBv16(3))}, + {BvSGeqExpr.class, False(), SGeq(SBv16(4), SBv16(5))}, + {BvSGeqExpr.class, True(), SGeq(SBv16(4), SBv16(4))}, + {BvSGeqExpr.class, True(), SGeq(SBv16(4), SBv16(3))}, + }); } private static BvLitExpr UBv16(int integer) { diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ExpressionUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ExpressionUtils.java index 47efd30c40..48f994c14d 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ExpressionUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/ExpressionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.core.utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.QuantifiedExpr; import hu.bme.mit.theta.core.type.functype.FuncAppExpr; - import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -28,7 +26,8 @@ public class ExpressionUtils { private static Stream> getWithAllOps(Expr e) { if (e instanceof QuantifiedExpr || e instanceof FuncAppExpr) { - return Stream.of(e); // we don't want their body to be unwrapped, as they contain ParamDecls + return Stream.of( + e); // we don't want their body to be unwrapped, as they contain ParamDecls } return Stream.concat(Stream.of(e), e.getOps().stream()); } @@ -44,8 +43,6 @@ private static Stream> getWithAllOps(Expr e) { BoolTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[2]), ArrayTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[2]), FuncTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[2]), - - BvTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[1]), BvTestUtils.BitvectorOperations().stream().map(o -> ((Object[]) o)[1]), BvTestUtils.RelationalOperations().stream().map(o -> ((Object[]) o)[1]), @@ -55,10 +52,12 @@ private static Stream> getWithAllOps(Expr e) { BoolTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[1]), ArrayTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[1]), FuncTestUtils.BasicOperations().stream().map(o -> ((Object[]) o)[1])) - - .reduce(Stream::concat).get() + .reduce(Stream::concat) + .get() .map(o -> (Expr) o) .flatMap(ExpressionUtils::getWithAllOps) - .collect(Collectors.toMap(o -> o.getClass().getSimpleName(), o -> o, (expr, expr2) -> expr2)); + .collect( + Collectors.toMap( + o -> o.getClass().getSimpleName(), o -> o, (expr, expr2) -> expr2)); } } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FpTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FpTestUtils.java index 1ac7aa2d51..3997762fa3 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FpTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FpTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,36 @@ */ package hu.bme.mit.theta.core.utils; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Add; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Div; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Eq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpAssign; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpType; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.FromBv; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Geq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Gt; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsInfinite; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Lt; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Max; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Min; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Mul; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Neg; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Neq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Pos; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Rem; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.RoundToIntegral; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sqrt; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.ToBv; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.ToFp; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNA; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RTZ; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.core.type.fptype.FpAbsExpr; @@ -42,170 +72,204 @@ import hu.bme.mit.theta.core.type.fptype.FpSubExpr; import hu.bme.mit.theta.core.type.fptype.FpToBvExpr; import hu.bme.mit.theta.core.type.fptype.FpToFpExpr; -import org.kframework.mpfr.BigFloat; -import org.kframework.mpfr.BinaryMathContext; - import java.math.BigInteger; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.stream.Stream; - -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Add; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Div; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Eq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpAssign; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpType; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.FromBv; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Geq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Gt; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsInfinite; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Lt; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Max; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Min; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Mul; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Neg; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Neq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Pos; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Rem; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.RoundToIntegral; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sqrt; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.ToBv; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.ToFp; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNA; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RTZ; +import org.kframework.mpfr.BigFloat; +import org.kframework.mpfr.BinaryMathContext; public class FpTestUtils { - private static final BinaryMathContext BINARY16 = BinaryMathContext.BINARY16.withRoundingMode( - FpUtils.getMathContextRoundingMode(RNE)); - private static final BinaryMathContext BINARY32 = BinaryMathContext.BINARY32.withRoundingMode( - FpUtils.getMathContextRoundingMode(RNE)); - private static final BinaryMathContext BINARY64 = BinaryMathContext.BINARY64.withRoundingMode( - FpUtils.getMathContextRoundingMode(RNE)); + private static final BinaryMathContext BINARY16 = + BinaryMathContext.BINARY16.withRoundingMode(FpUtils.getMathContextRoundingMode(RNE)); + private static final BinaryMathContext BINARY32 = + BinaryMathContext.BINARY32.withRoundingMode(FpUtils.getMathContextRoundingMode(RNE)); + private static final BinaryMathContext BINARY64 = + BinaryMathContext.BINARY64.withRoundingMode(FpUtils.getMathContextRoundingMode(RNE)); - private FpTestUtils() { - } + private FpTestUtils() {} public static Stream GetOperations() { return Stream.concat( Stream.concat( BasicOperations().stream(), Stream.concat( - LinuxSpecificTests().stream(), - WindowsSpecificTests().stream())), - Stream.concat( - NaNOperations().stream(), - InfinityOperations().stream() - )); + LinuxSpecificTests().stream(), WindowsSpecificTests().stream())), + Stream.concat(NaNOperations().stream(), InfinityOperations().stream())); } private static Collection BasicOperations() { - return Arrays.asList(new Object[][]{ - {FpAddExpr.class, Fp16("5.5"), Add(RNE, List.of(Fp16("2.1"), Fp16("3.4")))}, - {FpSubExpr.class, Fp16("2.1"), Sub(RNE, Fp16("5.5"), Fp16("3.4"))}, - {FpPosExpr.class, Fp16("2.1"), Pos(Fp16("2.1"))}, - {FpNegExpr.class, Fp16("-2.1"), Neg(Fp16("2.1"))}, - {FpMulExpr.class, Fp16("7.14"), Mul(RNE, List.of(Fp16("2.1"), Fp16("3.4")))}, - {FpDivExpr.class, Fp16("2.1"), Div(RNE, Fp16("7.14"), Fp16("3.4"))}, - {FpEqExpr.class, Bool(true), Eq(Fp16("7.14"), Fp16("7.14"))}, - {FpEqExpr.class, Bool(false), Eq(Fp16("7.14"), Fp16("7.15"))}, - {FpEqExpr.class, Bool(false), Eq(Fp16NaN(), Fp16NaN())}, - {FpAssignExpr.class, Bool(true), FpAssign(Fp16NaN(), Fp16NaN())}, - {FpNeqExpr.class, Bool(true), Neq(Fp16("-7.14"), Fp16("7.14"))}, - {FpNeqExpr.class, Bool(false), Neq(Fp16("-7.14"), Fp16("-7.14"))}, - {FpAbsExpr.class, Fp16("2.1"), Abs(Fp16("2.1"))}, - {FpAbsExpr.class, Fp16("2.1"), Abs(Fp16("-2.1"))}, - {FpGeqExpr.class, Bool(true), Geq(Fp16("7.15"), Fp16("7.14"))}, - {FpGeqExpr.class, Bool(true), Geq(Fp16("7.14"), Fp16("7.14"))}, - {FpGeqExpr.class, Bool(false), Geq(Fp16("-7.15"), Fp16("-7.14"))}, - {FpGtExpr.class, Bool(true), Gt(Fp16("7.15"), Fp16("7.14"))}, - {FpGtExpr.class, Bool(false), Gt(Fp16("7.14"), Fp16("7.14"))}, - {FpGtExpr.class, Bool(false), Gt(Fp16("-7.15"), Fp16("-7.14"))}, - {FpIsNanExpr.class, Bool(true), IsNan(Fp16NaN())}, - {FpIsNanExpr.class, Bool(false), IsNan(Fp16PInf())}, - {FpIsNanExpr.class, Bool(false), IsNan(Fp16NInf())}, - {FpIsNanExpr.class, Bool(false), IsNan(Fp16("0.0"))}, - {FpIsInfiniteExpr.class, Bool(false), IsInfinite(Fp16("0.0"))}, - {FpIsInfiniteExpr.class, Bool(true), IsInfinite(FpTestUtils.Fp16PInf())}, - {FpIsInfiniteExpr.class, Bool(true), IsInfinite(FpTestUtils.Fp16NInf())}, - {FpLeqExpr.class, Bool(true), Leq(Fp16("7.14"), Fp16("7.15"))}, - {FpLeqExpr.class, Bool(true), Leq(Fp16("7.14"), Fp16("7.14"))}, - {FpLeqExpr.class, Bool(false), Leq(Fp16("-7.14"), Fp16("-7.15"))}, - {FpLtExpr.class, Bool(true), Lt(Fp16("7.14"), Fp16("7.15"))}, - {FpLtExpr.class, Bool(false), Lt(Fp16("7.14"), Fp16("7.14"))}, - {FpLtExpr.class, Bool(false), Lt(Fp16("-7.14"), Fp16("-7.15"))}, - {FpMaxExpr.class, Fp16("2.1"), Max(Fp16("-2.1"), Fp16("2.1"))}, - {FpMaxExpr.class, Fp16("2.1"), Max(Fp16("1.9"), Fp16("2.1"))}, - {FpMinExpr.class, Fp16("-2.1"), Min(Fp16("-2.1"), Fp16("2.1"))}, - {FpMinExpr.class, Fp16("1.9"), Min(Fp16("1.9"), Fp16("2.1"))}, - {FpRemExpr.class, Fp16("0.1"), Rem(Fp16("4.3"), Fp16("2.1"))}, - {FpRemExpr.class, Fp16("-0.1"), Rem(Fp16("-4.3"), Fp16("2.1"))}, - {FpRemExpr.class, Fp16("0.1"), Rem(Fp16("4.3"), Fp16("-2.1"))}, - {FpRemExpr.class, Fp16("-0.1"), Rem(Fp16("-4.3"), Fp16("-2.1"))}, - {FpRoundToIntegralExpr.class, Fp16("2.0"), RoundToIntegral(RNE, Fp16("2.49"))}, - {FpRoundToIntegralExpr.class, Fp16("-10.0"), RoundToIntegral(RNE, Fp16("-10.49"))}, - {FpSqrtExpr.class, Fp16("2.1"), Sqrt(RNE, Fp16("4.41"))}, - {FpSqrtExpr.class, Fp16("3.0"), Sqrt(RNE, Fp16("9.0"))}, - {FpSqrtExpr.class, Fp16("0.1"), Sqrt(RNE, Fp16("0.01"))}, - {FpToBvExpr.class, BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.TEN, 16), - ToBv(RTZ, Fp16("10.9"), 16, false)}, - // {FpToBvExpr.class, BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.TEN, 3), - // ToBv(RTZ, Fp16("10.9"), 3, false)}, - {FpToBvExpr.class, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN, 16), - ToBv(RTZ, Fp16("10.9"), 16, true)}, - // {FpToBvExpr.class, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN, 4), - // ToBv(RTZ, Fp16("10.9"), 4, true)}, - {FpToBvExpr.class, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN.negate(), 16), - ToBv(RTZ, Fp16("-10.9"), 16, true)}, - // {FpToBvExpr.class, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN.negate(), 4), - // ToBv(RTZ, Fp16("-10.9"), 4, true)}, - {FpToFpExpr.class, Fp32("12.0"), ToFp(RNE, Fp16("12.0"), 8, 24)}, - {FpToFpExpr.class, Fp64("12.0"), ToFp(RNE, Fp16("12.0"), 11, 53)}, - {FpToFpExpr.class, Fp16("12.0"), ToFp(RNE, Fp32("12.0"), 5, 11)}, - {FpFromBvExpr.class, Fp16("0"), - FromBv(RNE, BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.ZERO, 16), - FpType(5, 11), false)}, - {FpFromBvExpr.class, Fp16("1"), - FromBv(RNE, BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.ONE, 16), - FpType(5, 11), false)}, - {FpFromBvExpr.class, Fp16("10"), - FromBv(RNE, BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.TEN, 16), - FpType(5, 11), false)}, - {FpFromBvExpr.class, Fp16("0"), - FromBv(RNE, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ZERO, 16), FpType(5, 11), - true)}, - {FpFromBvExpr.class, Fp16("1"), - FromBv(RNE, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ONE, 16), FpType(5, 11), - true)}, - {FpFromBvExpr.class, Fp16("10"), - FromBv(RNE, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN, 16), FpType(5, 11), - true)}, - {FpFromBvExpr.class, Fp16("0"), - FromBv(RNE, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ZERO.negate(), 16), - FpType(5, 11), true)}, - {FpFromBvExpr.class, Fp16("-1"), - FromBv(RNE, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ONE.negate(), 16), - FpType(5, 11), true)}, - {FpFromBvExpr.class, Fp16("-10"), - FromBv(RNE, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN.negate(), 16), - FpType(5, 11), true)}, - }); + return Arrays.asList( + new Object[][] { + {FpAddExpr.class, Fp16("5.5"), Add(RNE, List.of(Fp16("2.1"), Fp16("3.4")))}, + {FpSubExpr.class, Fp16("2.1"), Sub(RNE, Fp16("5.5"), Fp16("3.4"))}, + {FpPosExpr.class, Fp16("2.1"), Pos(Fp16("2.1"))}, + {FpNegExpr.class, Fp16("-2.1"), Neg(Fp16("2.1"))}, + {FpMulExpr.class, Fp16("7.14"), Mul(RNE, List.of(Fp16("2.1"), Fp16("3.4")))}, + {FpDivExpr.class, Fp16("2.1"), Div(RNE, Fp16("7.14"), Fp16("3.4"))}, + {FpEqExpr.class, Bool(true), Eq(Fp16("7.14"), Fp16("7.14"))}, + {FpEqExpr.class, Bool(false), Eq(Fp16("7.14"), Fp16("7.15"))}, + {FpEqExpr.class, Bool(false), Eq(Fp16NaN(), Fp16NaN())}, + {FpAssignExpr.class, Bool(true), FpAssign(Fp16NaN(), Fp16NaN())}, + {FpNeqExpr.class, Bool(true), Neq(Fp16("-7.14"), Fp16("7.14"))}, + {FpNeqExpr.class, Bool(false), Neq(Fp16("-7.14"), Fp16("-7.14"))}, + {FpAbsExpr.class, Fp16("2.1"), Abs(Fp16("2.1"))}, + {FpAbsExpr.class, Fp16("2.1"), Abs(Fp16("-2.1"))}, + {FpGeqExpr.class, Bool(true), Geq(Fp16("7.15"), Fp16("7.14"))}, + {FpGeqExpr.class, Bool(true), Geq(Fp16("7.14"), Fp16("7.14"))}, + {FpGeqExpr.class, Bool(false), Geq(Fp16("-7.15"), Fp16("-7.14"))}, + {FpGtExpr.class, Bool(true), Gt(Fp16("7.15"), Fp16("7.14"))}, + {FpGtExpr.class, Bool(false), Gt(Fp16("7.14"), Fp16("7.14"))}, + {FpGtExpr.class, Bool(false), Gt(Fp16("-7.15"), Fp16("-7.14"))}, + {FpIsNanExpr.class, Bool(true), IsNan(Fp16NaN())}, + {FpIsNanExpr.class, Bool(false), IsNan(Fp16PInf())}, + {FpIsNanExpr.class, Bool(false), IsNan(Fp16NInf())}, + {FpIsNanExpr.class, Bool(false), IsNan(Fp16("0.0"))}, + {FpIsInfiniteExpr.class, Bool(false), IsInfinite(Fp16("0.0"))}, + {FpIsInfiniteExpr.class, Bool(true), IsInfinite(FpTestUtils.Fp16PInf())}, + {FpIsInfiniteExpr.class, Bool(true), IsInfinite(FpTestUtils.Fp16NInf())}, + {FpLeqExpr.class, Bool(true), Leq(Fp16("7.14"), Fp16("7.15"))}, + {FpLeqExpr.class, Bool(true), Leq(Fp16("7.14"), Fp16("7.14"))}, + {FpLeqExpr.class, Bool(false), Leq(Fp16("-7.14"), Fp16("-7.15"))}, + {FpLtExpr.class, Bool(true), Lt(Fp16("7.14"), Fp16("7.15"))}, + {FpLtExpr.class, Bool(false), Lt(Fp16("7.14"), Fp16("7.14"))}, + {FpLtExpr.class, Bool(false), Lt(Fp16("-7.14"), Fp16("-7.15"))}, + {FpMaxExpr.class, Fp16("2.1"), Max(Fp16("-2.1"), Fp16("2.1"))}, + {FpMaxExpr.class, Fp16("2.1"), Max(Fp16("1.9"), Fp16("2.1"))}, + {FpMinExpr.class, Fp16("-2.1"), Min(Fp16("-2.1"), Fp16("2.1"))}, + {FpMinExpr.class, Fp16("1.9"), Min(Fp16("1.9"), Fp16("2.1"))}, + {FpRemExpr.class, Fp16("0.1"), Rem(Fp16("4.3"), Fp16("2.1"))}, + {FpRemExpr.class, Fp16("-0.1"), Rem(Fp16("-4.3"), Fp16("2.1"))}, + {FpRemExpr.class, Fp16("0.1"), Rem(Fp16("4.3"), Fp16("-2.1"))}, + {FpRemExpr.class, Fp16("-0.1"), Rem(Fp16("-4.3"), Fp16("-2.1"))}, + {FpRoundToIntegralExpr.class, Fp16("2.0"), RoundToIntegral(RNE, Fp16("2.49"))}, + { + FpRoundToIntegralExpr.class, + Fp16("-10.0"), + RoundToIntegral(RNE, Fp16("-10.49")) + }, + {FpSqrtExpr.class, Fp16("2.1"), Sqrt(RNE, Fp16("4.41"))}, + {FpSqrtExpr.class, Fp16("3.0"), Sqrt(RNE, Fp16("9.0"))}, + {FpSqrtExpr.class, Fp16("0.1"), Sqrt(RNE, Fp16("0.01"))}, + { + FpToBvExpr.class, + BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.TEN, 16), + ToBv(RTZ, Fp16("10.9"), 16, false) + }, + // {FpToBvExpr.class, BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.TEN, 3), + // ToBv(RTZ, Fp16("10.9"), 3, false)}, + { + FpToBvExpr.class, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN, 16), + ToBv(RTZ, Fp16("10.9"), 16, true) + }, + // {FpToBvExpr.class, BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN, 4), + // ToBv(RTZ, Fp16("10.9"), 4, true)}, + { + FpToBvExpr.class, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN.negate(), 16), + ToBv(RTZ, Fp16("-10.9"), 16, true) + }, + // {FpToBvExpr.class, + // BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN.negate(), 4), + // ToBv(RTZ, Fp16("-10.9"), 4, true)}, + {FpToFpExpr.class, Fp32("12.0"), ToFp(RNE, Fp16("12.0"), 8, 24)}, + {FpToFpExpr.class, Fp64("12.0"), ToFp(RNE, Fp16("12.0"), 11, 53)}, + {FpToFpExpr.class, Fp16("12.0"), ToFp(RNE, Fp32("12.0"), 5, 11)}, + { + FpFromBvExpr.class, + Fp16("0"), + FromBv( + RNE, + BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.ZERO, 16), + FpType(5, 11), + false) + }, + { + FpFromBvExpr.class, + Fp16("1"), + FromBv( + RNE, + BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.ONE, 16), + FpType(5, 11), + false) + }, + { + FpFromBvExpr.class, + Fp16("10"), + FromBv( + RNE, + BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.TEN, 16), + FpType(5, 11), + false) + }, + { + FpFromBvExpr.class, + Fp16("0"), + FromBv( + RNE, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ZERO, 16), + FpType(5, 11), + true) + }, + { + FpFromBvExpr.class, + Fp16("1"), + FromBv( + RNE, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ONE, 16), + FpType(5, 11), + true) + }, + { + FpFromBvExpr.class, + Fp16("10"), + FromBv( + RNE, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN, 16), + FpType(5, 11), + true) + }, + { + FpFromBvExpr.class, + Fp16("0"), + FromBv( + RNE, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ZERO.negate(), 16), + FpType(5, 11), + true) + }, + { + FpFromBvExpr.class, + Fp16("-1"), + FromBv( + RNE, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.ONE.negate(), 16), + FpType(5, 11), + true) + }, + { + FpFromBvExpr.class, + Fp16("-10"), + FromBv( + RNE, + BvUtils.bigIntegerToSignedBvLitExpr(BigInteger.TEN.negate(), 16), + FpType(5, 11), + true) + }, + }); } private static Collection LinuxSpecificTests() { if (!OsHelper.getOs().equals(OsHelper.OperatingSystem.LINUX)) { return ImmutableSet.of(); } - return Arrays.asList(new Object[][]{ - {FpRoundToIntegralExpr.class, Fp16("2.0"), RoundToIntegral(RNE, Fp16("1.5"))}, - }); + return Arrays.asList( + new Object[][] { + {FpRoundToIntegralExpr.class, Fp16("2.0"), RoundToIntegral(RNE, Fp16("1.5"))}, + }); } private static Collection WindowsSpecificTests() { @@ -213,39 +277,42 @@ private static Collection WindowsSpecificTests() { return ImmutableSet.of(); } //noinspection RedundantArrayCreation - return Arrays.asList(new Object[][]{ - // This is a placeholder for any tests that might be Windows-only - }); + return Arrays.asList( + new Object[][] { + // This is a placeholder for any tests that might be Windows-only + }); } private static Collection NaNOperations() { - return Arrays.asList(new Object[][]{ - {FpAddExpr.class, Fp16NaN(), Add(RNE, List.of(Fp16NaN(), Fp16("3.4")))}, - {FpSubExpr.class, Fp16NaN(), Sub(RNE, Fp16("5.5"), Fp16NaN())}, - {FpPosExpr.class, Fp16NaN(), Pos(Fp16NaN())}, - {FpNegExpr.class, Fp16NaN(), Neg(Fp16NaN())}, - {FpMulExpr.class, Fp16NaN(), Mul(RNE, List.of(Fp16NaN(), Fp16("3.4")))}, - {FpDivExpr.class, Fp16NaN(), Div(RNE, Fp16("7.14"), Fp16NaN())}, - {FpLeqExpr.class, Bool(false), Leq(Fp16("7.14"), Fp16NaN())}, - {FpGeqExpr.class, Bool(false), Geq(Fp16("7.14"), Fp16NaN())}, - {FpGtExpr.class, Bool(false), Gt(Fp16("7.14"), Fp16NaN())}, - {FpLtExpr.class, Bool(false), Lt(Fp16("7.14"), Fp16NaN())}, - {FpLeqExpr.class, Bool(false), Leq(Fp16NaN(), Fp16NaN())}, - {FpGeqExpr.class, Bool(false), Geq(Fp16NaN(), Fp16NaN())}, - {FpGtExpr.class, Bool(false), Gt(Fp16NaN(), Fp16NaN())}, - {FpLtExpr.class, Bool(false), Lt(Fp16NaN(), Fp16NaN())}, - }); + return Arrays.asList( + new Object[][] { + {FpAddExpr.class, Fp16NaN(), Add(RNE, List.of(Fp16NaN(), Fp16("3.4")))}, + {FpSubExpr.class, Fp16NaN(), Sub(RNE, Fp16("5.5"), Fp16NaN())}, + {FpPosExpr.class, Fp16NaN(), Pos(Fp16NaN())}, + {FpNegExpr.class, Fp16NaN(), Neg(Fp16NaN())}, + {FpMulExpr.class, Fp16NaN(), Mul(RNE, List.of(Fp16NaN(), Fp16("3.4")))}, + {FpDivExpr.class, Fp16NaN(), Div(RNE, Fp16("7.14"), Fp16NaN())}, + {FpLeqExpr.class, Bool(false), Leq(Fp16("7.14"), Fp16NaN())}, + {FpGeqExpr.class, Bool(false), Geq(Fp16("7.14"), Fp16NaN())}, + {FpGtExpr.class, Bool(false), Gt(Fp16("7.14"), Fp16NaN())}, + {FpLtExpr.class, Bool(false), Lt(Fp16("7.14"), Fp16NaN())}, + {FpLeqExpr.class, Bool(false), Leq(Fp16NaN(), Fp16NaN())}, + {FpGeqExpr.class, Bool(false), Geq(Fp16NaN(), Fp16NaN())}, + {FpGtExpr.class, Bool(false), Gt(Fp16NaN(), Fp16NaN())}, + {FpLtExpr.class, Bool(false), Lt(Fp16NaN(), Fp16NaN())}, + }); } private static Collection InfinityOperations() { - return Arrays.asList(new Object[][]{ - {FpAddExpr.class, Fp16PInf(), Add(RNA, List.of(Fp16PInf(), Fp16("3.4")))}, - {FpSubExpr.class, Fp16NInf(), Sub(RNA, Fp16("5.5"), Fp16PInf())}, - {FpPosExpr.class, Fp16PInf(), Pos(Fp16PInf())}, - {FpNegExpr.class, Fp16NInf(), Neg(Fp16PInf())}, - {FpMulExpr.class, Fp16PInf(), Mul(RNA, List.of(Fp16PInf(), Fp16("3.4")))}, - {FpDivExpr.class, Fp16("0"), Div(RNA, Fp16("7.14"), Fp16PInf())}, - }); + return Arrays.asList( + new Object[][] { + {FpAddExpr.class, Fp16PInf(), Add(RNA, List.of(Fp16PInf(), Fp16("3.4")))}, + {FpSubExpr.class, Fp16NInf(), Sub(RNA, Fp16("5.5"), Fp16PInf())}, + {FpPosExpr.class, Fp16PInf(), Pos(Fp16PInf())}, + {FpNegExpr.class, Fp16NInf(), Neg(Fp16PInf())}, + {FpMulExpr.class, Fp16PInf(), Mul(RNA, List.of(Fp16PInf(), Fp16("3.4")))}, + {FpDivExpr.class, Fp16("0"), Div(RNA, Fp16("7.14"), Fp16PInf())}, + }); } private static FpLitExpr Fp16(final String lit) { @@ -265,12 +332,12 @@ private static FpLitExpr Fp16NaN() { } private static FpLitExpr Fp16PInf() { - return FpUtils.bigFloatToFpLitExpr(BigFloat.positiveInfinity(BINARY16.precision), - FpType(5, 11)); + return FpUtils.bigFloatToFpLitExpr( + BigFloat.positiveInfinity(BINARY16.precision), FpType(5, 11)); } private static FpLitExpr Fp16NInf() { - return FpUtils.bigFloatToFpLitExpr(BigFloat.negativeInfinity(BINARY16.precision), - FpType(5, 11)); + return FpUtils.bigFloatToFpLitExpr( + BigFloat.negativeInfinity(BINARY16.precision), FpType(5, 11)); } } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FuncTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FuncTestUtils.java index bc0c90b86d..ca2337d1a3 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FuncTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/FuncTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,33 +15,31 @@ */ package hu.bme.mit.theta.core.utils; -import hu.bme.mit.theta.core.type.functype.FuncAppExpr; -import hu.bme.mit.theta.core.type.functype.FuncType; - -import java.util.Arrays; -import java.util.Collection; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import hu.bme.mit.theta.core.type.functype.FuncAppExpr; +import hu.bme.mit.theta.core.type.functype.FuncType; +import java.util.Arrays; +import java.util.Collection; + public class FuncTestUtils { - private FuncTestUtils() { - } + private FuncTestUtils() {} public static Collection BasicOperations() { final var sortFuncType = FuncType.of(Int(), FuncType.of(Int(), Bool())); final var sortFunc = Const("sort", sortFuncType); - return Arrays.asList(new Object[][]{ - - {FuncAppExpr.class, + return Arrays.asList( + new Object[][] { + { + FuncAppExpr.class, App(App(sortFunc.getRef(), Int(0)), Int(1)), - App(App(sortFunc.getRef(), Int(0)), Int(1))}, - - }); + App(App(sortFunc.getRef(), Int(0)), Int(1)) + }, + }); } - } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/IntTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/IntTestUtils.java index a52ce7613a..f2e73e6636 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/IntTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/IntTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,6 @@ */ package hu.bme.mit.theta.core.utils; -import hu.bme.mit.theta.core.type.inttype.IntAddExpr; -import hu.bme.mit.theta.core.type.inttype.IntDivExpr; -import hu.bme.mit.theta.core.type.inttype.IntEqExpr; -import hu.bme.mit.theta.core.type.inttype.IntGeqExpr; -import hu.bme.mit.theta.core.type.inttype.IntGtExpr; -import hu.bme.mit.theta.core.type.inttype.IntLeqExpr; -import hu.bme.mit.theta.core.type.inttype.IntLtExpr; -import hu.bme.mit.theta.core.type.inttype.IntModExpr; -import hu.bme.mit.theta.core.type.inttype.IntMulExpr; -import hu.bme.mit.theta.core.type.inttype.IntNegExpr; -import hu.bme.mit.theta.core.type.inttype.IntNeqExpr; -import hu.bme.mit.theta.core.type.inttype.IntPosExpr; -import hu.bme.mit.theta.core.type.inttype.IntRemExpr; -import hu.bme.mit.theta.core.type.inttype.IntSubExpr; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; @@ -53,50 +34,62 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Rem; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Sub; +import hu.bme.mit.theta.core.type.inttype.IntAddExpr; +import hu.bme.mit.theta.core.type.inttype.IntDivExpr; +import hu.bme.mit.theta.core.type.inttype.IntEqExpr; +import hu.bme.mit.theta.core.type.inttype.IntGeqExpr; +import hu.bme.mit.theta.core.type.inttype.IntGtExpr; +import hu.bme.mit.theta.core.type.inttype.IntLeqExpr; +import hu.bme.mit.theta.core.type.inttype.IntLtExpr; +import hu.bme.mit.theta.core.type.inttype.IntModExpr; +import hu.bme.mit.theta.core.type.inttype.IntMulExpr; +import hu.bme.mit.theta.core.type.inttype.IntNegExpr; +import hu.bme.mit.theta.core.type.inttype.IntNeqExpr; +import hu.bme.mit.theta.core.type.inttype.IntPosExpr; +import hu.bme.mit.theta.core.type.inttype.IntRemExpr; +import hu.bme.mit.theta.core.type.inttype.IntSubExpr; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + public class IntTestUtils { - private IntTestUtils() { - } + private IntTestUtils() {} public static Collection BasicOperations() { final var c1 = Const("x", Int()); - return Arrays.asList(new Object[][]{ - - {IntAddExpr.class, Int(4), Add(List.of(Int(1), Int(3)))}, - {IntSubExpr.class, Int(1), Sub(Int(4), Int(3))}, - {IntMulExpr.class, Int(12), Mul(List.of(Int(4), Int(3)))}, - {IntDivExpr.class, Int(4), Div(Int(12), Int(3))}, - {IntModExpr.class, Int(1), Mod(Int(13), Int(3))}, - {IntRemExpr.class, Int(1), Rem(Int(13), Int(3))}, - - {IntAddExpr.class, Int(4), Add(List.of(Int(-1), Int(5)))}, - {IntSubExpr.class, Int(-2), Sub(Int(4), Int(6))}, - {IntMulExpr.class, Int(-12), Mul(List.of(Int(-4), Int(3)))}, - {IntDivExpr.class, Int(-4), Div(Int(12), Int(-3))}, - {IntModExpr.class, Int(2), Mod(Int(-13), Int(3))}, - {IntRemExpr.class, Int(1), Rem(Int(13), Int(3))}, - {IntRemExpr.class, Int(-1), Rem(Int(13), Int(-3))}, - {IntRemExpr.class, Int(2), Rem(Int(-13), Int(3))}, - {IntRemExpr.class, Int(-2), Rem(Int(-13), Int(-3))}, - {IntNegExpr.class, Int(-13), Neg(Int(13))}, - - - {IntEqExpr.class, False(), Eq(Int(1), Int(3))}, - {IntEqExpr.class, True(), Eq(Int(3), Int(3))}, - {IntNeqExpr.class, True(), Neq(Int(1), Int(3))}, - {IntNeqExpr.class, False(), Neq(Int(3), Int(3))}, - {IntGeqExpr.class, False(), Geq(Int(1), Int(3))}, - {IntGeqExpr.class, True(), Geq(Int(3), Int(3))}, - {IntGtExpr.class, False(), Gt(Int(1), Int(3))}, - {IntGtExpr.class, False(), Gt(Int(3), Int(3))}, - {IntLeqExpr.class, True(), Leq(Int(1), Int(3))}, - {IntLeqExpr.class, True(), Leq(Int(3), Int(3))}, - {IntLtExpr.class, True(), Lt(Int(1), Int(3))}, - {IntLtExpr.class, False(), Lt(Int(3), Int(3))}, - - {IntPosExpr.class, c1.getRef(), Pos(c1.getRef())}, - }); + return Arrays.asList( + new Object[][] { + {IntAddExpr.class, Int(4), Add(List.of(Int(1), Int(3)))}, + {IntSubExpr.class, Int(1), Sub(Int(4), Int(3))}, + {IntMulExpr.class, Int(12), Mul(List.of(Int(4), Int(3)))}, + {IntDivExpr.class, Int(4), Div(Int(12), Int(3))}, + {IntModExpr.class, Int(1), Mod(Int(13), Int(3))}, + {IntRemExpr.class, Int(1), Rem(Int(13), Int(3))}, + {IntAddExpr.class, Int(4), Add(List.of(Int(-1), Int(5)))}, + {IntSubExpr.class, Int(-2), Sub(Int(4), Int(6))}, + {IntMulExpr.class, Int(-12), Mul(List.of(Int(-4), Int(3)))}, + {IntDivExpr.class, Int(-4), Div(Int(12), Int(-3))}, + {IntModExpr.class, Int(2), Mod(Int(-13), Int(3))}, + {IntRemExpr.class, Int(1), Rem(Int(13), Int(3))}, + {IntRemExpr.class, Int(-1), Rem(Int(13), Int(-3))}, + {IntRemExpr.class, Int(2), Rem(Int(-13), Int(3))}, + {IntRemExpr.class, Int(-2), Rem(Int(-13), Int(-3))}, + {IntNegExpr.class, Int(-13), Neg(Int(13))}, + {IntEqExpr.class, False(), Eq(Int(1), Int(3))}, + {IntEqExpr.class, True(), Eq(Int(3), Int(3))}, + {IntNeqExpr.class, True(), Neq(Int(1), Int(3))}, + {IntNeqExpr.class, False(), Neq(Int(3), Int(3))}, + {IntGeqExpr.class, False(), Geq(Int(1), Int(3))}, + {IntGeqExpr.class, True(), Geq(Int(3), Int(3))}, + {IntGtExpr.class, False(), Gt(Int(1), Int(3))}, + {IntGtExpr.class, False(), Gt(Int(3), Int(3))}, + {IntLeqExpr.class, True(), Leq(Int(1), Int(3))}, + {IntLeqExpr.class, True(), Leq(Int(3), Int(3))}, + {IntLtExpr.class, True(), Lt(Int(1), Int(3))}, + {IntLtExpr.class, False(), Lt(Int(3), Int(3))}, + {IntPosExpr.class, c1.getRef(), Pos(c1.getRef())}, + }); } - } diff --git a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/RatTestUtils.java b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/RatTestUtils.java index 88f2fa73e5..44d907f423 100644 --- a/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/RatTestUtils.java +++ b/subprojects/common/core/src/testFixtures/java/hu/bme/mit/theta/core/utils/RatTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,24 +15,6 @@ */ package hu.bme.mit.theta.core.utils; -import hu.bme.mit.theta.core.type.inttype.IntToRatExpr; -import hu.bme.mit.theta.core.type.rattype.RatAddExpr; -import hu.bme.mit.theta.core.type.rattype.RatDivExpr; -import hu.bme.mit.theta.core.type.rattype.RatEqExpr; -import hu.bme.mit.theta.core.type.rattype.RatGeqExpr; -import hu.bme.mit.theta.core.type.rattype.RatGtExpr; -import hu.bme.mit.theta.core.type.rattype.RatLeqExpr; -import hu.bme.mit.theta.core.type.rattype.RatLtExpr; -import hu.bme.mit.theta.core.type.rattype.RatMulExpr; -import hu.bme.mit.theta.core.type.rattype.RatNegExpr; -import hu.bme.mit.theta.core.type.rattype.RatNeqExpr; -import hu.bme.mit.theta.core.type.rattype.RatSubExpr; -import hu.bme.mit.theta.core.type.rattype.RatToIntExpr; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; @@ -51,43 +33,53 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Sub; import static hu.bme.mit.theta.core.type.rattype.RatExprs.ToInt; +import hu.bme.mit.theta.core.type.inttype.IntToRatExpr; +import hu.bme.mit.theta.core.type.rattype.RatAddExpr; +import hu.bme.mit.theta.core.type.rattype.RatDivExpr; +import hu.bme.mit.theta.core.type.rattype.RatEqExpr; +import hu.bme.mit.theta.core.type.rattype.RatGeqExpr; +import hu.bme.mit.theta.core.type.rattype.RatGtExpr; +import hu.bme.mit.theta.core.type.rattype.RatLeqExpr; +import hu.bme.mit.theta.core.type.rattype.RatLtExpr; +import hu.bme.mit.theta.core.type.rattype.RatMulExpr; +import hu.bme.mit.theta.core.type.rattype.RatNegExpr; +import hu.bme.mit.theta.core.type.rattype.RatNeqExpr; +import hu.bme.mit.theta.core.type.rattype.RatSubExpr; +import hu.bme.mit.theta.core.type.rattype.RatToIntExpr; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + public class RatTestUtils { - private RatTestUtils() { - } + private RatTestUtils() {} public static Collection BasicOperations() { - return Arrays.asList(new Object[][]{ - - {RatAddExpr.class, Rat(4, 1), Add(List.of(Rat(1, 1), Rat(3, 1)))}, - {RatSubExpr.class, Rat(1, 1), Sub(Rat(4, 1), Rat(3, 1))}, - {RatMulExpr.class, Rat(12, 1), Mul(List.of(Rat(4, 1), Rat(3, 1)))}, - {RatDivExpr.class, Rat(4, 1), Div(Rat(12, 1), Rat(3, 1))}, - - {RatAddExpr.class, Rat(4, 1), Add(List.of(Rat(-1, 1), Rat(5, 1)))}, - {RatSubExpr.class, Rat(-2, 1), Sub(Rat(4, 1), Rat(6, 1))}, - {RatMulExpr.class, Rat(-12, 1), Mul(List.of(Rat(-4, 1), Rat(3, 1)))}, - {RatDivExpr.class, Rat(-4, 1), Div(Rat(12, 1), Rat(-3, 1))}, - {RatNegExpr.class, Rat(-13, 1), Neg(Rat(13, 1))}, - - - {RatEqExpr.class, False(), Eq(Rat(1, 1), Rat(3, 1))}, - {RatEqExpr.class, True(), Eq(Rat(3, 1), Rat(3, 1))}, - {RatNeqExpr.class, True(), Neq(Rat(1, 1), Rat(3, 1))}, - {RatNeqExpr.class, False(), Neq(Rat(3, 1), Rat(3, 1))}, - {RatGeqExpr.class, False(), Geq(Rat(1, 1), Rat(3, 1))}, - {RatGeqExpr.class, True(), Geq(Rat(3, 1), Rat(3, 1))}, - {RatGtExpr.class, False(), Gt(Rat(1, 1), Rat(3, 1))}, - {RatGtExpr.class, False(), Gt(Rat(3, 1), Rat(3, 1))}, - {RatLeqExpr.class, True(), Leq(Rat(1, 1), Rat(3, 1))}, - {RatLeqExpr.class, True(), Leq(Rat(3, 1), Rat(3, 1))}, - {RatLtExpr.class, True(), Lt(Rat(1, 1), Rat(3, 1))}, - {RatLtExpr.class, False(), Lt(Rat(3, 1), Rat(3, 1))}, - - {RatToIntExpr.class, Int(5), ToInt(Rat(11, 2))}, - {IntToRatExpr.class, Rat(5, 1), ToRat(Int(5))}, - - }); + return Arrays.asList( + new Object[][] { + {RatAddExpr.class, Rat(4, 1), Add(List.of(Rat(1, 1), Rat(3, 1)))}, + {RatSubExpr.class, Rat(1, 1), Sub(Rat(4, 1), Rat(3, 1))}, + {RatMulExpr.class, Rat(12, 1), Mul(List.of(Rat(4, 1), Rat(3, 1)))}, + {RatDivExpr.class, Rat(4, 1), Div(Rat(12, 1), Rat(3, 1))}, + {RatAddExpr.class, Rat(4, 1), Add(List.of(Rat(-1, 1), Rat(5, 1)))}, + {RatSubExpr.class, Rat(-2, 1), Sub(Rat(4, 1), Rat(6, 1))}, + {RatMulExpr.class, Rat(-12, 1), Mul(List.of(Rat(-4, 1), Rat(3, 1)))}, + {RatDivExpr.class, Rat(-4, 1), Div(Rat(12, 1), Rat(-3, 1))}, + {RatNegExpr.class, Rat(-13, 1), Neg(Rat(13, 1))}, + {RatEqExpr.class, False(), Eq(Rat(1, 1), Rat(3, 1))}, + {RatEqExpr.class, True(), Eq(Rat(3, 1), Rat(3, 1))}, + {RatNeqExpr.class, True(), Neq(Rat(1, 1), Rat(3, 1))}, + {RatNeqExpr.class, False(), Neq(Rat(3, 1), Rat(3, 1))}, + {RatGeqExpr.class, False(), Geq(Rat(1, 1), Rat(3, 1))}, + {RatGeqExpr.class, True(), Geq(Rat(3, 1), Rat(3, 1))}, + {RatGtExpr.class, False(), Gt(Rat(1, 1), Rat(3, 1))}, + {RatGtExpr.class, False(), Gt(Rat(3, 1), Rat(3, 1))}, + {RatLeqExpr.class, True(), Leq(Rat(1, 1), Rat(3, 1))}, + {RatLeqExpr.class, True(), Leq(Rat(3, 1), Rat(3, 1))}, + {RatLtExpr.class, True(), Lt(Rat(1, 1), Rat(3, 1))}, + {RatLtExpr.class, False(), Lt(Rat(3, 1), Rat(3, 1))}, + {RatToIntExpr.class, Int(5), ToInt(Rat(11, 2))}, + {IntToRatExpr.class, Rat(5, 1), ToRat(Int(5))}, + }); } - } diff --git a/subprojects/common/grammar/build.gradle.kts b/subprojects/common/grammar/build.gradle.kts index c9dd534d33..9c02d767e9 100644 --- a/subprojects/common/grammar/build.gradle.kts +++ b/subprojects/common/grammar/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/SimpleScope.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/SimpleScope.kt index 6603ba4d5b..1afb6930fd 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/SimpleScope.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/SimpleScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.grammar.dsl import hu.bme.mit.theta.common.dsl.MutableScope @@ -23,27 +22,24 @@ import hu.bme.mit.theta.common.dsl.SymbolTable import java.util.* class SimpleScope( - private val symbolTable: SymbolTable = SymbolTable(), - private val enclosingScope: Scope? = null, + private val symbolTable: SymbolTable = SymbolTable(), + private val enclosingScope: Scope? = null, ) : MutableScope { - override fun enclosingScope(): Optional { - return Optional.ofNullable(enclosingScope) - } + override fun enclosingScope(): Optional { + return Optional.ofNullable(enclosingScope) + } - override fun resolve(name: String?): Optional { - val resolved = symbolTable[name] - return if (resolved.isEmpty) - enclosingScope?.resolve(name) ?: Optional.empty() - else - resolved - } + override fun resolve(name: String?): Optional { + val resolved = symbolTable[name] + return if (resolved.isEmpty) enclosingScope?.resolve(name) ?: Optional.empty() else resolved + } - override fun add(symbol: Symbol) { - symbolTable.add(symbol) - } + override fun add(symbol: Symbol) { + symbolTable.add(symbol) + } - override fun addAll(symbols: MutableIterable?) { - symbolTable.addAll(symbols) - } -} \ No newline at end of file + override fun addAll(symbols: MutableIterable?) { + symbolTable.addAll(symbols) + } +} 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 7b141fbb09..cb5e32c5e5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 d497a3f45d..1f63f99b35 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 00bf2ad1b9..1641978208 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/type/TypeParser.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/type/TypeParser.kt index 454d7993a3..211f65b70f 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/type/TypeParser.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/dsl/type/TypeParser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -34,58 +34,58 @@ import org.antlr.v4.runtime.CommonTokenStream class TypeWrapper(content: String) { - private val context: TypeContext + private val context: TypeContext - init { - val lexer = TypeLexer(CharStreams.fromString(content)) - lexer.addErrorListener(ThrowingErrorListener) - val parser = TypeParser(CommonTokenStream(lexer)) - parser.errorHandler = BailErrorStrategy() - this.context = parser.type() - } + init { + val lexer = TypeLexer(CharStreams.fromString(content)) + lexer.addErrorListener(ThrowingErrorListener) + val parser = TypeParser(CommonTokenStream(lexer)) + parser.errorHandler = BailErrorStrategy() + this.context = parser.type() + } - fun instantiate(): Type { - return TypeCreatorVisitor.INSTANCE.visit(context) - } + fun instantiate(): Type { + return TypeCreatorVisitor.INSTANCE.visit(context) + } - private class TypeCreatorVisitor private constructor() : TypeBaseVisitor() { + private class TypeCreatorVisitor private constructor() : TypeBaseVisitor() { - override fun visitBoolType(ctx: BoolTypeContext): Type { - return BoolExprs.Bool() - } + override fun visitBoolType(ctx: BoolTypeContext): Type { + return BoolExprs.Bool() + } - override fun visitIntType(ctx: IntTypeContext): Type { - return IntExprs.Int() - } + override fun visitIntType(ctx: IntTypeContext): Type { + return IntExprs.Int() + } - override fun visitRatType(ctx: RatTypeContext): Type { - return RatExprs.Rat() - } + override fun visitRatType(ctx: RatTypeContext): Type { + return RatExprs.Rat() + } - override fun visitArrayType(ctx: ArrayTypeContext): Type { - val indexType: Type = ctx.indexType.accept(this) - val elemType: Type = ctx.elemType.accept(this) - return ArrayExprs.Array(indexType, elemType) - } + override fun visitArrayType(ctx: ArrayTypeContext): Type { + val indexType: Type = ctx.indexType.accept(this) + val elemType: Type = ctx.elemType.accept(this) + return ArrayExprs.Array(indexType, elemType) + } - override fun visitBvType(ctx: BvTypeContext): Type { - val size: Int = ctx.size.getText().toInt() - return BvExprs.BvType(size) - } + override fun visitBvType(ctx: BvTypeContext): Type { + val size: Int = ctx.size.getText().toInt() + return BvExprs.BvType(size) + } - override fun visitFpType(ctx: TypeParser.FpTypeContext): Type { - val expSize = ctx.exponent.text.toInt() - val sigSize = ctx.significand.text.toInt() - return FpType.of(expSize, sigSize) - } + override fun visitFpType(ctx: TypeParser.FpTypeContext): Type { + val expSize = ctx.exponent.text.toInt() + val sigSize = ctx.significand.text.toInt() + return FpType.of(expSize, sigSize) + } - override fun visitFuncType(ctx: FuncTypeContext?): Type { - return Func(ctx!!.from.accept(this), ctx.to.accept(this)) - } + override fun visitFuncType(ctx: FuncTypeContext?): Type { + return Func(ctx!!.from.accept(this), ctx.to.accept(this)) + } - companion object { + companion object { - val INSTANCE = TypeCreatorVisitor() - } + val INSTANCE = TypeCreatorVisitor() } -} \ No newline at end of file + } +} 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 be2030d86e..2d4a92c1c1 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 575b3e9ca8..88b90aaeed 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/OptionalAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/OptionalAdapter.kt index 49ca174847..5e02ffec05 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/OptionalAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/OptionalAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.grammar.gson import com.google.gson.Gson @@ -26,38 +25,39 @@ import kotlin.reflect.KClass class OptionalAdapter(val gsonSupplier: () -> Gson) : TypeAdapter>() { - private lateinit var gson: Gson - override fun write(writer: JsonWriter, value: Optional) { - initGson() - writer.beginObject() - if (value.isPresent) { - writer.name("type").value(value.get()::class.qualifiedName) - writer.name("value") - gson.toJson(gson.toJsonTree(value.get()), writer) - } - writer.endObject() + private lateinit var gson: Gson + + override fun write(writer: JsonWriter, value: Optional) { + initGson() + writer.beginObject() + if (value.isPresent) { + writer.name("type").value(value.get()::class.qualifiedName) + writer.name("value") + gson.toJson(gson.toJsonTree(value.get()), writer) } + writer.endObject() + } - override fun read(reader: JsonReader): Optional { - initGson() - reader.beginObject() - var a: A? = null - if (reader.peek() != JsonToken.END_OBJECT) { - lateinit var clazz: KClass<*> - lateinit var value: Any - while (reader.peek() != JsonToken.END_OBJECT) { - when (reader.nextName()) { - "type" -> clazz = Class.forName(reader.nextString()).kotlin - "value" -> value = gson.fromJson(reader, clazz.java) - } - } - a = value as A + override fun read(reader: JsonReader): Optional { + initGson() + reader.beginObject() + var a: A? = null + if (reader.peek() != JsonToken.END_OBJECT) { + lateinit var clazz: KClass<*> + lateinit var value: Any + while (reader.peek() != JsonToken.END_OBJECT) { + when (reader.nextName()) { + "type" -> clazz = Class.forName(reader.nextString()).kotlin + "value" -> value = gson.fromJson(reader, clazz.java) } - reader.endObject() - return Optional.ofNullable(a) + } + a = value as A } + reader.endObject() + return Optional.ofNullable(a) + } - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() - } -} \ No newline at end of file + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/PairAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/PairAdapter.kt index c8442dbe93..0cc2d79bb8 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/PairAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/PairAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.grammar.gson import com.google.gson.Gson @@ -25,60 +24,61 @@ import kotlin.reflect.KClass class PairAdapter(val gsonSupplier: () -> Gson) : TypeAdapter>() { - private lateinit var gson: Gson - override fun write(writer: JsonWriter, value: Pair?) { - initGson() - writer.beginObject() - if (value != null) { - writer.name("first") - writer.beginObject() - writer.name("type").value(value.first::class.java.name) - writer.name("value") - gson.toJson(gson.toJsonTree(value.first), writer) - writer.endObject() + private lateinit var gson: Gson - writer.name("second") - writer.beginObject() - writer.name("type").value(value.second::class.java.name) - writer.name("value") - gson.toJson(gson.toJsonTree(value.second), writer) - writer.endObject() - } + override fun write(writer: JsonWriter, value: Pair?) { + initGson() + writer.beginObject() + if (value != null) { + writer.name("first") + writer.beginObject() + writer.name("type").value(value.first::class.java.name) + writer.name("value") + gson.toJson(gson.toJsonTree(value.first), writer) + writer.endObject() - writer.endObject() + writer.name("second") + writer.beginObject() + writer.name("type").value(value.second::class.java.name) + writer.name("value") + gson.toJson(gson.toJsonTree(value.second), writer) + writer.endObject() } - override fun read(reader: JsonReader): Pair? { - initGson() - reader.beginObject() - lateinit var a: A - lateinit var b: B - var nonNull = false + writer.endObject() + } - while (reader.peek() != JsonToken.END_OBJECT) { - nonNull = true - val nextName = reader.nextName() - reader.beginObject() - lateinit var clazz: KClass<*> - lateinit var value: Any - while (reader.peek() != JsonToken.END_OBJECT) { - when (reader.nextName()) { - "type" -> clazz = Class.forName(reader.nextString()).kotlin - "value" -> value = gson.fromJson(reader, clazz.java) - } - } - reader.endObject() - when (nextName) { - "first" -> a = value as A - "second" -> b = value as B - } - } + override fun read(reader: JsonReader): Pair? { + initGson() + reader.beginObject() + lateinit var a: A + lateinit var b: B + var nonNull = false - reader.endObject() - return if (nonNull) Pair(a, b) else null + while (reader.peek() != JsonToken.END_OBJECT) { + nonNull = true + val nextName = reader.nextName() + reader.beginObject() + lateinit var clazz: KClass<*> + lateinit var value: Any + while (reader.peek() != JsonToken.END_OBJECT) { + when (reader.nextName()) { + "type" -> clazz = Class.forName(reader.nextString()).kotlin + "value" -> value = gson.fromJson(reader, clazz.java) + } + } + reader.endObject() + when (nextName) { + "first" -> a = value as A + "second" -> b = value as B + } } - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() - } -} \ No newline at end of file + reader.endObject() + return if (nonNull) Pair(a, b) else null + } + + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} 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 0cd6eb5b2f..f5109848c7 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 bef973890b..91ebc76a96 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StringTypeAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StringTypeAdapter.kt index d5396d2925..6aae64e5b8 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StringTypeAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/StringTypeAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.grammar.gson import com.google.gson.TypeAdapter @@ -23,18 +22,16 @@ import com.google.gson.stream.JsonWriter class StringTypeAdapter(val fromString: (String) -> T) : TypeAdapter() { - override fun write(writer: JsonWriter, value: T?) { - if (value != null) writer.value(value.toString()) - else writer.nullValue() - } + override fun write(writer: JsonWriter, value: T?) { + if (value != null) writer.value(value.toString()) else writer.nullValue() + } - override fun read(reader: JsonReader): T? { - if (reader.peek() == JsonToken.NULL) { - return null - } else { - check(reader.peek() == JsonToken.STRING) - return fromString(reader.nextString()) - } + override fun read(reader: JsonReader): T? { + if (reader.peek() == JsonToken.NULL) { + return null + } else { + check(reader.peek() == JsonToken.STRING) + return fromString(reader.nextString()) } - -} \ No newline at end of file + } +} 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 ec99225711..4105002a76 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TripleAdapter.kt b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TripleAdapter.kt index 1ee752082d..7a7223e467 100644 --- a/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TripleAdapter.kt +++ b/subprojects/common/grammar/src/main/java/hu/bme/mit/theta/grammar/gson/TripleAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.grammar.gson import com.google.gson.Gson @@ -24,68 +23,69 @@ import com.google.gson.stream.JsonWriter import kotlin.reflect.KClass class TripleAdapter(val gsonSupplier: () -> Gson) : - TypeAdapter>() { + TypeAdapter>() { - private lateinit var gson: Gson - override fun write(writer: JsonWriter, value: Triple) { - initGson() - writer.beginObject() + private lateinit var gson: Gson - writer.name("first") - writer.beginObject() - writer.name("type").value(value.first::class.java.name) - writer.name("value") - gson.toJson(gson.toJsonTree(value.first), writer) - writer.endObject() + override fun write(writer: JsonWriter, value: Triple) { + initGson() + writer.beginObject() - writer.name("second") - writer.beginObject() - writer.name("type").value(value.second::class.java.name) - writer.name("value") - gson.toJson(gson.toJsonTree(value.second), writer) - writer.endObject() + writer.name("first") + writer.beginObject() + writer.name("type").value(value.first::class.java.name) + writer.name("value") + gson.toJson(gson.toJsonTree(value.first), writer) + writer.endObject() - writer.name("third") - writer.beginObject() - writer.name("type").value(value.third::class.java.name) - writer.name("value") - gson.toJson(gson.toJsonTree(value.third), writer) - writer.endObject() + writer.name("second") + writer.beginObject() + writer.name("type").value(value.second::class.java.name) + writer.name("value") + gson.toJson(gson.toJsonTree(value.second), writer) + writer.endObject() - writer.endObject() - } + writer.name("third") + writer.beginObject() + writer.name("type").value(value.third::class.java.name) + writer.name("value") + gson.toJson(gson.toJsonTree(value.third), writer) + writer.endObject() - override fun read(reader: JsonReader): Triple { - initGson() - reader.beginObject() - lateinit var a: A - lateinit var b: B - lateinit var c: C + writer.endObject() + } - while (reader.peek() != JsonToken.END_OBJECT) { - val nextName = reader.nextName() - reader.beginObject() - lateinit var clazz: KClass<*> - lateinit var value: Any - while (reader.peek() != JsonToken.END_OBJECT) { - when (reader.nextName()) { - "type" -> clazz = Class.forName(reader.nextString()).kotlin - "value" -> value = gson.fromJson(reader, clazz.java) - } - } - reader.endObject() - when (nextName) { - "first" -> a = value as A - "second" -> b = value as B - "third" -> c = value as C - } - } + override fun read(reader: JsonReader): Triple { + initGson() + reader.beginObject() + lateinit var a: A + lateinit var b: B + lateinit var c: C - reader.endObject() - return Triple(a, b, c) + while (reader.peek() != JsonToken.END_OBJECT) { + val nextName = reader.nextName() + reader.beginObject() + lateinit var clazz: KClass<*> + lateinit var value: Any + while (reader.peek() != JsonToken.END_OBJECT) { + when (reader.nextName()) { + "type" -> clazz = Class.forName(reader.nextString()).kotlin + "value" -> value = gson.fromJson(reader, clazz.java) + } + } + reader.endObject() + when (nextName) { + "first" -> a = value as A + "second" -> b = value as B + "third" -> c = value as C + } } - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() - } -} \ No newline at end of file + reader.endObject() + return Triple(a, b, c) + } + + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} 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 6789015a9a..b3c514d5ea 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 a93ef5340c..9dca4e8338 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 72b7181a69..2d3b5fdc23 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 9232a2b034..8c27359f61 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 be9268ba6c..8a8b8f6dbd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl-cli/build.gradle.kts b/subprojects/common/ltl-cli/build.gradle.kts index 227805593a..c739d78afd 100644 --- a/subprojects/common/ltl-cli/build.gradle.kts +++ b/subprojects/common/ltl-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl-cli/src/main/kotlin/common/ltl/cli/LtlCliOptions.kt b/subprojects/common/ltl-cli/src/main/kotlin/common/ltl/cli/LtlCliOptions.kt index 7e1b905ca5..7595a907ed 100644 --- a/subprojects/common/ltl-cli/src/main/kotlin/common/ltl/cli/LtlCliOptions.kt +++ b/subprojects/common/ltl-cli/src/main/kotlin/common/ltl/cli/LtlCliOptions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,7 @@ import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.required import com.github.ajalt.clikt.parameters.types.enum -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy open class LtlCliOptions : @@ -35,8 +35,8 @@ open class LtlCliOptions : .required() val searchStrategy by option(help = "Which strategy to use for search") - .enum() - .default(LoopcheckerSearchStrategy.GDFS) + .enum() + .default(LoopCheckerSearchStrategy.GDFS) val refinerStrategy by option(help = "Which strategy to use for search") .enum() diff --git a/subprojects/common/ltl/build.gradle.kts b/subprojects/common/ltl/build.gradle.kts index 6624b9f823..0af7af8da7 100644 --- a/subprojects/common/ltl/build.gradle.kts +++ b/subprojects/common/ltl/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/Ltl2BuchiTransformer.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/Ltl2BuchiTransformer.kt index 5422c540f7..449378f106 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/Ltl2BuchiTransformer.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/Ltl2BuchiTransformer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/APGeneratorVisitor.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/APGeneratorVisitor.kt index 9668c2f3fa..bf6f705c92 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/APGeneratorVisitor.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/APGeneratorVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/BuchiBuilder.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/BuchiBuilder.kt index 3820cc1876..ce3ec03e01 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/BuchiBuilder.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/BuchiBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -165,7 +165,7 @@ internal constructor( val to = getOrCreateLocation(list[0]) val edge = builder.createEdge(from, to, Stmts.Assume(apBoolExpressionToInternal(booleanExpression))) - if (list1 != null && !list1.isEmpty()) builder.setAcceptingEdge(edge) + if (list1 != null && !list1.isEmpty()) builder.addAcceptingEdge(edge) } override fun notifyEndOfState(i: Int) { diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ExternalLtl2Hoaf.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ExternalLtl2Hoaf.kt index 4b4ab5b9ae..1b3fcc0540 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ExternalLtl2Hoaf.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ExternalLtl2Hoaf.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/LTLExprVisitor.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/LTLExprVisitor.kt index 6d4b8b42e0..1e33206f31 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/LTLExprVisitor.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/LTLExprVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2BuchiThroughHoaf.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2BuchiThroughHoaf.kt index 6244119cf5..349700fd13 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2BuchiThroughHoaf.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2BuchiThroughHoaf.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2Hoaf.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2Hoaf.kt index e0da409ba3..d571c69198 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2Hoaf.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2Hoaf.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2HoafFromDir.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2HoafFromDir.kt index cd27f0c9c5..bccd791a0d 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2HoafFromDir.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/Ltl2HoafFromDir.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ToStringVisitor.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ToStringVisitor.kt index a97a05486a..decda0af06 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ToStringVisitor.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/cfa/buchi/hoa/ToStringVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/ltl/LtlChecker.kt b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/ltl/LtlChecker.kt index bfe0c7cf79..0fd58f9e6f 100644 --- a/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/ltl/LtlChecker.kt +++ b/subprojects/common/ltl/src/main/kotlin/hu/bme/mit/theta/common/ltl/LtlChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,7 +25,7 @@ import hu.bme.mit.theta.analysis.algorithm.asg.ASGTrace import hu.bme.mit.theta.analysis.algorithm.cegar.CegarChecker import hu.bme.mit.theta.analysis.algorithm.loopchecker.AcceptancePredicate import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.ASGAbstractor -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.SingleASGTraceRefiner import hu.bme.mit.theta.analysis.expr.ExprState @@ -75,7 +75,7 @@ class LtlChecker< ltl: String, solverFactory: SolverFactory, logger: Logger, - searchStrategy: LoopcheckerSearchStrategy, + searchStrategy: LoopCheckerSearchStrategy, refinerStrategy: ASGTraceCheckerStrategy, ltl2BuchiTransformer: Ltl2BuchiTransformer, variables: Collection>, diff --git a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaExpl.kt b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaExpl.kt index aaad70321e..a86e7c5868 100644 --- a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaExpl.kt +++ b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaExpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,7 +15,7 @@ */ package hu.bme.mit.theta.common.ltl -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy import hu.bme.mit.theta.analysis.expl.ExplAnalysis import hu.bme.mit.theta.analysis.expl.ExplPrec @@ -98,7 +98,7 @@ class LtlCheckTestWithCfaExpl( ltlExpr, itpSolverFactory, logger, - LoopcheckerSearchStrategy.GDFS, + LoopCheckerSearchStrategy.GDFS, ASGTraceCheckerStrategy.DIRECT_REFINEMENT, Ltl2BuchiThroughHoaf(Ltl2HoafFromDir("src/test/resources/hoa"), logger), variables, diff --git a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaPred.kt b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaPred.kt index 8f6b578f36..5a7a40d671 100644 --- a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaPred.kt +++ b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithCfaPred.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,7 +15,7 @@ */ package hu.bme.mit.theta.common.ltl -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy import hu.bme.mit.theta.analysis.expr.ExprAction import hu.bme.mit.theta.analysis.multi.NextSideFunctions @@ -43,7 +43,7 @@ class LtlCheckTestWithCfaPred( private val cfaName: String, private val ltlExpr: String, private val result: Boolean, - private val searchStrategy: LoopcheckerSearchStrategy, + private val searchStrategy: LoopCheckerSearchStrategy, private val refinerStrategy: ASGTraceCheckerStrategy, ) { @@ -76,11 +76,9 @@ class LtlCheckTestWithCfaPred( @JvmStatic @Parameterized.Parameters(name = "{3}-{4}: {0}") fun params() = - listOf(LoopcheckerSearchStrategy.GDFS, LoopcheckerSearchStrategy.NDFS).flatMap { search -> - listOf(ASGTraceCheckerStrategy.DIRECT_REFINEMENT, ASGTraceCheckerStrategy.BOUNDED_UNROLLING).flatMap { - ref -> - data().map { arrayOf(*it, search, ref) } - } + listOf(LoopCheckerSearchStrategy.GDFS, LoopCheckerSearchStrategy.NDFS).flatMap { search -> + listOf(ASGTraceCheckerStrategy.DIRECT_REFINEMENT, ASGTraceCheckerStrategy.BOUNDED_UNROLLING) + .flatMap { ref -> data().map { arrayOf(*it, search, ref) } } } } diff --git a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsExpl.kt b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsExpl.kt index cefae2a949..e4508c94e5 100644 --- a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsExpl.kt +++ b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsExpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,7 +15,7 @@ */ package hu.bme.mit.theta.common.ltl -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy import hu.bme.mit.theta.analysis.expl.ExplPrec import hu.bme.mit.theta.analysis.expl.ExplState @@ -103,7 +103,7 @@ class LtlCheckTestWithXstsExpl( ltlExpr, solverFactory, logger, - LoopcheckerSearchStrategy.GDFS, + LoopCheckerSearchStrategy.GDFS, ASGTraceCheckerStrategy.DIRECT_REFINEMENT, Ltl2BuchiThroughHoaf(Ltl2HoafFromDir("src/test/resources/hoa"), logger), xsts.vars, diff --git a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsPred.kt b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsPred.kt index dcc83fa154..01d32c5bfb 100644 --- a/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsPred.kt +++ b/subprojects/common/ltl/src/test/kotlin/hu/bme/mit/theta/common/ltl/LtlCheckTestWithXstsPred.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,7 +15,7 @@ */ package hu.bme.mit.theta.common.ltl -import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopcheckerSearchStrategy +import hu.bme.mit.theta.analysis.algorithm.loopchecker.abstraction.LoopCheckerSearchStrategy import hu.bme.mit.theta.analysis.algorithm.loopchecker.refinement.ASGTraceCheckerStrategy import hu.bme.mit.theta.analysis.pred.ExprSplitters import hu.bme.mit.theta.analysis.pred.ItpRefToPredPrec @@ -41,7 +41,7 @@ class LtlCheckTestWithXstsPred( private val xstsName: String, private val ltlExpr: String, private val result: Boolean, - private val searchStrategy: LoopcheckerSearchStrategy, + private val searchStrategy: LoopCheckerSearchStrategy, private val refinerStrategy: ASGTraceCheckerStrategy, ) { @@ -108,7 +108,7 @@ class LtlCheckTestWithXstsPred( @JvmStatic @Parameterized.Parameters(name = "{3}-{4}: {0}") fun params() = - listOf(LoopcheckerSearchStrategy.GDFS, LoopcheckerSearchStrategy.NDFS).flatMap { search -> + listOf(LoopCheckerSearchStrategy.GDFS, LoopCheckerSearchStrategy.NDFS).flatMap { search -> ASGTraceCheckerStrategy.entries.flatMap { ref -> data().map { arrayOf(*it, search, ref) } } } } diff --git a/subprojects/common/multi-tests/build.gradle.kts b/subprojects/common/multi-tests/build.gradle.kts index 0eb6b08b2b..c948b50fde 100644 --- a/subprojects/common/multi-tests/build.gradle.kts +++ b/subprojects/common/multi-tests/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternating3Test.kt b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternating3Test.kt index 68e6ed2688..ecd97d29ab 100644 --- a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternating3Test.kt +++ b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternating3Test.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package multi import hu.bme.mit.theta.analysis.expl.ExplPrec @@ -33,64 +32,71 @@ import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory import hu.bme.mit.theta.xsts.XSTS import hu.bme.mit.theta.xsts.analysis.config.XstsConfigBuilder import hu.bme.mit.theta.xsts.dsl.XstsDslManager -import org.junit.Test -import org.junit.jupiter.api.Assertions.assertTrue import java.io.FileInputStream import java.io.IOException import java.io.SequenceInputStream +import org.junit.Test +import org.junit.jupiter.api.Assertions.assertTrue class MultiAlternating3Test { - val logger: Logger = ConsoleLogger(Logger.Level.SUBSTEP) - val solver: Solver = Z3LegacySolverFactory.getInstance().createSolver() + val logger: Logger = ConsoleLogger(Logger.Level.SUBSTEP) + val solver: Solver = Z3LegacySolverFactory.getInstance().createSolver() - @Test - fun test() { - var xsts: XSTS - try { - SequenceInputStream( - FileInputStream("src/test/resources/xsts/incr_double.xsts"), - FileInputStream("src/test/resources/xsts/xneq32.prop") - ).use { inputStream -> - xsts = XstsDslManager.createXsts(inputStream) - } - } catch (e: IOException) { - throw RuntimeException(e) - } - val variables = xsts.vars - - val xstsConfigBuilder = XstsConfigBuilder( - XstsConfigBuilder.Domain.EXPL, - XstsConfigBuilder.Refinement.SEQ_ITP, - Z3LegacySolverFactory.getInstance(), - Z3LegacySolverFactory.getInstance() + @Test + fun test() { + var xsts: XSTS + try { + SequenceInputStream( + FileInputStream("src/test/resources/xsts/incr_double.xsts"), + FileInputStream("src/test/resources/xsts/xneq32.prop"), ) - val xstsExplBuilder1 = xstsConfigBuilder.ExplStrategy(xsts) - val xstsExplBuilder2 = xstsConfigBuilder.ExplStrategy(xsts) - val xstsExplBuilder3 = xstsConfigBuilder.ExplStrategy(xsts) + .use { inputStream -> xsts = XstsDslManager.createXsts(inputStream) } + } catch (e: IOException) { + throw RuntimeException(e) + } + val variables = xsts.vars - val dataAnalysis = xstsExplBuilder1.dataAnalysis - val dataInitPrec = ExplPrec.of(variables) + val xstsConfigBuilder = + XstsConfigBuilder( + XstsConfigBuilder.Domain.EXPL, + XstsConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance(), + Z3LegacySolverFactory.getInstance(), + ) + val xstsExplBuilder1 = xstsConfigBuilder.ExplStrategy(xsts) + val xstsExplBuilder2 = xstsConfigBuilder.ExplStrategy(xsts) + val xstsExplBuilder3 = xstsConfigBuilder.ExplStrategy(xsts) - val doubleProduct = StmtMultiBuilder(xstsExplBuilder1.multiSide, xstsExplBuilder1.lts) - .addRightSide(xstsExplBuilder2.multiSide, xstsExplBuilder2.lts) - .build(NextSideFunctions.Alternating(), dataAnalysis.initFunc) - val tripeProduct = StmtMultiBuilder(xstsExplBuilder3.multiSide, xstsExplBuilder3.lts) - .addRightSide(doubleProduct.side, doubleProduct.lts) - .build(NextSideFunctions.Alternating3(), dataAnalysis.initFunc) - val prop = Not(xsts.prop) - val dataPredicate = ExplStatePredicate(prop, solver) - val multiConfigBuilder = StmtMultiConfigBuilder.ItpStmtMultiConfigBuilder( - tripeProduct, prop, - MultiStatePredicate(dataPredicate), - ItpRefToExplPrec(), RefToMultiPrec(ItpRefToExplPrec(), ItpRefToExplPrec(), ItpRefToExplPrec()), - ItpRefToExplPrec(), dataInitPrec, - MultiPrec(dataInitPrec, dataInitPrec, dataInitPrec), dataInitPrec, Z3LegacySolverFactory.getInstance(), - logger - ) - val result = multiConfigBuilder.build().check() + val dataAnalysis = xstsExplBuilder1.dataAnalysis + val dataInitPrec = ExplPrec.of(variables) - assertTrue(result.isUnsafe) + val doubleProduct = + StmtMultiBuilder(xstsExplBuilder1.multiSide, xstsExplBuilder1.lts) + .addRightSide(xstsExplBuilder2.multiSide, xstsExplBuilder2.lts) + .build(NextSideFunctions.Alternating(), dataAnalysis.initFunc) + val tripeProduct = + StmtMultiBuilder(xstsExplBuilder3.multiSide, xstsExplBuilder3.lts) + .addRightSide(doubleProduct.side, doubleProduct.lts) + .build(NextSideFunctions.Alternating3(), dataAnalysis.initFunc) + val prop = Not(xsts.prop) + val dataPredicate = ExplStatePredicate(prop, solver) + val multiConfigBuilder = + StmtMultiConfigBuilder.ItpStmtMultiConfigBuilder( + tripeProduct, + prop, + MultiStatePredicate(dataPredicate), + ItpRefToExplPrec(), + RefToMultiPrec(ItpRefToExplPrec(), ItpRefToExplPrec(), ItpRefToExplPrec()), + ItpRefToExplPrec(), + dataInitPrec, + MultiPrec(dataInitPrec, dataInitPrec, dataInitPrec), + dataInitPrec, + Z3LegacySolverFactory.getInstance(), + logger, + ) + val result = multiConfigBuilder.build().check() - } -} \ No newline at end of file + assertTrue(result.isUnsafe) + } +} diff --git a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternatingTest.kt b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternatingTest.kt index 1408a365aa..604d53dcef 100644 --- a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternatingTest.kt +++ b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiAlternatingTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 6bfde67da4..a3b44a187f 100644 --- a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiNondetDiningPhilosophersTest.kt +++ b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiNondetDiningPhilosophersTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiSelfProductTest.kt b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiSelfProductTest.kt index 5355c57c31..06427ceabb 100644 --- a/subprojects/common/multi-tests/src/test/kotlin/multi/MultiSelfProductTest.kt +++ b/subprojects/common/multi-tests/src/test/kotlin/multi/MultiSelfProductTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package multi import hu.bme.mit.theta.analysis.expl.ExplPrec @@ -31,58 +30,66 @@ import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory import hu.bme.mit.theta.xsts.XSTS import hu.bme.mit.theta.xsts.analysis.config.XstsConfigBuilder import hu.bme.mit.theta.xsts.dsl.XstsDslManager -import org.junit.Test -import org.junit.jupiter.api.Assertions.assertTrue import java.io.FileInputStream import java.io.IOException import java.io.SequenceInputStream +import org.junit.Test +import org.junit.jupiter.api.Assertions.assertTrue class MultiSelfProductTest { - val logger: Logger = ConsoleLogger(Logger.Level.SUBSTEP) - val solver: Solver = Z3LegacySolverFactory.getInstance().createSolver() + val logger: Logger = ConsoleLogger(Logger.Level.SUBSTEP) + val solver: Solver = Z3LegacySolverFactory.getInstance().createSolver() - @Test - fun test() { - var xsts: XSTS - try { - SequenceInputStream( - FileInputStream("src/test/resources/xsts/incr_double.xsts"), - FileInputStream("src/test/resources/xsts/xneq12.prop") - ).use { inputStream -> - xsts = XstsDslManager.createXsts(inputStream) - } - } catch (e: IOException) { - throw RuntimeException(e) - } - val variables = xsts.vars - - val xstsConfigBuilder = XstsConfigBuilder( - XstsConfigBuilder.Domain.EXPL, - XstsConfigBuilder.Refinement.SEQ_ITP, - Z3LegacySolverFactory.getInstance(), - Z3LegacySolverFactory.getInstance() + @Test + fun test() { + var xsts: XSTS + try { + SequenceInputStream( + FileInputStream("src/test/resources/xsts/incr_double.xsts"), + FileInputStream("src/test/resources/xsts/xneq12.prop"), ) - val xstsExplBuilder1 = xstsConfigBuilder.ExplStrategy(xsts) - val xstsExplBuilder2 = xstsConfigBuilder.ExplStrategy(xsts) + .use { inputStream -> xsts = XstsDslManager.createXsts(inputStream) } + } catch (e: IOException) { + throw RuntimeException(e) + } + val variables = xsts.vars - val dataAnalysis = xstsExplBuilder1.dataAnalysis - val dataInitPrec = ExplPrec.of(variables) + val xstsConfigBuilder = + XstsConfigBuilder( + XstsConfigBuilder.Domain.EXPL, + XstsConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance(), + Z3LegacySolverFactory.getInstance(), + ) + val xstsExplBuilder1 = xstsConfigBuilder.ExplStrategy(xsts) + val xstsExplBuilder2 = xstsConfigBuilder.ExplStrategy(xsts) - val product = StmtMultiBuilder(xstsExplBuilder1.multiSide, xstsExplBuilder1.lts) - .addRightSide(xstsExplBuilder2.multiSide, xstsExplBuilder2.lts) - .build(NextSideFunctions.Alternating(), dataAnalysis.initFunc) - val prop = Not(xsts.prop) - val dataPredicate = ExplStatePredicate(prop, solver) - val multiConfigBuilder = StmtMultiConfigBuilder.ItpStmtMultiConfigBuilder( - product, prop, - MultiStatePredicate(dataPredicate), - ItpRefToExplPrec(), ItpRefToExplPrec(), ItpRefToExplPrec(), dataInitPrec, - dataInitPrec, dataInitPrec, Z3LegacySolverFactory.getInstance(), logger - ) - val result = multiConfigBuilder.build().check() + val dataAnalysis = xstsExplBuilder1.dataAnalysis + val dataInitPrec = ExplPrec.of(variables) - assertTrue(result.isUnsafe) + val product = + StmtMultiBuilder(xstsExplBuilder1.multiSide, xstsExplBuilder1.lts) + .addRightSide(xstsExplBuilder2.multiSide, xstsExplBuilder2.lts) + .build(NextSideFunctions.Alternating(), dataAnalysis.initFunc) + val prop = Not(xsts.prop) + val dataPredicate = ExplStatePredicate(prop, solver) + val multiConfigBuilder = + StmtMultiConfigBuilder.ItpStmtMultiConfigBuilder( + product, + prop, + MultiStatePredicate(dataPredicate), + ItpRefToExplPrec(), + ItpRefToExplPrec(), + ItpRefToExplPrec(), + dataInitPrec, + dataInitPrec, + dataInitPrec, + Z3LegacySolverFactory.getInstance(), + logger, + ) + val result = multiConfigBuilder.build().check() - } -} \ No newline at end of file + assertTrue(result.isUnsafe) + } +} diff --git a/subprojects/frontends/c-frontend/build.gradle.kts b/subprojects/frontends/c-frontend/build.gradle.kts index 13604673bb..1f8376de5f 100644 --- a/subprojects/frontends/c-frontend/build.gradle.kts +++ b/subprojects/frontends/c-frontend/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,4 +21,4 @@ dependencies { implementation(project(":theta-core")) implementation(project(":theta-common")) implementation(project(":theta-grammar")) -} \ No newline at end of file +} 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 563878ffc2..c854d70a1c 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/FrontendMetadata.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/FrontendMetadata.java index 4f02529971..7720599792 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/FrontendMetadata.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/FrontendMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; -import org.jetbrains.annotations.NotNull; - import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; - -import static com.google.common.base.Preconditions.checkNotNull; +import org.jetbrains.annotations.NotNull; public class FrontendMetadata { private final Map> lookupKeyValue; @@ -47,22 +45,28 @@ public FrontendMetadata(@NotNull Map> lookupKeyValu public Optional getMetadataValue(X owner, String key) { if (owner instanceof Expr && key.equals("cType")) { - Tuple2, Integer> pair = Tuple2.of((Expr) owner, System.identityHashCode(owner)); + Tuple2, Integer> pair = + Tuple2.of((Expr) owner, System.identityHashCode(owner)); return Optional.ofNullable(types.get(pair)); } - return Optional.ofNullable(lookupKeyValue.getOrDefault(getHashCode(owner), Map.of()).get(key)); + return Optional.ofNullable( + lookupKeyValue.getOrDefault(getHashCode(owner), Map.of()).get(key)); } public void create(X owner, String key, T value) { checkNotNull(value); if (owner instanceof Expr && key.equals("cType") && value instanceof CComplexType) { - Tuple2, Integer> pair = Tuple2.of((Expr) owner, System.identityHashCode(owner)); -// if (types.containsKey(pair) && types.get(pair).getClass() != value.getClass()) { -// throw new RuntimeException("Expression (" + owner + ") already has a different type: " + types.get(pair) + ". New type: " + value); -// } + Tuple2, Integer> pair = + Tuple2.of((Expr) owner, System.identityHashCode(owner)); + // if (types.containsKey(pair) && types.get(pair).getClass() != + // value.getClass()) { + // throw new RuntimeException("Expression (" + owner + ") already has a + // different type: " + types.get(pair) + ". New type: " + value); + // } types.put(pair, (CComplexType) value); } else { - Map keyvalues = lookupKeyValue.getOrDefault(getHashCode(owner), new LinkedHashMap<>()); + Map keyvalues = + lookupKeyValue.getOrDefault(getHashCode(owner), new LinkedHashMap<>()); keyvalues.put(key, value); lookupKeyValue.put(getHashCode(owner), keyvalues); } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/ParseContext.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/ParseContext.java index 982e84b417..f959171998 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/ParseContext.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/ParseContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend; import hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.ArchitectureType; import hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.ArithmeticType; import hu.bme.mit.theta.frontend.transformation.CStmtCounter; import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.ArithmeticTrait; - import java.util.LinkedHashSet; import java.util.Set; @@ -43,8 +41,7 @@ public ParseContext( final Set arithmeticTraits, final ArchitectureType architecture, final Boolean multiThreading, - final ArithmeticType arithmetic - ) { + final ArithmeticType arithmetic) { this.metadata = metadata; this.cStmtCounter = cStmtCounter; this.arithmeticTraits = arithmeticTraits; 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 index e3bef460e0..387ee8a1ae 100644 --- 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * 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 { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/ArchitectureConfig.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/ArchitectureConfig.java index 51c5c38f15..0823b8261e 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/ArchitectureConfig.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/ArchitectureConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation; import hu.bme.mit.theta.core.stmt.AssumeStmt; @@ -28,13 +27,11 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector.TypeVisitor; import hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector.UnitValueVisitor; import hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector.ValueVisitor; - import java.util.LinkedHashMap; import java.util.Map; public class ArchitectureConfig { - private ArchitectureConfig() { - } + private ArchitectureConfig() {} /** * ILP32 and LP64 Architecture, see here: https://unix.org/whitepapers/64bit.html Warning note: @@ -47,10 +44,21 @@ public enum ArchitectureType { public final Map standardTypeSizes = new LinkedHashMap<>(); - ArchitectureType(int _bool, int _char, int _short, int _int, int _long, int _longlong, int __int128, - int _float_significand, int _float_exponent, int _double_significand, - int _double_exponent, - int _longdouble_significand, int _longdouble_exponend, int _fitsall) { + ArchitectureType( + int _bool, + int _char, + int _short, + int _int, + int _long, + int _longlong, + int __int128, + int _float_significand, + int _float_exponent, + int _double_significand, + int _double_exponent, + int _longdouble_significand, + int _longdouble_exponend, + int _fitsall) { standardTypeSizes.put("void", 1); standardTypeSizes.put("bool", _bool); standardTypeSizes.put("char", _char); @@ -74,11 +82,11 @@ public int getBitWidth(String typeName) { } /** - * Which parseContext.getArithmetic() type to use: - integer: bitvectors are not supported (e.g. floats, bitwise - * ops). This is the most performant. - bitvector: every operation is handled through BV - * primitives. This can handle virtually anything (in scope). This is not as performant as - * integer parseContext.getArithmetic(). - efficient: Integer when possible, bitvector when necessary - this is - * the default (and performance-wise best) option + * Which parseContext.getArithmetic() type to use: - integer: bitvectors are not supported (e.g. + * floats, bitwise ops). This is the most performant. - bitvector: every operation is handled + * through BV primitives. This can handle virtually anything (in scope). This is not as + * performant as integer parseContext.getArithmetic(). - efficient: Integer when possible, + * bitvector when necessary - this is the default (and performance-wise best) option */ public enum ArithmeticType { integer, @@ -86,51 +94,63 @@ public enum ArithmeticType { efficient } - public static CComplexType.CComplexTypeVisitor, Expr> getCastVisitor(ParseContext parseContext) { + public static CComplexType.CComplexTypeVisitor, Expr> getCastVisitor( + ParseContext parseContext) { if (parseContext.getArithmetic() == ArithmeticType.bitvector) { return new CastVisitor(parseContext); } else { - return new hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer.CastVisitor(parseContext); + return new hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer + .CastVisitor(parseContext); } } - public static CComplexType.CComplexTypeVisitor, AssumeStmt> getLimitVisitor(ParseContext parseContext) { + public static CComplexType.CComplexTypeVisitor, AssumeStmt> getLimitVisitor( + ParseContext parseContext) { if (parseContext.getArithmetic() == ArithmeticType.bitvector) { return LimitVisitor.instance; } else { - return new hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer.LimitVisitor(parseContext); + return new hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer + .LimitVisitor(parseContext); } } - public static CComplexType.CComplexTypeVisitor> getNullValueVisitor(ParseContext parseContext) { + public static CComplexType.CComplexTypeVisitor> getNullValueVisitor( + ParseContext parseContext) { if (parseContext.getArithmetic() == ArithmeticType.bitvector) { return new NullValueVisitor(parseContext); } else { - return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer.NullValueVisitor.instance; + return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer + .NullValueVisitor.instance; } } - public static CComplexType.CComplexTypeVisitor> getUnitValueVisitor(ParseContext parseContext) { + public static CComplexType.CComplexTypeVisitor> getUnitValueVisitor( + ParseContext parseContext) { if (parseContext.getArithmetic() == ArithmeticType.bitvector) { return new UnitValueVisitor(parseContext); } else { - return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer.UnitValueVisitor.instance; + return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer + .UnitValueVisitor.instance; } } - public static CComplexType.CComplexTypeVisitor getTypeVisitor(ParseContext parseContext) { + public static CComplexType.CComplexTypeVisitor getTypeVisitor( + ParseContext parseContext) { if (parseContext.getArithmetic() == ArithmeticType.bitvector) { return new TypeVisitor(parseContext); } else { - return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer.TypeVisitor.instance; + return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer + .TypeVisitor.instance; } } - public static CComplexType.CComplexTypeVisitor> getValueVisitor(ParseContext parseContext) { + public static CComplexType.CComplexTypeVisitor> getValueVisitor( + ParseContext parseContext) { if (parseContext.getArithmetic() == ArithmeticType.bitvector) { return new ValueVisitor(parseContext); } else { - return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer.ValueVisitor.instance; + return hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer + .ValueVisitor.instance; } } } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/CStmtCounter.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/CStmtCounter.java index 78fb59618f..0552ad4899 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/CStmtCounter.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/CStmtCounter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation; public class CStmtCounter { 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 79b5e3ee7b..08c48a1edb 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 b11b230c07..b623c4f9d4 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.expression; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.model.Valuation; 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; - public class UnsupportedInitializer extends NullaryExpr { @Override @@ -33,7 +32,8 @@ public IntType getType() { @Override public LitExpr eval(Valuation val) { - throw new UnsupportedFrontendElementException("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/function/FunctionVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/function/FunctionVisitor.java index a8325f792f..60fd59cf19 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/ArithmeticTrait.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/ArithmeticTrait.java index 4cc2a90561..103757ef89 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/ArithmeticTrait.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/ArithmeticTrait.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.preprocess; public enum ArithmeticTrait { - LIN_INT, NONLIN_INT, BITWISE, FLOAT, ARR, MULTITHREAD + LIN_INT, + NONLIN_INT, + BITWISE, + FLOAT, + ARR, + MULTITHREAD } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/BitwiseChecker.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/BitwiseChecker.java index 1a47851372..feda80a944 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/BitwiseChecker.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/BitwiseChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.preprocess; import hu.bme.mit.theta.c.frontend.dsl.gen.CBaseVisitor; @@ -24,7 +23,6 @@ import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.DirectDeclaratorArray4Context; import hu.bme.mit.theta.c.frontend.dsl.gen.CParser.MultiplicativeExpressionContext; import hu.bme.mit.theta.frontend.ParseContext; - import java.util.List; import java.util.Set; @@ -35,7 +33,8 @@ private BitwiseChecker(ParseContext parseContext) { this.parseContext = parseContext; } - public static Set gatherArithmeticTraits(ParseContext parseContext, List contexts) { + public static Set gatherArithmeticTraits( + ParseContext parseContext, List contexts) { BitwiseChecker instance = new BitwiseChecker(parseContext); for (CParser.ExternalDeclarationContext ctx : contexts) { ctx.accept(instance); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/GlobalDeclUsageVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/GlobalDeclUsageVisitor.java index ac26995168..86e2d8917f 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/GlobalDeclUsageVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/GlobalDeclUsageVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.preprocess; +import static com.google.common.base.Preconditions.checkState; + 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.common.Tuple2; import hu.bme.mit.theta.frontend.transformation.grammar.type.DeclarationVisitor; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; - import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -32,8 +32,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkState; - public class GlobalDeclUsageVisitor extends CBaseVisitor> { private final DeclarationVisitor declarationVisitor; @@ -41,7 +39,6 @@ public GlobalDeclUsageVisitor(DeclarationVisitor declarationVisitor) { this.declarationVisitor = declarationVisitor; } - public void clear() { globalUsages.clear(); usedContexts.clear(); @@ -49,18 +46,28 @@ public void clear() { } private final Map> globalUsages = new LinkedHashMap<>(); - private final List> usedContexts = new ArrayList<>(); + private final List> usedContexts = + new ArrayList<>(); private String current; @Override public List visitGlobalDeclaration(CParser.GlobalDeclarationContext ctx) { - List declarations = declarationVisitor.getDeclarations(ctx.declaration().declarationSpecifiers(), ctx.declaration().initDeclaratorList(), false); + List declarations = + declarationVisitor.getDeclarations( + ctx.declaration().declarationSpecifiers(), + ctx.declaration().initDeclaratorList(), + false); for (CDeclaration declaration : declarations) { if (!declaration.getType().isTypedef()) { globalUsages.remove(declaration.getName()); globalUsages.put(declaration.getName(), new LinkedHashSet<>()); - if (usedContexts.stream().anyMatch(c -> Objects.equals(c.get1(), declaration.getName()))) { - usedContexts.replaceAll(c -> Objects.equals(c.get1(), declaration.getName()) ? Tuple2.of(declaration.getName(), ctx) : c); // keep the order, but overwrite the context + if (usedContexts.stream() + .anyMatch(c -> Objects.equals(c.get1(), declaration.getName()))) { + usedContexts.replaceAll( + c -> + Objects.equals(c.get1(), declaration.getName()) + ? Tuple2.of(declaration.getName(), ctx) + : c); // keep the order, but overwrite the context } else { usedContexts.add(Tuple2.of(declaration.getName(), ctx)); } @@ -73,7 +80,8 @@ public List visitGlobalDeclaration(CParser.GlobalDeclarationContex } @Override - public List visitExternalFunctionDefinition(CParser.ExternalFunctionDefinitionContext ctx) { + public List visitExternalFunctionDefinition( + CParser.ExternalFunctionDefinitionContext ctx) { CDeclaration funcDecl = ctx.functionDefinition().declarator().accept(declarationVisitor); globalUsages.put(funcDecl.getName(), new LinkedHashSet<>()); usedContexts.add(Tuple2.of(funcDecl.getName(), ctx)); @@ -89,10 +97,12 @@ public List visitPrimaryExpressionId(CParser.PrimaryExpressionIdCo return null; } - public List getGlobalUsages(CParser.CompilationUnitContext ctx) { + public List getGlobalUsages( + CParser.CompilationUnitContext ctx) { globalUsages.clear(); usedContexts.clear(); - for (CParser.ExternalDeclarationContext externalDeclarationContext : ctx.translationUnit().externalDeclaration()) { + for (CParser.ExternalDeclarationContext externalDeclarationContext : + ctx.translationUnit().externalDeclaration()) { try { externalDeclarationContext.accept(this); } catch (Throwable e) { @@ -107,10 +117,17 @@ public List getGlobalUsages(CParser.Compilat Optional remOpt = remaining.stream().findAny(); String rem = remOpt.get(); ret.add(rem); - Set toAdd = globalUsages.get(rem).stream().filter(globalUsages::containsKey).collect(Collectors.toSet()); + Set toAdd = + globalUsages.get(rem).stream() + .filter(globalUsages::containsKey) + .collect(Collectors.toSet()); remaining.addAll(toAdd); remaining.removeAll(ret); } - return usedContexts.stream().filter(objects -> ret.contains(objects.get1())).map(Tuple2::get2).distinct().collect(Collectors.toList()); + return usedContexts.stream() + .filter(objects -> ret.contains(objects.get1())) + .map(Tuple2::get2) + .distinct() + .collect(Collectors.toList()); } } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/TypedefVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/TypedefVisitor.java index 2e6e45a1d2..724d444978 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/TypedefVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/grammar/preprocess/TypedefVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.preprocess; import hu.bme.mit.theta.c.frontend.dsl.gen.CBaseVisitor; @@ -22,12 +21,11 @@ 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 org.antlr.v4.runtime.tree.ParseTree; - import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; import java.util.Set; +import org.antlr.v4.runtime.tree.ParseTree; public class TypedefVisitor extends CBaseVisitor> { private final DeclarationVisitor declarationVisitor; @@ -43,18 +41,26 @@ public void clear() { private final Set declarations = new LinkedHashSet<>(); public Optional getType(String id) { - return declarations.stream().filter(cDeclaration -> cDeclaration.getName().equals(id)).map(CDeclaration::getActualType).findFirst(); + return declarations.stream() + .filter(cDeclaration -> cDeclaration.getName().equals(id)) + .map(CDeclaration::getActualType) + .findFirst(); } public Optional getSimpleType(String id) { - return declarations.stream().filter(cDeclaration -> cDeclaration.getName().equals(id)).map(CDeclaration::getType).findFirst(); + return declarations.stream() + .filter(cDeclaration -> cDeclaration.getName().equals(id)) + .map(CDeclaration::getType) + .findFirst(); } @Override public Set visitDeclaration(CParser.DeclarationContext ctx) { Set ret = new LinkedHashSet<>(); if (ctx.declarationSpecifiers().declarationSpecifier(0).getText().equals("typedef")) { - List declarations = declarationVisitor.getDeclarations(ctx.declarationSpecifiers(), ctx.initDeclaratorList()); + List declarations = + declarationVisitor.getDeclarations( + ctx.declarationSpecifiers(), ctx.initDeclaratorList()); this.declarations.addAll(declarations); ret.addAll(declarations); return ret; @@ -90,8 +96,15 @@ public Set visitCompoundStatement(CParser.CompoundStatementContext @Override public Set visitGlobalDeclaration(CParser.GlobalDeclarationContext ctx) { Set ret = new LinkedHashSet<>(); - if (ctx.declaration().declarationSpecifiers().declarationSpecifier(0).getText().equals("typedef")) { - List declarations = declarationVisitor.getDeclarations(ctx.declaration().declarationSpecifiers(), ctx.declaration().initDeclaratorList()); + if (ctx.declaration() + .declarationSpecifiers() + .declarationSpecifier(0) + .getText() + .equals("typedef")) { + List declarations = + declarationVisitor.getDeclarations( + ctx.declaration().declarationSpecifiers(), + ctx.declaration().initDeclaratorList()); ret.addAll(declarations); this.declarations.addAll(declarations); return ret; @@ -104,14 +117,16 @@ public Set visitCompilationUnit(CParser.CompilationUnitContext ctx declarations.clear(); CParser.TranslationUnitContext translationUnitContext = ctx.translationUnit(); if (translationUnitContext != null) { - for (CParser.ExternalDeclarationContext externalDeclarationContext : translationUnitContext.externalDeclaration()) { + for (CParser.ExternalDeclarationContext externalDeclarationContext : + translationUnitContext.externalDeclaration()) { try { Set declList = externalDeclarationContext.accept(this); if (declList != null) { declarations.addAll(declList); } } catch (Throwable e) { - // we don't do anything, we'll throw an error later if something crucial is missing + // we don't do anything, we'll throw an error later if something crucial is + // missing } } } 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 84be79414d..f9286e488e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.type; +import static com.google.common.base.Preconditions.checkState; + 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.common.logging.Logger; @@ -31,12 +32,9 @@ import hu.bme.mit.theta.frontend.transformation.model.statements.CInitializerList; import hu.bme.mit.theta.frontend.transformation.model.statements.CStatement; import hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleType; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkState; - public class DeclarationVisitor extends CBaseVisitor { private final ParseContext parseContext; private final FunctionVisitor functionVisitor; @@ -44,7 +42,10 @@ public class DeclarationVisitor extends CBaseVisitor { private final TypeVisitor typeVisitor; private final Logger uniqueWarningLogger; - public DeclarationVisitor(ParseContext parseContext, FunctionVisitor functionVisitor, Logger uniqueWarningLogger) { + public DeclarationVisitor( + ParseContext parseContext, + FunctionVisitor functionVisitor, + Logger uniqueWarningLogger) { this.parseContext = parseContext; this.functionVisitor = functionVisitor; this.uniqueWarningLogger = uniqueWarningLogger; @@ -60,9 +61,9 @@ public TypeVisitor getTypeVisitor() { return typeVisitor; } - - public List getDeclarations(CParser.DeclarationSpecifiersContext declSpecContext, - CParser.InitDeclaratorListContext initDeclContext) { + public List getDeclarations( + CParser.DeclarationSpecifiersContext declSpecContext, + CParser.InitDeclaratorListContext initDeclContext) { return getDeclarations(declSpecContext, initDeclContext, true); } @@ -74,9 +75,10 @@ public List getDeclarations(CParser.DeclarationSpecifiersContext d * @param initDeclContext initialization list context * @return the corresponding CDeclarations */ - public List getDeclarations(CParser.DeclarationSpecifiersContext declSpecContext, - CParser.InitDeclaratorListContext initDeclContext, - boolean getInitExpr) { + public List getDeclarations( + CParser.DeclarationSpecifiersContext declSpecContext, + CParser.InitDeclaratorListContext initDeclContext, + boolean getInitExpr) { List ret = new ArrayList<>(); CSimpleType cSimpleType = declSpecContext.accept(typeVisitor); if (cSimpleType.getAssociatedName() != null) { @@ -94,23 +96,40 @@ public List getDeclarations(CParser.DeclarationSpecifiersContext d checkState( context.initializer().initializerList().designation().size() == 0, "Initializer list designators not yet implemented!"); - CInitializerList cInitializerList = new CInitializerList( - cSimpleType.getActualType(), parseContext); + CInitializerList cInitializerList = + new CInitializerList(cSimpleType.getActualType(), parseContext); try { - for (CParser.InitializerContext initializer : context.initializer() - .initializerList().initializers) { - Expr expr = cSimpleType.getActualType().castTo(initializer.assignmentExpression().accept(functionVisitor).getExpression()); + for (CParser.InitializerContext initializer : + context.initializer().initializerList().initializers) { + Expr expr = + cSimpleType + .getActualType() + .castTo( + initializer + .assignmentExpression() + .accept(functionVisitor) + .getExpression()); parseContext.getMetadata().create(expr, "cType", cSimpleType); - cInitializerList.addStatement(null /* TODO: add designator */, new CExpr(expr, parseContext)); + cInitializerList.addStatement( + null /* TODO: add designator */, + new CExpr(expr, parseContext)); } initializerExpression = cInitializerList; } catch (NullPointerException e) { - initializerExpression = new CExpr(new UnsupportedInitializer(), parseContext); - parseContext.getMetadata().create(initializerExpression.getExpression(), "cType", cSimpleType); + initializerExpression = + new CExpr(new UnsupportedInitializer(), parseContext); + parseContext + .getMetadata() + .create( + initializerExpression.getExpression(), + "cType", + cSimpleType); } } else { - initializerExpression = context.initializer().assignmentExpression() - .accept(functionVisitor); + initializerExpression = + context.initializer() + .assignmentExpression() + .accept(functionVisitor); } declaration.setInitExpr(initializerExpression); } @@ -118,7 +137,8 @@ public List getDeclarations(CParser.DeclarationSpecifiersContext d ret.add(declaration); } } - if (cSimpleType.getAssociatedName() == null && initDeclContext != null + if (cSimpleType.getAssociatedName() == null + && initDeclContext != null && initDeclContext.initDeclarator().size() > 0) { ret.get(0).incDerefCounter(cSimpleType.getPointerLevel()); } @@ -154,9 +174,11 @@ public CDeclaration visitAbstractParameterDeclaration( @Override public CDeclaration visitDeclarator(CParser.DeclaratorContext ctx) { - checkState(ctx.pointer() == null || ctx.pointer().typeQualifierList().size() == 0, + checkState( + ctx.pointer() == null || ctx.pointer().typeQualifierList().size() == 0, "pointers should not have type qualifiers! (not yet implemented)"); - //checkState(ctx.gccDeclaratorExtension().size() == 0, "Cannot do anything with gccDeclaratorExtensions!"); + // checkState(ctx.gccDeclaratorExtension().size() == 0, "Cannot do anything with + // gccDeclaratorExtensions!"); CDeclaration decl = ctx.directDeclarator().accept(this); if (ctx.pointer() != null) { @@ -178,7 +200,8 @@ public CDeclaration visitDirectDeclaratorBraces(CParser.DirectDeclaratorBracesCo @Override public CDeclaration visitDirectDeclaratorArray1(CParser.DirectDeclaratorArray1Context ctx) { - checkState(ctx.typeQualifierList() == null, + checkState( + ctx.typeQualifierList() == null, "Type qualifiers inside array declarations are not yet implemented."); CDeclaration decl = ctx.directDeclarator().accept(this); @@ -215,8 +238,8 @@ public CDeclaration visitDirectDeclaratorFunctionDecl( return decl; } if (ctx.parameterTypeList() != null) { - for (CParser.ParameterDeclarationContext parameterDeclarationContext : ctx.parameterTypeList() - .parameterList().parameterDeclaration()) { + for (CParser.ParameterDeclarationContext parameterDeclarationContext : + ctx.parameterTypeList().parameterList().parameterDeclaration()) { decl.addFunctionParam(parameterDeclarationContext.accept(this)); } } 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 8fad36f961..afdbceef43 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.grammar.type; +import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.*; + 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.CastDeclarationSpecifierContext; @@ -29,15 +30,12 @@ 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.Enum; import hu.bme.mit.theta.frontend.transformation.model.types.simple.*; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.tree.ParseTree; - +import hu.bme.mit.theta.frontend.transformation.model.types.simple.Enum; import java.util.*; import java.util.stream.Collectors; - -import static hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleTypeFactory.*; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.tree.ParseTree; public class TypeVisitor extends CBaseVisitor { private final DeclarationVisitor declarationVisitor; @@ -45,20 +43,22 @@ public class TypeVisitor extends CBaseVisitor { private final ParseContext parseContext; private final Logger uniqueWarningLogger; - private static final List standardTypes = List.of("int", "char", "long", "short", "void", "float", "double", "unsigned", "_Bool"); private static final List shorthandTypes = List.of("long", "__int128", "short", "unsigned", "_Bool"); - public TypeVisitor(DeclarationVisitor declarationVisitor, TypedefVisitor typedefVisitor, ParseContext parseContext, Logger uniqueWarningLogger) { + public TypeVisitor( + DeclarationVisitor declarationVisitor, + TypedefVisitor typedefVisitor, + ParseContext parseContext, + Logger uniqueWarningLogger) { this.declarationVisitor = declarationVisitor; this.typedefVisitor = typedefVisitor; this.parseContext = parseContext; this.uniqueWarningLogger = uniqueWarningLogger; } - @Override public CSimpleType visitDeclarationSpecifiers(CParser.DeclarationSpecifiersContext ctx) { return createCType(ctx.declarationSpecifier()); @@ -75,25 +75,42 @@ public CSimpleType visitCastDeclarationSpecifierList(CastDeclarationSpecifierLis } private CSimpleType mergeCTypes(List cSimpleTypes) { - List enums = cSimpleTypes.stream().filter(cType -> cType instanceof Enum) - .collect(Collectors.toList()); + List enums = + cSimpleTypes.stream() + .filter(cType -> cType instanceof Enum) + .collect(Collectors.toList()); if (enums.size() > 0) { - uniqueWarningLogger.write(Level.INFO, "WARNING: enums are not yet supported! Using int instead.\n"); + uniqueWarningLogger.write( + Level.INFO, "WARNING: enums are not yet supported! Using int instead.\n"); cSimpleTypes.add(NamedType("int", parseContext, uniqueWarningLogger)); cSimpleTypes.removeAll(enums); } - List namedElements = cSimpleTypes.stream() - .map(o -> o instanceof DeclaredName declaredName ? typedefVisitor.getSimpleType(declaredName.getDeclaredName()).orElse(o) : o) - .filter(o -> o instanceof NamedType).collect(Collectors.toList()); + List namedElements = + cSimpleTypes.stream() + .map( + o -> + o instanceof DeclaredName declaredName + ? typedefVisitor + .getSimpleType( + declaredName.getDeclaredName()) + .orElse(o) + : o) + .filter(o -> o instanceof NamedType) + .collect(Collectors.toList()); if (namedElements.isEmpty()) { namedElements.add(NamedType("int", parseContext, uniqueWarningLogger)); } - CSimpleType mainType = namedElements.get(namedElements.size() - 1); // if typedef, then last element is the associated name + CSimpleType mainType = + namedElements.get( + namedElements.size() + - 1); // if typedef, then last element is the associated name if (mainType instanceof DeclaredName declaredName) { - mainType = typedefVisitor.getSimpleType(declaredName.getDeclaredName()).orElse(mainType); + mainType = + typedefVisitor.getSimpleType(declaredName.getDeclaredName()).orElse(mainType); } - if (mainType instanceof NamedType namedType && shorthandTypes.contains(namedType.getNamedType())) { + if (mainType instanceof NamedType namedType + && shorthandTypes.contains(namedType.getNamedType())) { mainType = NamedType("int", parseContext, uniqueWarningLogger); } else { cSimpleTypes.remove(mainType); @@ -103,8 +120,10 @@ private CSimpleType mergeCTypes(List cSimpleTypes) { // we didn't get explicit signedness if (type.isSigned() == null) { if (type instanceof NamedType && ((NamedType) type).getNamedType().contains("char")) { - uniqueWarningLogger.write(Level.INFO, - "WARNING: signedness of the type char is implementation specific. Right now it is interpreted as a signed char.\n"); + uniqueWarningLogger.write( + Level.INFO, + "WARNING: signedness of the type char is implementation specific. Right now" + + " it is interpreted as a signed char.\n"); } type.setSigned(true); } @@ -120,22 +139,23 @@ private CSimpleType createCType( CParser.SpecifierQualifierListContext specifierQualifierListContext) { List cSimpleTypes = new ArrayList<>(); if (specifierQualifierListContext != null) { - for (CParser.TypeSpecifierOrQualifierContext typeSpecifierOrQualifierContext : specifierQualifierListContext.typeSpecifierOrQualifier()) { + for (CParser.TypeSpecifierOrQualifierContext typeSpecifierOrQualifierContext : + specifierQualifierListContext.typeSpecifierOrQualifier()) { CSimpleType qualifierSpecifier = null; if (typeSpecifierOrQualifierContext.typeSpecifier() != null) { - qualifierSpecifier = typeSpecifierOrQualifierContext.typeSpecifier() - .accept(this); + qualifierSpecifier = + typeSpecifierOrQualifierContext.typeSpecifier().accept(this); } else if (typeSpecifierOrQualifierContext.typeQualifier() != null) { - qualifierSpecifier = typeSpecifierOrQualifierContext.typeQualifier() - .accept(this); + qualifierSpecifier = + typeSpecifierOrQualifierContext.typeQualifier().accept(this); } if (qualifierSpecifier != null) { cSimpleTypes.add(qualifierSpecifier); } } if (specifierQualifierListContext.typeSpecifierPointer() != null) { - CSimpleType qualifierSpecifier = specifierQualifierListContext.typeSpecifierPointer() - .accept(this); + CSimpleType qualifierSpecifier = + specifierQualifierListContext.typeSpecifierPointer().accept(this); if (qualifierSpecifier != null) { cSimpleTypes.add(qualifierSpecifier); } @@ -148,7 +168,8 @@ private CSimpleType createCType( private CSimpleType createCType( List declarationSpecifierContexts) { List cSimpleTypes = new ArrayList<>(); - for (CParser.DeclarationSpecifierContext declarationSpecifierContext : declarationSpecifierContexts) { + for (CParser.DeclarationSpecifierContext declarationSpecifierContext : + declarationSpecifierContexts) { for (ParseTree child : declarationSpecifierContext.children) { CSimpleType ctype = child.accept(this); if (ctype != null) { @@ -161,9 +182,7 @@ private CSimpleType createCType( } private CSimpleType createCType( - List spec1list, - TypeSpecifierPointerContext spec2 - ) { + List spec1list, TypeSpecifierPointerContext spec2) { List cSimpleTypes = new ArrayList<>(); for (CastDeclarationSpecifierContext declarationSpecifierContext : spec1list) { for (ParseTree child : declarationSpecifierContext.children) { @@ -195,7 +214,8 @@ public CSimpleType visitStorageClassSpecifier(CParser.StorageClassSpecifierConte case "auto": case "register": case "_Thread_local": - throw new UnsupportedFrontendElementException("Not yet implemented (" + ctx.getText() + ")"); + throw new UnsupportedFrontendElementException( + "Not yet implemented (" + ctx.getText() + ")"); } throw new UnsupportedFrontendElementException( "Storage class specifier not expected: " + ctx.getText()); @@ -212,7 +232,8 @@ public CSimpleType visitTypeSpecifierCompound(CParser.TypeSpecifierCompoundConte } @Override - public CSimpleType visitTypeSpecifierFunctionPointer(CParser.TypeSpecifierFunctionPointerContext ctx) { + public CSimpleType visitTypeSpecifierFunctionPointer( + CParser.TypeSpecifierFunctionPointerContext ctx) { throw new UnsupportedFrontendElementException("Function pointers not yet implemented"); } @@ -224,18 +245,19 @@ public CSimpleType visitCompoundDefinition(CParser.CompoundDefinitionContext ctx name = ctx.Identifier().getText(); } Struct struct = CSimpleTypeFactory.Struct(name, parseContext, uniqueWarningLogger); - for (CParser.StructDeclarationContext structDeclarationContext : ctx.structDeclarationList() - .structDeclaration()) { - CParser.SpecifierQualifierListContext specifierQualifierListContext = structDeclarationContext.specifierQualifierList(); + for (CParser.StructDeclarationContext structDeclarationContext : + ctx.structDeclarationList().structDeclaration()) { + CParser.SpecifierQualifierListContext specifierQualifierListContext = + structDeclarationContext.specifierQualifierList(); CSimpleType cSimpleType = specifierQualifierListContext.accept(this); if (structDeclarationContext.structDeclaratorList() == null) { final var decl = new CDeclaration(cSimpleType); struct.addField(decl); } else { - for (CParser.StructDeclaratorContext structDeclaratorContext : structDeclarationContext.structDeclaratorList() - .structDeclarator()) { - CDeclaration declaration = structDeclaratorContext.accept( - declarationVisitor); + for (CParser.StructDeclaratorContext structDeclaratorContext : + structDeclarationContext.structDeclaratorList().structDeclarator()) { + CDeclaration declaration = + structDeclaratorContext.accept(declarationVisitor); if (declaration.getType() == null) { declaration.setType(cSimpleType); } @@ -245,7 +267,8 @@ public CSimpleType visitCompoundDefinition(CParser.CompoundDefinitionContext ctx } return struct; } else { - uniqueWarningLogger.write(Level.INFO, "WARNING: CompoundDefinitions are not yet implemented!\n"); + uniqueWarningLogger.write( + Level.INFO, "WARNING: CompoundDefinitions are not yet implemented!\n"); return NamedType("int", parseContext, uniqueWarningLogger); } } @@ -256,7 +279,8 @@ public CSimpleType visitCompoundUsage(CParser.CompoundUsageContext ctx) { if (ctx.structOrUnion().Struct() != null) { return Struct.getByName(text); } else { - return NamedType(ctx.structOrUnion().getText() + " " + text, parseContext, uniqueWarningLogger); + return NamedType( + ctx.structOrUnion().getText() + " " + text, parseContext, uniqueWarningLogger); } } @@ -271,9 +295,12 @@ public CSimpleType visitEnumDefinition(CParser.EnumDefinitionContext ctx) { Map>> fields = new LinkedHashMap<>(); for (CParser.EnumeratorContext enumeratorContext : ctx.enumeratorList().enumerator()) { String value = enumeratorContext.enumerationConstant().getText(); - CParser.ConstantExpressionContext expressionContext = enumeratorContext.constantExpression(); + CParser.ConstantExpressionContext expressionContext = + enumeratorContext.constantExpression(); Expr expr = - expressionContext == null ? null : null;//expressionContext.accept(null ); // TODO + expressionContext == null + ? null + : null; // expressionContext.accept(null ); // TODO fields.put(value, Optional.ofNullable(expr)); } return Enum(id, fields); @@ -377,5 +404,4 @@ public CSimpleType visitFunctionSpecifier(CParser.FunctionSpecifierContext ctx) public CSimpleType visitAlignmentSpecifier(CParser.AlignmentSpecifierContext ctx) { return null; } - } 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 cd00c718f1..c74e29ca94 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 8d285f2d04..b4ce381441 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.AbstractExprs; import hu.bme.mit.theta.core.type.bvtype.BvExprs; @@ -23,19 +25,16 @@ 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; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - public class CAssignment extends CStatement { private final Expr lValue; private final CStatement rValue; private final String operator; - public CAssignment(Expr lValue, CStatement rValue, String operator, ParseContext parseContext) { + public CAssignment( + Expr lValue, CStatement rValue, String operator, ParseContext parseContext) { super(parseContext); checkNotNull(rValue.getExpression()); this.lValue = lValue; @@ -88,16 +87,34 @@ public Expr getrExpression() { ret = AbstractExprs.Sub(type.castTo(lValue), type.castTo(rExpression)); break; case "^=": - checkState(lValue.getType() instanceof BvType && rExpression.getType() instanceof BvType); - ret = BvExprs.Xor(List.of((Expr) type.castTo(lValue), (Expr) type.castTo(rExpression))); + checkState( + lValue.getType() instanceof BvType + && rExpression.getType() instanceof BvType); + ret = + BvExprs.Xor( + List.of( + (Expr) type.castTo(lValue), + (Expr) type.castTo(rExpression))); break; case "&=": - checkState(lValue.getType() instanceof BvType && rExpression.getType() instanceof BvType); - ret = BvExprs.And(List.of((Expr) type.castTo(lValue), (Expr) type.castTo(rExpression))); + checkState( + lValue.getType() instanceof BvType + && rExpression.getType() instanceof BvType); + ret = + BvExprs.And( + List.of( + (Expr) type.castTo(lValue), + (Expr) type.castTo(rExpression))); break; case "|=": - checkState(lValue.getType() instanceof BvType && rExpression.getType() instanceof BvType); - ret = BvExprs.Or(List.of((Expr) type.castTo(lValue), (Expr) type.castTo(rExpression))); + checkState( + lValue.getType() instanceof BvType + && rExpression.getType() instanceof BvType); + ret = + BvExprs.Or( + List.of( + (Expr) type.castTo(lValue), + (Expr) type.castTo(rExpression))); break; default: throw new UnsupportedFrontendElementException("Unsupported operator: " + operator); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssume.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssume.java index 34100a9186..4a47327d8b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssume.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CAssume.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; -import static com.google.common.base.Preconditions.checkNotNull; - public class CAssume extends CStatement { private final AssumeStmt assumeStmt; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CBreak.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CBreak.java index af444c770e..0aecb42358 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CBreak.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CBreak.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCall.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCall.java index f5f36e7ee8..35dac2bf24 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCall.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCall.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,19 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; +import static hu.bme.mit.theta.core.decl.Decls.Var; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.frontend.ParseContext; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cint.CSignedInt; - import java.util.List; import java.util.Optional; -import static hu.bme.mit.theta.core.decl.Decls.Var; - public class CCall extends CStatement { private final VarDecl ret; @@ -36,8 +34,10 @@ public CCall(String functionId, List params, ParseContext parseConte super(parseContext); this.functionId = functionId; this.params = params; - Optional cTypeOpt = parseContext.getMetadata().getMetadataValue(functionId, "cType"); - CComplexType type = (CComplexType) cTypeOpt.orElseGet(() -> new CSignedInt(null, parseContext)); + Optional cTypeOpt = + parseContext.getMetadata().getMetadataValue(functionId, "cType"); + CComplexType type = + (CComplexType) cTypeOpt.orElseGet(() -> new CSignedInt(null, parseContext)); ret = Var("call_" + functionId + "_ret" + counter++, type.getSmtType()); parseContext.getMetadata().create(ret.getRef(), "cType", type); } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCase.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCase.java index 9f1004d4c7..202e2a2cd5 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCase.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCompound.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCompound.java index d5ff044e53..f0674181d3 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCompound.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CCompound.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; - import java.util.ArrayList; import java.util.List; @@ -54,5 +52,4 @@ public void setPreStatements(CStatement preStatements) { public R accept(CStatementVisitor visitor, P param) { return visitor.visit(this, param); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CContinue.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CContinue.java index 14a6d1d169..2f2462b6e5 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CContinue.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CContinue.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDecls.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDecls.java index c9634ceae9..05e9d26bc7 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDecls.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDecls.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.frontend.ParseContext; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; - import java.util.ArrayList; import java.util.List; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDefault.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDefault.java index 504e529d6f..ca08570c3b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDefault.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDefault.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDoWhile.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDoWhile.java index bd5a7f72b4..9196285c45 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDoWhile.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CDoWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CExpr.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CExpr.java index a2c4037608..5d3128a23e 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CExpr.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.core.type.Expr; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFor.java index 8d43a8aa59..cf0072ca3c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; @@ -25,7 +24,12 @@ public class CFor extends CStatement { private final CStatement guard; private final CStatement increment; - public CFor(CStatement body, CStatement init, CStatement guard, CStatement increment, ParseContext parseContext) { + public CFor( + CStatement body, + CStatement init, + CStatement guard, + CStatement increment, + ParseContext parseContext) { super(parseContext); this.body = body; this.init = init; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFunction.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFunction.java index 8da47ca0db..4aa5d93953 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFunction.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CGoto.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CGoto.java index 9a0dfca141..8c14a23c2d 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CGoto.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CGoto.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CIf.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CIf.java index 9b407e1d59..2103de9922 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CIf.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CIf.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; @@ -24,7 +23,11 @@ public class CIf extends CStatement { private final CStatement body; private final CStatement elseStatement; - public CIf(CStatement guard, CStatement body, CStatement elseStatement, ParseContext parseContext) { + public CIf( + CStatement guard, + CStatement body, + CStatement elseStatement, + ParseContext parseContext) { super(parseContext); this.guard = guard; this.body = body; 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 d12151fe4b..dfbd6b2ad6 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.common.Tuple2; @@ -21,12 +20,11 @@ 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; import java.util.List; import java.util.Optional; -//TODO: designators +// TODO: designators public class CInitializerList extends CStatement { private final List, CStatement>> statements; private final CComplexType type; @@ -39,7 +37,8 @@ public CInitializerList(CComplexType type, ParseContext parseContext) { @Override public Expr getExpression() { - throw new UnsupportedFrontendElementException("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/CProgram.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CProgram.java index a588fa6bee..972b164733 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CProgram.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CProgram.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.frontend.ParseContext; import hu.bme.mit.theta.frontend.transformation.model.declaration.CDeclaration; - import java.util.ArrayList; import java.util.List; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CRet.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CRet.java index ad169a3d23..a26ab39025 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CRet.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CRet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; 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 989f18d3b8..b0573bdd1e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitor.java index 327b236530..8b02b58a5a 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; public interface CStatementVisitor { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitorBase.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitorBase.java index 5b1be35994..6516aa4379 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitorBase.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CStatementVisitorBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; public abstract class CStatementVisitorBase implements CStatementVisitor { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CSwitch.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CSwitch.java index 62cc74dea1..dc3dbf2f45 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CSwitch.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CSwitch.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CWhile.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CWhile.java index 69244dd115..aa061dbe6e 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CWhile.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/statements/CWhile.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.statements; import hu.bme.mit.theta.frontend.ParseContext; public class CWhile extends CStatement { - //TODO: guard should not be multiple compounds inside! + // TODO: guard should not be multiple compounds inside! private final CStatement body; private final CStatement guard; 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 1f54441d28..4314f23788 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex; +import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.*; + import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; @@ -54,13 +55,10 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CLongDouble; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CReal; import hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleType; - import java.util.List; import java.util.Map.Entry; import java.util.Optional; -import static hu.bme.mit.theta.frontend.transformation.ArchitectureConfig.*; - public abstract class CComplexType { private final CSimpleType origin; private boolean threadLocal = false; @@ -125,7 +123,8 @@ public int width() { return parseContext.getArchitecture().getBitWidth(getTypeName()); } - public static CComplexType getSmallestCommonType(List types, ParseContext parseContext) { + public static CComplexType getSmallestCommonType( + List types, ParseContext parseContext) { CComplexType ret = getSignedInt(parseContext); for (int i = 0; i < types.size(); i++) { ret = ret.getSmallestCommonType(types.get(i)); @@ -170,7 +169,7 @@ public static CComplexType getType(Expr expr, ParseContext parseContext) { return ((CSimpleType) cTypeOptional.get()).getActualType(); } else { return getType(expr.getType(), parseContext); -// throw new RuntimeException("Type not known for expression: " + expr); + // throw new RuntimeException("Type not known for expression: " + expr); } } @@ -182,27 +181,32 @@ private static CComplexType getType(Type type, ParseContext parseContext) { } else if (type instanceof BoolType) { return new CBool(null, parseContext); } else if (type instanceof FpType) { - final var doubleType = FpType.of( - parseContext.getArchitecture().getBitWidth("double_e"), - parseContext.getArchitecture().getBitWidth("double_s")); + final var doubleType = + FpType.of( + parseContext.getArchitecture().getBitWidth("double_e"), + parseContext.getArchitecture().getBitWidth("double_s")); if (doubleType.equals(type)) { return new CDouble(null, parseContext); } - final var floatType = FpType.of( - parseContext.getArchitecture().getBitWidth("float_e"), - parseContext.getArchitecture().getBitWidth("float_s")); + final var floatType = + FpType.of( + parseContext.getArchitecture().getBitWidth("float_e"), + parseContext.getArchitecture().getBitWidth("float_s")); if (floatType.equals(type)) { return new CFloat(null, parseContext); } - final var longDoubleType = FpType.of( - parseContext.getArchitecture().getBitWidth("longdouble_e"), - parseContext.getArchitecture().getBitWidth("longdouble_s")); + final var longDoubleType = + FpType.of( + parseContext.getArchitecture().getBitWidth("longdouble_e"), + parseContext.getArchitecture().getBitWidth("longdouble_s")); if (longDoubleType.equals(type)) { return new CFloat(null, parseContext); } - throw new UnsupportedFrontendElementException("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()) { + for (Entry entry : + parseContext.getArchitecture().standardTypeSizes.entrySet()) { String s = entry.getKey(); Integer integer = entry.getValue(); if (integer == ((BvType) type).getSize()) { @@ -210,25 +214,35 @@ private static CComplexType getType(Type type, ParseContext parseContext) { case "bool": return new CBool(null, parseContext); case "short": - return ((BvType) type).getSigned() ? new CSignedShort(null, parseContext) : new CUnsignedShort(null, parseContext); + return ((BvType) type).getSigned() + ? new CSignedShort(null, parseContext) + : new CUnsignedShort(null, parseContext); case "int": - return ((BvType) type).getSigned() ? new CSignedInt(null, parseContext) : new CUnsignedInt(null, parseContext); + return ((BvType) type).getSigned() + ? new CSignedInt(null, parseContext) + : new CUnsignedInt(null, parseContext); case "long": - return ((BvType) type).getSigned() ? new CSignedLong(null, parseContext) : new CUnsignedLong(null, parseContext); + return ((BvType) type).getSigned() + ? new CSignedLong(null, parseContext) + : new CUnsignedLong(null, parseContext); case "longlong": - return ((BvType) type).getSigned() ? new CSignedLongLong(null, parseContext) : new CUnsignedLongLong(null, parseContext); + return ((BvType) type).getSigned() + ? new CSignedLongLong(null, parseContext) + : new CUnsignedLongLong(null, parseContext); case "__int128": - return ((BvType) type).getSigned() ? new CSigned128(null, parseContext) : new CUnsigned128(null, parseContext); + return ((BvType) type).getSigned() + ? new CSigned128(null, parseContext) + : new CUnsigned128(null, parseContext); } } } - throw new UnsupportedFrontendElementException("No suitable width found for type: " + type); + throw new UnsupportedFrontendElementException( + "No suitable width found for type: " + type); } else { throw new UnsupportedFrontendElementException("Not yet implemented for type: " + type); } } - public void setThreadLocal() { threadLocal = true; } @@ -299,7 +313,12 @@ public R accept(CComplexTypeVisitor visitor, T param) { public static class CComplexTypeVisitor { public R visit(CComplexType type, T param) { - throw new UnsupportedFrontendElementException("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) { @@ -426,5 +445,4 @@ public R visit(CPointer type, T param) { return CComplexType.getUnsignedLong(type.getParseContext()).accept(this, param); } } - } 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 353ca2cc9a..b4a9a8974e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CArray.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CArray.java index 806bfa9a7d..3e92817ec6 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CArray.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CCompound.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CCompound.java index 77fe3e6894..38eb161c32 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CCompound.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CCompound.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.compound; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CFunction.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CFunction.java index 5a61434e9f..27c91d9a29 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CFunction.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.compound; import hu.bme.mit.theta.frontend.ParseContext; @@ -28,5 +27,4 @@ public CFunction(CSimpleType origin, ParseContext parseContext) { public R accept(CComplexTypeVisitor visitor, T param) { return visitor.visit(this, param); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CPointer.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CPointer.java index 023c66b7d1..0db66ea25b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CPointer.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CPointer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.compound; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CStruct.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CStruct.java index c334a96b49..20bccfc68b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CStruct.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/compound/CStruct.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.compound; import hu.bme.mit.theta.common.Tuple2; @@ -22,7 +21,6 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.CInteger; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clong.CUnsignedLong; import hu.bme.mit.theta.frontend.transformation.model.types.simple.CSimpleType; - import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -31,7 +29,10 @@ public class CStruct extends CInteger { private final List> fields; - public CStruct(CSimpleType origin, List> fields, ParseContext parseContext) { + public CStruct( + CSimpleType origin, + List> fields, + ParseContext parseContext) { super(origin, parseContext); this.fields = fields; } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/CInteger.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/CInteger.java index 609ca4c241..a9c8c8ad7b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/CInteger.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/CInteger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer; import hu.bme.mit.theta.frontend.ParseContext; 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 8cb56130a7..93eb0778cd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer; import hu.bme.mit.theta.frontend.ParseContext; @@ -33,7 +32,6 @@ public R accept(CComplexTypeVisitor visitor, T param) { return visitor.visit(this, param); } - @Override public String getTypeName() { return "fitsall"; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Signed.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Signed.java index aa5a99e759..b41c2bdfbf 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Signed.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Signed.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer; -public interface Signed { - -} +public interface Signed {} diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Unsigned.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Unsigned.java index 4ada5c1edd..df6c72b572 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Unsigned.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/Unsigned.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer; -public interface Unsigned { - -} +public interface Unsigned {} diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/C128.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/C128.java index e633e15f6b..2770cc7435 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/C128.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/C128.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.c128; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CSigned128.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CSigned128.java index 628c8dc643..285c395c8f 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CSigned128.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CSigned128.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.c128; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CUnsigned128.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CUnsigned128.java index f8f161d67e..448b451faa 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CUnsigned128.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/c128/CUnsigned128.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.c128; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cbool/CBool.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cbool/CBool.java index 736280c4e4..3ddfe19691 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cbool/CBool.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cbool/CBool.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cbool; import hu.bme.mit.theta.frontend.ParseContext; @@ -35,7 +34,6 @@ public R accept(CComplexTypeVisitor visitor, T param) { return visitor.visit(this, param); } - @Override public String getTypeName() { return "bool"; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CChar.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CChar.java index d10928750a..788fd85e8c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CChar.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CChar.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cchar; import hu.bme.mit.theta.frontend.ParseContext; @@ -47,5 +46,4 @@ public CInteger getSignedVersion() { public CInteger getUnsignedVersion() { return new CUnsignedChar(null, parseContext); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CSignedChar.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CSignedChar.java index 8dd0cf2ac8..9637fecc99 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CSignedChar.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CSignedChar.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cchar; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CUnsignedChar.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CUnsignedChar.java index 8929e11648..4bc40c57ee 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CUnsignedChar.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cchar/CUnsignedChar.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cchar; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CInt.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CInt.java index 5807c305ec..0741c257f9 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CInt.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CInt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cint; import hu.bme.mit.theta.frontend.ParseContext; @@ -33,7 +32,6 @@ public R accept(CComplexTypeVisitor visitor, T param) { return visitor.visit(this, param); } - @Override public String getTypeName() { return "int"; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CSignedInt.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CSignedInt.java index c0398b638d..215bb2b114 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CSignedInt.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CSignedInt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cint; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CUnsignedInt.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CUnsignedInt.java index d86d229364..2f131b9086 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CUnsignedInt.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cint/CUnsignedInt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cint; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CLong.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CLong.java index ec25911694..228afb92f6 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CLong.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clong; import hu.bme.mit.theta.frontend.ParseContext; @@ -33,7 +32,6 @@ public R accept(CComplexTypeVisitor visitor, T param) { return visitor.visit(this, param); } - @Override public String getTypeName() { return "long"; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CSignedLong.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CSignedLong.java index d3abef7047..66ba13feb2 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CSignedLong.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CSignedLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clong; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CUnsignedLong.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CUnsignedLong.java index 8efd0619f1..7291e83f2b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CUnsignedLong.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clong/CUnsignedLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clong; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CLongLong.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CLongLong.java index 3ceb8e3f43..b973315cd3 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CLongLong.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CLongLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clonglong; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CSignedLongLong.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CSignedLongLong.java index 6be08cc7c6..385a6441bb 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CSignedLongLong.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CSignedLongLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clonglong; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CUnsignedLongLong.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CUnsignedLongLong.java index 6b5a00bae2..da2045436e 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CUnsignedLongLong.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/clonglong/CUnsignedLongLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clonglong; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CShort.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CShort.java index c1253d095e..e0e69e0ebc 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CShort.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CShort.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CSignedShort.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CSignedShort.java index 15e3fe4923..afa58dd8d1 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CSignedShort.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CSignedShort.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CUnsignedShort.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CUnsignedShort.java index e5583a8804..8f0a443ba1 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CUnsignedShort.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/integer/cshort/CUnsignedShort.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CDouble.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CDouble.java index 30df1442ca..26fd871d6f 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CDouble.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.real; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CFloat.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CFloat.java index 55615e93c6..ae516f8c64 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CFloat.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CFloat.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.real; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CLongDouble.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CLongDouble.java index 0b79f0a87a..a5225390f5 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CLongDouble.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CLongDouble.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.real; import hu.bme.mit.theta.frontend.ParseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CReal.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CReal.java index fd10961b3b..ff9860d120 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CReal.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/real/CReal.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.real; import hu.bme.mit.theta.frontend.ParseContext; @@ -34,8 +33,8 @@ public R accept(CComplexTypeVisitor visitor, T param) { @Override public int width() { - return parseContext.getArchitecture().getBitWidth(getTypeName() + "_s") + - parseContext.getArchitecture().getBitWidth(getTypeName() + "_e"); + return parseContext.getArchitecture().getBitWidth(getTypeName() + "_s") + + parseContext.getArchitecture().getBitWidth(getTypeName() + "_e"); } @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 6187ff3391..24309f6b4b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.FromBv; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.ToFp; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.bvtype.BvExprs; @@ -51,11 +55,6 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CLongDouble; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CReal; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.FromBv; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.ToFp; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public class CastVisitor extends CComplexType.CComplexTypeVisitor, Expr> { private final ParseContext parseContext; @@ -74,23 +73,26 @@ private Expr handleSignedConversion(CInteger type, Expr param } else if (that instanceof CInteger) { if (that.width() < type.width()) { if (that instanceof Unsigned) { - return BvExprs.ZExt(cast(param, BvType.of(that.width())), - BvType.of(type.width(), true)); + return BvExprs.ZExt( + cast(param, BvType.of(that.width())), BvType.of(type.width(), true)); } - return BvExprs.SExt(cast(param, BvType.of(that.width())), - BvType.of(type.width(), true)); + return BvExprs.SExt( + cast(param, BvType.of(that.width())), BvType.of(type.width(), true)); } else if (that.width() > type.width()) { - return BvExprs.Extract(cast(param, BvType.of(that.width())), Int(0), - Int(type.width())); + return BvExprs.Extract( + cast(param, BvType.of(that.width())), Int(0), Int(type.width())); } else { // width equals if (that instanceof Unsigned) { - return BvSignChangeExpr.of((Expr) param, BvType.of(((BvType) param.getType()).getSize(), true)); + return BvSignChangeExpr.of( + (Expr) param, + BvType.of(((BvType) param.getType()).getSize(), true)); } else { return param; } } } else { - throw new UnsupportedFrontendElementException("Compound types are not directly supported!"); + throw new UnsupportedFrontendElementException( + "Compound types are not directly supported!"); } } @@ -105,22 +107,26 @@ private Expr handleUnsignedConversion(CInteger type, Expr par } else if (that instanceof CInteger) { if (that.width() < type.width()) { if (that instanceof Signed) { - return BvExprs.SExt(cast(param, BvType.of(that.width())), - BvType.of(type.width(), false)); + return BvExprs.SExt( + cast(param, BvType.of(that.width())), BvType.of(type.width(), false)); } - return BvExprs.ZExt(cast(param, BvType.of(that.width())), BvType.of(type.width(), false)); + return BvExprs.ZExt( + cast(param, BvType.of(that.width())), BvType.of(type.width(), false)); } else if (that.width() > type.width()) { - return BvExprs.Extract(cast(param, BvType.of(that.width())), Int(0), - Int(type.width())); + return BvExprs.Extract( + cast(param, BvType.of(that.width())), Int(0), Int(type.width())); } else { // width equals if (that instanceof Signed) { - return BvSignChangeExpr.of((Expr) param, BvType.of(((BvType) param.getType()).getSize(), false)); + return BvSignChangeExpr.of( + (Expr) param, + BvType.of(((BvType) param.getType()).getSize(), false)); } else { return param; } } } else { - throw new UnsupportedFrontendElementException("Compound types are not directly supported!"); + throw new UnsupportedFrontendElementException( + "Compound types are not directly supported!"); } } @@ -129,19 +135,21 @@ private Expr handleFp(CReal type, Expr param) { if (that instanceof CReal) { FpType fpType = (FpType) type.getSmtType(); //noinspection unchecked - return ToFp(FpRoundingMode.RTZ, (Expr) param, fpType.getExponent(), + return ToFp( + FpRoundingMode.RTZ, + (Expr) param, + fpType.getExponent(), fpType.getSignificand()); } else if (that instanceof CInteger) { boolean signed = that instanceof Signed; //noinspection unchecked - return FromBv(FpRoundingMode.RTZ, (Expr) param, (FpType) type.getSmtType(), - signed); + return FromBv( + FpRoundingMode.RTZ, (Expr) param, (FpType) type.getSmtType(), signed); } else { throw new UnsupportedOperationException("Bad type!"); } } - @Override public Expr visit(CSignedShort type, Expr param) { return handleSignedConversion(type, param); @@ -190,7 +198,6 @@ public Expr visit(CSignedLong type, Expr param) { @Override public Expr visit(CSignedInt type, Expr param) { return handleSignedConversion(type, param); - } @Override @@ -234,7 +241,6 @@ public Expr visit(CFloat type, Expr param) { return param.withOps(param.getOps()); } return handleFp(type, param); - } @Override @@ -244,6 +250,5 @@ public Expr visit(CLongDouble type, Expr param) { return param.withOps(param.getOps()); } return handleFp(type, param); - } } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/LimitVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/LimitVisitor.java index da5b813c12..687ccbcb93 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/LimitVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/LimitVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector; +import static hu.bme.mit.theta.core.stmt.Stmts.Assume; + import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; -import static hu.bme.mit.theta.core.stmt.Stmts.Assume; - public class LimitVisitor extends CComplexType.CComplexTypeVisitor, AssumeStmt> { public static final LimitVisitor instance = new LimitVisitor(); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/NullValueVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/NullValueVisitor.java index ad3983d643..5a12728c36 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/NullValueVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/NullValueVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector; import hu.bme.mit.theta.core.type.LitExpr; @@ -27,11 +26,10 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CDouble; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CFloat; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CLongDouble; +import java.math.BigInteger; import org.kframework.mpfr.BigFloat; import org.kframework.mpfr.BinaryMathContext; -import java.math.BigInteger; - public class NullValueVisitor extends CComplexType.CComplexTypeVisitor> { private final ParseContext parseContext; @@ -86,5 +84,4 @@ public LitExpr visit(CInteger type, Void param) { return BvUtils.bigIntegerToUnsignedBvLitExpr(BigInteger.ZERO, type.width()); } } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/TypeVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/TypeVisitor.java index 5017a20cbf..135fd2a958 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/TypeVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/TypeVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector; import hu.bme.mit.theta.core.type.Type; @@ -65,5 +64,4 @@ public Type visit(CInteger type, Void param) { public Type visit(CVoid type, Void param) { return BvType.of(1, false); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/UnitValueVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/UnitValueVisitor.java index a8b9384329..0caa3016c5 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/UnitValueVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/UnitValueVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector; import hu.bme.mit.theta.core.type.LitExpr; @@ -27,11 +26,10 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CDouble; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CFloat; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CLongDouble; +import java.math.BigInteger; import org.kframework.mpfr.BigFloat; import org.kframework.mpfr.BinaryMathContext; -import java.math.BigInteger; - public class UnitValueVisitor extends CComplexType.CComplexTypeVisitor> { private final ParseContext parseContext; diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/ValueVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/ValueVisitor.java index 6b48e08fec..9191e99803 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/ValueVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/bitvector/ValueVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.bitvector; import hu.bme.mit.theta.core.type.LitExpr; @@ -27,11 +26,10 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CDouble; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CFloat; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CLongDouble; +import java.math.BigInteger; import org.kframework.mpfr.BigFloat; import org.kframework.mpfr.BinaryMathContext; -import java.math.BigInteger; - public class ValueVisitor extends CComplexType.CComplexTypeVisitor> { private final ParseContext parseContext; @@ -86,5 +84,4 @@ public LitExpr visit(CInteger type, String param) { return BvUtils.bigIntegerToUnsignedBvLitExpr(new BigInteger(param), type.width()); } } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/CastVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/CastVisitor.java index 446f9d7439..98b50e451f 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/CastVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/CastVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add; +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.Pos; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Sub; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.anytype.IteExpr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; @@ -38,18 +46,8 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clonglong.CUnsignedLongLong; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort.CSignedShort; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort.CUnsignedShort; - import java.math.BigInteger; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add; -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.Pos; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Sub; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class CastVisitor extends CComplexType.CComplexTypeVisitor, Expr> { private final ParseContext parseContext; @@ -100,7 +98,6 @@ public Expr visit(CUnsignedShort type, Expr param) { return Mod(param, Int(upperLimit)); } - @Override public Expr visit(CSigned128 type, Expr param) { IteExpr sameSizeExpr = handleUnsignedSameSize(type, param); @@ -182,7 +179,6 @@ public Expr visit(CSignedInt type, Expr param) { return Sub(Mod(Add(param, Int(minValue)), Int(upperLimit)), Int(minValue)); } - @Override public Expr visit(CUnsignedInt type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("int"); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/LimitVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/LimitVisitor.java index dcbba49ce3..afab96acd4 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/LimitVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/LimitVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer; +import static hu.bme.mit.theta.core.stmt.Stmts.Assume; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.stmt.AssumeStmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; @@ -34,15 +39,8 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.clonglong.CUnsignedLongLong; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort.CSignedShort; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.cshort.CUnsignedShort; - import java.math.BigInteger; -import static hu.bme.mit.theta.core.stmt.Stmts.Assume; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class LimitVisitor extends CComplexType.CComplexTypeVisitor, AssumeStmt> { private final ParseContext parseContext; @@ -50,116 +48,125 @@ public LimitVisitor(ParseContext parseContext) { this.parseContext = parseContext; } - @Override public AssumeStmt visit(CSignedShort type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("short"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CUnsignedShort type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("short"); - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(0)), + Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(Fitsall type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("fitsall"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CSigned128 type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("__int128"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CUnsigned128 type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("__int128"); - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(0)), + Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); } - @Override public AssumeStmt visit(CSignedLongLong type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("longlong"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CUnsignedLongLong type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("longlong"); - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(0)), + Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CUnsignedLong type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("long"); - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(0)), + Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CSignedLong type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("long"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CSignedInt type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("int"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CUnsignedInt type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("int"); - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(0)), + Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CSignedChar type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("char"); - return Assume(And( - Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), - Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(BigInteger.TWO.pow(width - 1).negate())), + Leq(param, Int(BigInteger.TWO.pow(width - 1).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CUnsignedChar type, Expr param) { int width = parseContext.getArchitecture().getBitWidth("char"); - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); + return Assume( + And( + Geq(param, Int(0)), + Leq(param, Int(BigInteger.TWO.pow(width).subtract(BigInteger.ONE))))); } @Override public AssumeStmt visit(CBool type, Expr param) { - return Assume(And( - Geq(param, Int(0)), - Leq(param, Int(1)))); + return Assume(And(Geq(param, Int(0)), Leq(param, Int(1)))); } } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/NullValueVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/NullValueVisitor.java index 9cffcc3ab6..3887c072ad 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/NullValueVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/NullValueVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.CInteger; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class NullValueVisitor extends CComplexType.CComplexTypeVisitor> { public static final NullValueVisitor instance = new NullValueVisitor(); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/TypeVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/TypeVisitor.java index 18a2165f3a..c228150ebc 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/TypeVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/TypeVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.type.Type; 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.integer.CInteger; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class TypeVisitor extends CComplexType.CComplexTypeVisitor { public static final TypeVisitor instance = new TypeVisitor(); @@ -36,5 +35,4 @@ public Type visit(CInteger type, Void param) { public Type visit(CVoid type, Void param) { return Int(); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/UnitValueVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/UnitValueVisitor.java index 6a5369a8e1..9ac25860b8 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/UnitValueVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/UnitValueVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.CInteger; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class UnitValueVisitor extends CComplexType.CComplexTypeVisitor> { public static final UnitValueVisitor instance = new UnitValueVisitor(); @@ -30,5 +29,4 @@ public class UnitValueVisitor extends CComplexType.CComplexTypeVisitor visit(CInteger type, Void param) { return Int(1); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/ValueVisitor.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/ValueVisitor.java index 411dd16746..fb9daaabfe 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/ValueVisitor.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/complex/visitors/integer/ValueVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,17 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.complex.visitors.integer; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; import hu.bme.mit.theta.frontend.transformation.model.types.complex.integer.CInteger; - import java.math.BigInteger; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class ValueVisitor extends CComplexType.CComplexTypeVisitor> { public static final ValueVisitor instance = new ValueVisitor(); @@ -32,5 +30,4 @@ public class ValueVisitor extends CComplexType.CComplexTypeVisitor visit(CInteger type, String param) { return Int(new BigInteger(param)); } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Atomic.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Atomic.java index a6e4a87891..415618d46c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Atomic.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Atomic.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class Atomic extends CSimpleType { - public final static Atomic instance = new Atomic(); + public static final Atomic instance = new Atomic(); - private Atomic() { - } + private Atomic() {} @Override public CSimpleType copyOf() { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleType.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleType.java index 7dba2397ab..f2bfedcc7c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleType.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; import hu.bme.mit.theta.frontend.transformation.model.types.complex.CComplexType; - import java.util.List; /** @@ -68,8 +66,8 @@ public boolean isBool() { public void setBool(boolean bool) { if (bool) { - setSigned( - false); // _Bool isn't signed, but signed might be the default value in some cases + setSigned(false); // _Bool isn't signed, but signed might be the default value in some + // cases } this.bool = bool; } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleTypeFactory.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleTypeFactory.java index d31a7861a6..b1816e8c8c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleTypeFactory.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/CSimpleTypeFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.frontend.ParseContext; - import java.util.Map; import java.util.Optional; @@ -49,7 +47,8 @@ public static Typedef Typedef() { return Typedef.instance; } - public static NamedType NamedType(final String namedType, ParseContext parseContext, Logger uniqueWarningLogger) { + public static NamedType NamedType( + final String namedType, ParseContext parseContext, Logger uniqueWarningLogger) { return new NamedType(parseContext, namedType, uniqueWarningLogger); } @@ -61,7 +60,8 @@ public static Enum Enum(final String id, final Map>> fi return new Enum(id, fields); } - public static Struct Struct(final String name, ParseContext parseContext, Logger uniqueWarningLogger) { + public static Struct Struct( + final String name, ParseContext parseContext, Logger uniqueWarningLogger) { return new Struct(name, parseContext, uniqueWarningLogger); } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/DeclaredName.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/DeclaredName.java index aaa5a13970..f682b44535 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/DeclaredName.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/DeclaredName.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class DeclaredName extends CSimpleType { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Enum.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Enum.java index aa8f4e1856..630297fa1c 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Enum.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Enum.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; import hu.bme.mit.theta.core.type.Expr; - import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; @@ -61,5 +59,4 @@ public CSimpleType copyOf() { setUpCopy(declaredNameRet); return declaredNameRet; } - } diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Extern.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Extern.java index b7df17ce87..c5c31da92d 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Extern.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Extern.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class Extern extends CSimpleType { - public final static Extern instance = new Extern(); + public static final Extern instance = new Extern(); - private Extern() { - } + private Extern() {} @Override public CSimpleType copyOf() { @@ -30,7 +28,6 @@ public CSimpleType copyOf() { return declaredNameRet; } - @Override protected void patch(CSimpleType cSimpleType) { cSimpleType.setExtern(true); 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 2ff2c5fdb0..eb5a747c44 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; import hu.bme.mit.theta.common.logging.Logger; @@ -40,9 +39,7 @@ import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CFloat; import hu.bme.mit.theta.frontend.transformation.model.types.complex.real.CLongDouble; -/** - * This type either represents a built-in type like int or float, or a typedef'd named type. - */ +/** This type either represents a built-in type like int or float, or a typedef'd named type. */ public class NamedType extends CSimpleType { protected final ParseContext parseContext; @@ -108,11 +105,13 @@ public CComplexType getActualType() { case "void": type = new CVoid(this, parseContext); break; - default: { - uniqueWarningLogger.write(Level.INFO, "WARNING: Unknown simple type " + namedType + "\n"); - type = new CVoid(this, parseContext); - break; - } + default: + { + uniqueWarningLogger.write( + Level.INFO, "WARNING: Unknown simple type " + namedType + "\n"); + type = new CVoid(this, parseContext); + break; + } } if (isThreadLocal()) { type.setThreadLocal(); @@ -124,23 +123,23 @@ public CComplexType getActualType() { return type; } -// public static NamedType getIntType() { -// NamedType namedType = new NamedType(parseContext, "int"); -// namedType.setSigned(true); -// return namedType; -// } -// -// public static NamedType getUnsignedIntType() { -// NamedType namedType = new NamedType(parseContext, "int"); -// namedType.setSigned(false); -// return namedType; -// } -// -// public static NamedType getBoolType() { -// NamedType namedType = new NamedType(parseContext, "_Bool"); -// namedType.setSigned(false); -// return namedType; -// } + // public static NamedType getIntType() { + // NamedType namedType = new NamedType(parseContext, "int"); + // namedType.setSigned(true); + // return namedType; + // } + // + // public static NamedType getUnsignedIntType() { + // NamedType namedType = new NamedType(parseContext, "int"); + // namedType.setSigned(false); + // return namedType; + // } + // + // public static NamedType getBoolType() { + // NamedType namedType = new NamedType(parseContext, "_Bool"); + // namedType.setSigned(false); + // return namedType; + // } public String getNamedType() { return namedType; @@ -247,4 +246,3 @@ public CSimpleType copyOf() { return namedType; } } - diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Signed.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Signed.java index 5fe53c0021..debd32e6d2 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Signed.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Signed.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class Signed extends CSimpleType { - public final static Signed instance = new Signed(); + public static final Signed instance = new Signed(); - private Signed() { - } + private Signed() {} @Override public CSimpleType copyOf() { 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 a7b55db04d..ec152ff990 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.common.logging.Logger.Level; @@ -24,14 +25,11 @@ 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; import java.util.LinkedHashMap; 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; @@ -63,12 +61,14 @@ public void addField(CDeclaration decl) { @Override public CComplexType getActualType() { if (currentlyBeingBuilt) { - uniqueWarningLogger.write(Level.INFO, "WARNING: self-embedded structs! Using long as a placeholder\n"); + uniqueWarningLogger.write( + Level.INFO, "WARNING: self-embedded structs! Using long as a placeholder\n"); return CComplexType.getSignedInt(parseContext); } currentlyBeingBuilt = true; List> actualFields = new ArrayList<>(); - fields.forEach((s, cDeclaration) -> actualFields.add(Tuple2.of(s, cDeclaration.getActualType()))); + fields.forEach( + (s, cDeclaration) -> actualFields.add(Tuple2.of(s, cDeclaration.getActualType()))); currentlyBeingBuilt = false; CComplexType type = new CStruct(this, actualFields, parseContext); @@ -97,6 +97,4 @@ public CSimpleType copyOf() { setUpCopy(struct); return struct; } - } - diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/ThreadLocal.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/ThreadLocal.java index 937d3b5cb6..b07ed7e2f8 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/ThreadLocal.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/ThreadLocal.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class ThreadLocal extends CSimpleType { - public final static ThreadLocal instance = new ThreadLocal(); + public static final ThreadLocal instance = new ThreadLocal(); - private ThreadLocal() { - } + private ThreadLocal() {} @Override public CSimpleType copyOf() { diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Typedef.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Typedef.java index 0f2c5fece9..f6e9017085 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Typedef.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Typedef.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class Typedef extends CSimpleType { - public final static Typedef instance = new Typedef(); + public static final Typedef instance = new Typedef(); - private Typedef() { - } + private Typedef() {} @Override public CSimpleType copyOf() { @@ -30,7 +28,6 @@ public CSimpleType copyOf() { return declaredNameRet; } - @Override protected void patch(CSimpleType cSimpleType) { cSimpleType.setTypedef(true); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Unsigned.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Unsigned.java index 809ad939e8..b21d6d611b 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Unsigned.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Unsigned.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class Unsigned extends CSimpleType { - public final static Unsigned instance = new Unsigned(); + public static final Unsigned instance = new Unsigned(); - private Unsigned() { - } + private Unsigned() {} @Override public CSimpleType copyOf() { @@ -30,7 +28,6 @@ public CSimpleType copyOf() { return declaredNameRet; } - @Override protected void patch(CSimpleType cSimpleType) { cSimpleType.setSigned(false); diff --git a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Volatile.java b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Volatile.java index b5cc1d8f64..5407813b99 100644 --- a/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Volatile.java +++ b/subprojects/frontends/c-frontend/src/main/java/hu/bme/mit/theta/frontend/transformation/model/types/simple/Volatile.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,15 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.transformation.model.types.simple; public class Volatile extends CSimpleType { - public final static Volatile instance = new Volatile(); + public static final Volatile instance = new Volatile(); - private Volatile() { - } + private Volatile() {} @Override public CSimpleType copyOf() { @@ -30,7 +28,6 @@ public CSimpleType copyOf() { return declaredNameRet; } - @Override protected void patch(CSimpleType cSimpleType) { cSimpleType.setVolatile(true); diff --git a/subprojects/frontends/chc-frontend/build.gradle.kts b/subprojects/frontends/chc-frontend/build.gradle.kts index 7fc271dd2a..51d4f9be7d 100644 --- a/subprojects/frontends/chc-frontend/build.gradle.kts +++ b/subprojects/frontends/chc-frontend/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcBackwardXcfaBuilder.java b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcBackwardXcfaBuilder.java index 9457748898..5138d427ab 100644 --- a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcBackwardXcfaBuilder.java +++ b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcBackwardXcfaBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcForwardXcfaBuilder.java b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcForwardXcfaBuilder.java index 84f38db5b0..86647a10b2 100644 --- a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcForwardXcfaBuilder.java +++ b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcForwardXcfaBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcFrontend.java b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcFrontend.java index f225ad3715..eb0cdba939 100644 --- a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcFrontend.java +++ b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcFrontend.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -41,13 +41,14 @@ public XcfaBuilder buildXcfa(CharStream charStream, ProcedurePassManager procedu ChcUtils.init(charStream); CHCParser parser = new CHCParser(new CommonTokenStream(new CHCLexer(charStream))); parser.setErrorHandler(new BailErrorStrategy()); - ChcXcfaBuilder chcXcfaBuilder = switch (chcTransformation) { - case FORWARD -> new ChcForwardXcfaBuilder(procedurePassManager); - case BACKWARD -> new ChcBackwardXcfaBuilder(procedurePassManager); - default -> - throw new RuntimeException("Should not be here; adapt PORTFOLIO to FW/BW beforehand."); - }; + ChcXcfaBuilder chcXcfaBuilder = + switch (chcTransformation) { + case FORWARD -> new ChcForwardXcfaBuilder(procedurePassManager); + case BACKWARD -> new ChcBackwardXcfaBuilder(procedurePassManager); + default -> + throw new RuntimeException( + "Should not be here; adapt PORTFOLIO to FW/BW beforehand."); + }; return chcXcfaBuilder.buildXcfa(parser); } } - diff --git a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcUtils.java b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcUtils.java index 307d6af069..207ee21a48 100644 --- a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcUtils.java +++ b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,13 @@ */ package hu.bme.mit.theta.frontend.chc; +import static com.google.common.base.Preconditions.checkArgument; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.xcfa.passes.UtilsKt.changeVars; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.chc.frontend.dsl.gen.CHCParser; import hu.bme.mit.theta.common.Tuple2; @@ -35,37 +42,28 @@ import hu.bme.mit.theta.solver.smtlib.solver.model.SmtLibModel; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTypeTransformer; -import hu.bme.mit.theta.xcfa.model.EmptyMetaData; import hu.bme.mit.theta.xcfa.model.StmtLabel; import hu.bme.mit.theta.xcfa.model.XcfaLabel; import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.misc.Interval; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - -import static com.google.common.base.Preconditions.checkArgument; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.xcfa.passes.UtilsKt.changeVars; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; public class ChcUtils { // TODO eliminate static fields (re-runs?) private static GenericSmtLibSymbolTable initialSymbolTable = new GenericSmtLibSymbolTable(); private static GenericSmtLibSymbolTable symbolTable; private static SmtLibTypeTransformer typeTransformer = new GenericSmtLibTypeTransformer(null); - private static SmtLibTermTransformer termTransformer = new GenericSmtLibTermTransformer(initialSymbolTable); + private static SmtLibTermTransformer termTransformer = + new GenericSmtLibTermTransformer(initialSymbolTable); private static CharStream charStream; - private ChcUtils() { - } + private ChcUtils() {} public static void init(CharStream cs) { initialSymbolTable = new GenericSmtLibSymbolTable(); @@ -74,21 +72,28 @@ public static void init(CharStream cs) { charStream = cs; } - public static List getTailConditionLabels(CHCParser.Chc_tailContext tail, Map> localVars) { + public static List getTailConditionLabels( + CHCParser.Chc_tailContext tail, Map> localVars) { List labels = new ArrayList<>(); - tail.i_formula().forEach(i_formula -> { // null as SmtLibModel, because it is unused - Expr expr = termTransformer.toExpr(getOriginalText(i_formula), Bool(), new SmtLibModel(Collections.emptyMap())); - List> exprVars = new ArrayList<>(); - ExprUtils.collectConstants(expr, exprVars); - Map, VarDecl> varsToLocal = new HashMap<>(); - for (Decl var : exprVars) { - if (localVars.containsKey(var.getName())) { - varsToLocal.put(var, localVars.get(var.getName())); - } - } - Expr replacedExpr = changeVars(expr, varsToLocal); - labels.add(new StmtLabel(AssumeStmt.of(replacedExpr))); - }); + tail.i_formula() + .forEach( + i_formula -> { // null as SmtLibModel, because it is unused + Expr expr = + termTransformer.toExpr( + getOriginalText(i_formula), + Bool(), + new SmtLibModel(Collections.emptyMap())); + List> exprVars = new ArrayList<>(); + ExprUtils.collectConstants(expr, exprVars); + Map, VarDecl> varsToLocal = new HashMap<>(); + for (Decl var : exprVars) { + if (localVars.containsKey(var.getName())) { + varsToLocal.put(var, localVars.get(var.getName())); + } + } + Expr replacedExpr = changeVars(expr, varsToLocal); + labels.add(new StmtLabel(AssumeStmt.of(replacedExpr))); + }); return labels; } @@ -96,7 +101,8 @@ public static String getOriginalText(ParserRuleContext ctx) { return charStream.getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } - public static Map> createVars(XcfaProcedureBuilder builder, List var_decls) { + public static Map> createVars( + XcfaProcedureBuilder builder, List var_decls) { resetSymbolTable(); Map> vars = new HashMap<>(); for (CHCParser.Var_declContext var_decl : var_decls) { @@ -114,7 +120,6 @@ public static Map> createVars(XcfaProcedureBuilder builder, L public static void resetSymbolTable() { symbolTable = new GenericSmtLibSymbolTable(initialSymbolTable); termTransformer = new GenericSmtLibTermTransformer(symbolTable); - } public static Type transformSort(final CHCParser.SortContext ctx) { @@ -145,14 +150,14 @@ public static void transformConst(final ConstDecl decl, boolean initial) { final Type returnType = extractedTypes.get2(); final String returnSort = typeTransformer.toSort(returnType); - final String[] paramSorts = paramTypes.stream().map(typeTransformer::toSort) - .toArray(String[]::new); + final String[] paramSorts = + paramTypes.stream().map(typeTransformer::toSort).toArray(String[]::new); final String symbolName = decl.getName(); - final String symbolDeclaration = String.format( - "(declare-fun %s (%s) %s)", - symbolName, String.join(" ", paramSorts), returnSort - ); + final String symbolDeclaration = + String.format( + "(declare-fun %s (%s) %s)", + symbolName, String.join(" ", paramSorts), returnSort); (initial ? initialSymbolTable : symbolTable).put(decl, symbolName, symbolDeclaration); } @@ -168,7 +173,8 @@ public static Tuple2, Type> extractTypes(final Type type) { final Tuple2, Type> subResult = extractTypes(resultType); final List paramTypes = subResult.get1(); final Type newResultType = subResult.get2(); - final List newParamTypes = ImmutableList.builder().add(paramType).addAll(paramTypes).build(); + final List newParamTypes = + ImmutableList.builder().add(paramType).addAll(paramTypes).build(); final Tuple2, Type> result = Tuple2.of(newParamTypes, newResultType); return result; diff --git a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcXcfaBuilder.java b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcXcfaBuilder.java index 9125073a1e..f86f1f9e24 100644 --- a/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcXcfaBuilder.java +++ b/subprojects/frontends/chc-frontend/src/main/java/hu/bme/mit/theta/frontend/chc/ChcXcfaBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,7 +16,6 @@ package hu.bme.mit.theta.frontend.chc; import hu.bme.mit.theta.chc.frontend.dsl.gen.CHCParser; -import hu.bme.mit.theta.xcfa.model.XCFA; import hu.bme.mit.theta.xcfa.model.XcfaBuilder; public interface ChcXcfaBuilder { diff --git a/subprojects/frontends/llvm/build.gradle.kts b/subprojects/frontends/llvm/build.gradle.kts index 2d93c23af0..ed2fc924be 100644 --- a/subprojects/frontends/llvm/build.gradle.kts +++ b/subprojects/frontends/llvm/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/build.gradle.kts b/subprojects/frontends/petrinet-frontend/petrinet-analysis/build.gradle.kts index e81d02f70c..131355f995 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/build.gradle.kts +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,4 +26,4 @@ dependencies { implementation(project(":theta-common")) implementation(project(":theta-analysis")) implementation(project(":theta-petrinet-model")) -} \ No newline at end of file +} diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/ModelProperties.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/ModelProperties.java index 21cf7ccff1..07c05db0d9 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/ModelProperties.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/ModelProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,13 +16,20 @@ package hu.bme.mit.theta.frontend.petrinet.analysis; import hu.bme.mit.theta.common.table.TableWriter; - import java.util.Arrays; public final class ModelProperties { - private static final String[] headers = new String[]{"id", "Name", "Type", "#Place", "#Transition", "#Arc", - "HasReadOnlyEffect", - "HasReadOnlyEffectOnTop"}; + private static final String[] headers = + new String[] { + "id", + "Name", + "Type", + "#Place", + "#Transition", + "#Arc", + "HasReadOnlyEffect", + "HasReadOnlyEffectOnTop" + }; private final PtNetSystem model; private final String id; diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetDependency2Gxl.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetDependency2Gxl.java index 1df02156e0..c3e14f0909 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetDependency2Gxl.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetDependency2Gxl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,7 +18,6 @@ import com.koloboke.collect.set.hash.HashObjSets; import hu.bme.mit.theta.frontend.petrinet.model.Place; import hu.bme.mit.theta.frontend.petrinet.model.Transition; - import java.util.Map; import java.util.Objects; import java.util.Set; @@ -99,7 +98,8 @@ private String getId() { } public static String toGxl(PtNetSystem system, final boolean omitReadOnly) { - final Map> depMat = system.getDependencyMatrix(); + final Map> depMat = + system.getDependencyMatrix(); Set nodes = HashObjSets.newUpdatableSet(); Set edges = HashObjSets.newUpdatableSet(); @@ -118,13 +118,14 @@ public static String toGxl(PtNetSystem system, final boolean omitReadOnly) { } // } - for (Map.Entry> t : depMat.entrySet()) { + for (Map.Entry> t : + depMat.entrySet()) { Set inPlaces = HashObjSets.newUpdatableSet(); Set outPlaces = HashObjSets.newUpdatableSet(); - //Set readOnlyPlaces = HashObjSets.newUpdatableSet(); + // Set readOnlyPlaces = HashObjSets.newUpdatableSet(); for (Map.Entry e : t.getValue().entrySet()) { if (e.getValue().takes == e.getValue().puts) { - //readOnlyPlaces.add(e.getKey()); + // readOnlyPlaces.add(e.getKey()); if (omitReadOnly) { continue; } @@ -161,8 +162,7 @@ public static String toGxl(PtNetSystem system, final boolean omitReadOnly) { } private static String serializeGxl( - final String name, final Set nodes, final Set edges - ) { + final String name, final Set nodes, final Set edges) { StringBuilder sb = new StringBuilder(); sb.append("\n"); sb.append("\n"); @@ -173,16 +173,17 @@ private static String serializeGxl( for (DepEdge edge : edges) { // if (edge.weight == 1) { - sb.append("\n"); + sb.append( + "\n"); // } else { // sb.append(" getValuations(final StateSpaceInfo localStateSpace) { + public IntObjMapView getValuations( + final StateSpaceInfo localStateSpace) { if (assignedPlace == localStateSpace.getTraceInfo()) { return IntObjMapView.singleton(initialMarking, continuation); } else { diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetSystem.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetSystem.java index 4b53d5c82d..eaee7841cd 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetSystem.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,7 +25,6 @@ import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.impl.OrNextStateDescriptor; import hu.bme.mit.theta.frontend.petrinet.model.*; - import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; @@ -35,7 +34,8 @@ public final class PtNetSystem { public static class TransitionEffect { - public static final TransitionEffect INDEPENDENT = new TransitionEffect(0, Integer.MAX_VALUE, 0); + public static final TransitionEffect INDEPENDENT = + new TransitionEffect(0, Integer.MAX_VALUE, 0); public final int takes; public final int inhibits; @@ -73,7 +73,8 @@ public String toString() { private PetriNet petriNet; private final List placeOrdering; - private Map> dependencyMatrix = HashObjObjMaps.newUpdatableMap(); + private Map> dependencyMatrix = + HashObjObjMaps.newUpdatableMap(); private ObjIntMap transitionTop = HashObjIntMaps.newUpdatableMap(); boolean hasReadOnlyEffect = false; boolean hasReadOnlyEffectOnTop = false; @@ -101,15 +102,17 @@ public PtNetSystem(final PetriNet petriNet, List placeOrdering) { } private AbstractNextStateDescriptor.Postcondition createInitializer() { - PtNetInitializer current = new PtNetInitializer(placeOrdering.get(0), - Math.toIntExact(placeOrdering.get(0).getInitialMarking()), - AbstractNextStateDescriptor.terminalIdentity() - ); + PtNetInitializer current = + new PtNetInitializer( + placeOrdering.get(0), + Math.toIntExact(placeOrdering.get(0).getInitialMarking()), + AbstractNextStateDescriptor.terminalIdentity()); for (int i = 1; i < placeOrdering.size(); ++i) { - current = new PtNetInitializer(placeOrdering.get(i), - Math.toIntExact(placeOrdering.get(i).getInitialMarking()), - current - ); + current = + new PtNetInitializer( + placeOrdering.get(i), + Math.toIntExact(placeOrdering.get(i).getInitialMarking()), + current); } return current; } @@ -124,8 +127,7 @@ private AbstractNextStateDescriptor createTransitions() { } private AbstractNextStateDescriptor createTransition( - final Transition t, final UniqueTable uniqueTable - ) { + final Transition t, final UniqueTable uniqueTable) { ObjIntMap takes = HashObjIntMaps.newUpdatableMap(t.getIncomingArcs().size()); ObjIntMap puts = HashObjIntMaps.newUpdatableMap(t.getOutgoingArcs().size()); ObjIntMap inhibits = HashObjIntMaps.newUpdatableMap(); @@ -141,7 +143,8 @@ private AbstractNextStateDescriptor createTransition( puts.put(arc.getTarget(), Math.toIntExact(arc.getWeight())); } - final HashObjObjMap transitionDependecies = HashObjObjMaps.newUpdatableMap(); + final HashObjObjMap transitionDependecies = + HashObjObjMaps.newUpdatableMap(); boolean readOnlyOnTop = false; @@ -163,13 +166,15 @@ private AbstractNextStateDescriptor createTransition( readOnlyOnTop = false; } - current = uniqueTable.checkIn(new PtNetTransitionNextStateDescriptor(t, - placeOrdering.get(i), - nTakes, - nInhibits, - nPuts, - current - )); + current = + uniqueTable.checkIn( + new PtNetTransitionNextStateDescriptor( + t, + placeOrdering.get(i), + nTakes, + nInhibits, + nPuts, + current)); } } @@ -206,15 +211,19 @@ public String printDependencyMatrixCsv() { for (Place p : placeOrdering) { sb2.append(';'); - sb2.append(dependencyMatrix.getOrDefault(t, Map.of()) - .getOrDefault(p, TransitionEffect.INDEPENDENT) - .toString()); + sb2.append( + dependencyMatrix + .getOrDefault(t, Map.of()) + .getOrDefault(p, TransitionEffect.INDEPENDENT) + .toString()); } sb2.append('\n'); transitionLines.add(sb2.toString()); } - transitionLines.sort((a, b) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(a), reverseString(b))); + transitionLines.sort( + (a, b) -> + String.CASE_INSENSITIVE_ORDER.compare(reverseString(a), reverseString(b))); for (String line : transitionLines) { sb.append(line); @@ -230,7 +239,8 @@ public static String reverseString(String str) { } public BufferedImage dependencyMatrixImage(final int blockWidth) { - int width = placeOrdering.size() * blockWidth, height = petriNet.getTransitions().size() * blockWidth; + int width = placeOrdering.size() * blockWidth, + height = petriNet.getTransitions().size() * blockWidth; // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed // into integer pixels @@ -245,9 +255,10 @@ public BufferedImage dependencyMatrixImage(final int blockWidth) { for (int x = 0; x < placeOrdering.size(); x++) { final Place p = placeOrdering.get(x); - final TransitionEffect effect = dependencyMatrix.getOrDefault(t, Map.of()).getOrDefault(p, - TransitionEffect.INDEPENDENT - ); + final TransitionEffect effect = + dependencyMatrix + .getOrDefault(t, Map.of()) + .getOrDefault(p, TransitionEffect.INDEPENDENT); if (effect.writes()) { graphics.setPaint(Color.RED); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetTransitionNextStateDescriptor.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetTransitionNextStateDescriptor.java index f58192dfa8..acc2b1a3a1 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetTransitionNextStateDescriptor.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/PtNetTransitionNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,10 +21,8 @@ import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.StateSpaceInfo; import hu.bme.mit.theta.frontend.petrinet.model.Place; import hu.bme.mit.theta.frontend.petrinet.model.Transition; - import java.util.NoSuchElementException; - public final class PtNetTransitionNextStateDescriptor implements AbstractNextStateDescriptor { private Transition representedTransition; private Place affectedPlace; @@ -40,8 +38,7 @@ public PtNetTransitionNextStateDescriptor( final int takes, final int inhibits, final int puts, - final AbstractNextStateDescriptor continuation - ) { + final AbstractNextStateDescriptor continuation) { this.representedTransition = representedTransition; this.affectedPlace = affectedPlace; this.takes = takes; @@ -51,7 +48,8 @@ public PtNetTransitionNextStateDescriptor( } @Override - public IntObjMapView getDiagonal(final StateSpaceInfo localStateSpace) { + public IntObjMapView getDiagonal( + final StateSpaceInfo localStateSpace) { if (localStateSpace.getTraceInfo() == affectedPlace) { return new IntObjMapView() { @Override @@ -123,7 +121,8 @@ public int size() { } @Override - public IntObjMapView> getOffDiagonal(final StateSpaceInfo localStateSpace) { + public IntObjMapView> getOffDiagonal( + final StateSpaceInfo localStateSpace) { if (localStateSpace.getTraceInfo() == affectedPlace) { return new IntObjMapView>() { @Override @@ -252,7 +251,8 @@ public int size() { } }; } else { - return IntObjMapView.empty(IntObjMapView.empty(AbstractNextStateDescriptor.terminalEmpty())); + return IntObjMapView.empty( + IntObjMapView.empty(AbstractNextStateDescriptor.terminalEmpty())); } } @@ -266,9 +266,12 @@ public boolean equals(final Object o) { if (takes != that.takes) return false; if (inhibits != that.inhibits) return false; if (puts != that.puts) return false; - if (affectedPlace != null ? !affectedPlace.equals(that.affectedPlace) : that.affectedPlace != null) - return false; - return continuation != null ? continuation.equals(that.continuation) : that.continuation == null; + if (affectedPlace != null + ? !affectedPlace.equals(that.affectedPlace) + : that.affectedPlace != null) return false; + return continuation != null + ? continuation.equals(that.continuation) + : that.continuation == null; } @Override diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/VariableOrderingFactory.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/VariableOrderingFactory.java index 15b1608336..5c05513bdb 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/VariableOrderingFactory.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/main/java/hu/bme/mit/theta/frontend/petrinet/analysis/VariableOrderingFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import hu.bme.mit.theta.frontend.petrinet.model.Identified; import hu.bme.mit.theta.frontend.petrinet.model.PetriNet; import hu.bme.mit.theta.frontend.petrinet.model.Place; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -29,7 +28,8 @@ import java.util.stream.Collectors; public final class VariableOrderingFactory { - public static List fromPathString(String orderingPath, PetriNet petriNet) throws Exception { + public static List fromPathString(String orderingPath, PetriNet petriNet) + throws Exception { final File orderingFile = new File(orderingPath); if (!orderingFile.exists()) { throw new IOException("Cannot open ordering file: " + orderingPath); @@ -43,10 +43,10 @@ public static List fromFile(File orderingFile, PetriNet petriNet) throws if (orderingIds.size() != petriNet.getPlaces().size()) { throw new Exception("The ordering does not match the net: different number of entries"); } - Map placeIdMap = HashObjObjMaps.newImmutableMap(petriNet - .getPlaces() - .stream() - .collect(Collectors.toMap(Identified::getId, p -> p))); + Map placeIdMap = + HashObjObjMaps.newImmutableMap( + petriNet.getPlaces().stream() + .collect(Collectors.toMap(Identified::getId, p -> p))); final List ordering = new ArrayList<>(orderingIds.size()); for (String s : orderingIds) { Place p = placeIdMap.get(s); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/BfsTest.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/BfsTest.java index 2a89944cd9..5b73ecdb9f 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/BfsTest.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/BfsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.frontend.petrinet.analysis; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.delta.java.mdd.GraphvizSerializer; import hu.bme.mit.delta.java.mdd.JavaMddFactory; import hu.bme.mit.delta.java.mdd.MddHandle; @@ -27,12 +29,9 @@ import hu.bme.mit.theta.frontend.petrinet.model.PetriNet; import hu.bme.mit.theta.frontend.petrinet.model.Place; import hu.bme.mit.theta.frontend.petrinet.pnml.PetriNetParser; -import org.junit.Test; - import java.io.File; import java.util.List; - -import static org.junit.Assert.assertEquals; +import org.junit.Test; public final class BfsTest { public static String reverseString(String str) { @@ -48,9 +47,13 @@ public void testBfs() throws Exception { assertEquals(1, petriNets.size()); - final List ordering = VariableOrderingFactory.fromPathString(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0)); + final List ordering = + VariableOrderingFactory.fromPathString( + getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), + petriNets.get(0)); // ordering = new ArrayList<>(petriNets.get(0).getPlaces()); - // ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()), + // ordering.sort((p1, p2) -> + // String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()), // reverseString(p2.getId()))); PtNetSystem system = new PtNetSystem(petriNets.get(0), ordering); @@ -63,12 +66,14 @@ public void testBfs() throws Exception { variableOrder.createOnTop(MddVariableDescriptor.create(p)); } - BfsProvider bfs = new BfsProvider(variableOrder, new LegacyRelationalProductProvider(variableOrder)); + BfsProvider bfs = + new BfsProvider(variableOrder, new LegacyRelationalProductProvider(variableOrder)); - final MddHandle stateSpace = bfs.compute(system.getInitializer(), - system.getTransitions(), - variableOrder.getDefaultSetSignature().getTopVariableHandle() - ); + final MddHandle stateSpace = + bfs.compute( + system.getInitializer(), + system.getTransitions(), + variableOrder.getDefaultSetSignature().getTopVariableHandle()); System.out.println(GraphvizSerializer.serialize(stateSpace)); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/GeneralizedSaturationTest.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/GeneralizedSaturationTest.java index 8b1fb204f9..f1c6b1d5b6 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/GeneralizedSaturationTest.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/GeneralizedSaturationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.frontend.petrinet.analysis; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.delta.java.mdd.GraphvizSerializer; import hu.bme.mit.delta.java.mdd.JavaMddFactory; import hu.bme.mit.delta.java.mdd.MddHandle; @@ -27,12 +29,9 @@ import hu.bme.mit.theta.frontend.petrinet.model.PetriNet; import hu.bme.mit.theta.frontend.petrinet.model.Place; import hu.bme.mit.theta.frontend.petrinet.pnml.PetriNetParser; -import org.junit.Test; - import java.io.File; import java.util.List; - -import static org.junit.Assert.assertEquals; +import org.junit.Test; public final class GeneralizedSaturationTest { public static String reverseString(String str) { @@ -48,9 +47,13 @@ public void testGS() throws Exception { assertEquals(1, petriNets.size()); - final List ordering = VariableOrderingFactory.fromPathString(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0)); + final List ordering = + VariableOrderingFactory.fromPathString( + getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), + petriNets.get(0)); // ordering = new ArrayList<>(petriNets.get(0).getPlaces()); - // ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()), + // ordering.sort((p1, p2) -> + // String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()), // reverseString(p2.getId()))); // ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(p1.getId(), // p2.getId())); @@ -59,7 +62,7 @@ public void testGS() throws Exception { System.out.println(system.printDependencyMatrixCsv()); - //new BufferedReader(new InputStreamReader(System.in)).readLine(); + // new BufferedReader(new InputStreamReader(System.in)).readLine(); MddVariableOrder variableOrder = JavaMddFactory.getDefault().createMddVariableOrder(LatticeDefinition.forSets()); @@ -67,20 +70,22 @@ public void testGS() throws Exception { variableOrder.createOnTop(MddVariableDescriptor.create(p)); } - GeneralizedSaturationProvider gs = new GeneralizedSaturationProvider(variableOrder, - new CursorRelationalProductProvider(variableOrder)); + GeneralizedSaturationProvider gs = + new GeneralizedSaturationProvider( + variableOrder, new CursorRelationalProductProvider(variableOrder)); - final MddHandle stateSpace = gs.compute(system.getInitializer(), - system.getTransitions(), - variableOrder.getDefaultSetSignature().getTopVariableHandle() - ); + final MddHandle stateSpace = + gs.compute( + system.getInitializer(), + system.getTransitions(), + variableOrder.getDefaultSetSignature().getTopVariableHandle()); String dot = GraphvizSerializer.serialize(stateSpace); System.out.println(dot); -// StringSelection stringSelection = new StringSelection(dot); -// Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); -// clipboard.setContents(stringSelection, null); + // StringSelection stringSelection = new StringSelection(dot); + // Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + // clipboard.setContents(stringSelection, null); final Long stateSpaceSize = MddInterpreter.calculateNonzeroCount(stateSpace); assertEquals(TestData.STATESPACESIZE, stateSpaceSize.longValue()); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/RelationalProductTest.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/RelationalProductTest.java index 62d8cc61ea..8ff2a55080 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/RelationalProductTest.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/RelationalProductTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,7 +24,7 @@ import org.junit.Before; public final class RelationalProductTest { - private static final int[] tupleSignature = new int[]{0, 0, 0}; + private static final int[] tupleSignature = new int[] {0, 0, 0}; private MddGraph graph; private MddVariableOrder order; @@ -36,7 +36,9 @@ public void prepare() { graph = JavaMddFactory.getDefault().createMddGraph(LatticeDefinition.forSets()); order = JavaMddFactory.getDefault().createMddVariableOrder(graph); for (int i = 0; i < tupleSignature.length; i++) { - order.createOnTop(MddVariableDescriptor.create("x" + i, tupleSignature[tupleSignature.length - i - 1])); + order.createOnTop( + MddVariableDescriptor.create( + "x" + i, tupleSignature[tupleSignature.length - i - 1])); } signature = order.getDefaultSetSignature(); } diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/SimpleSaturationTest.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/SimpleSaturationTest.java index 491c32c286..571437bc96 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/SimpleSaturationTest.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/SimpleSaturationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.frontend.petrinet.analysis; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.delta.java.mdd.JavaMddFactory; import hu.bme.mit.delta.java.mdd.MddHandle; import hu.bme.mit.delta.java.mdd.MddVariableOrder; @@ -25,12 +27,9 @@ import hu.bme.mit.theta.frontend.petrinet.model.PetriNet; import hu.bme.mit.theta.frontend.petrinet.model.Place; import hu.bme.mit.theta.frontend.petrinet.pnml.PetriNetParser; -import org.junit.Test; - import java.io.File; import java.util.List; - -import static org.junit.Assert.assertEquals; +import org.junit.Test; public final class SimpleSaturationTest { public static String reverseString(String str) { @@ -47,19 +46,21 @@ public void testSS() throws Exception { assertEquals(1, petriNets.size()); final List ordering = - VariableOrderingFactory.fromPathString(getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), + VariableOrderingFactory.fromPathString( + getClass().getResource(TestData.ORDERINGPATH).toURI().getPath(), petriNets.get(0)); // ordering = new ArrayList<>(petriNets.get(0).getPlaces()); - // ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()), + // ordering.sort((p1, p2) -> + // String.CASE_INSENSITIVE_ORDER.compare(reverseString(p1.getId()), // reverseString(p2.getId()))); - //ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(p1.getId(), + // ordering.sort((p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(p1.getId(), // p2.getId())); PtNetSystem system = new PtNetSystem(petriNets.get(0), ordering); System.out.println(system.printDependencyMatrixCsv()); - //new BufferedReader(new InputStreamReader(System.in)).readLine(); + // new BufferedReader(new InputStreamReader(System.in)).readLine(); MddVariableOrder variableOrder = JavaMddFactory.getDefault().createMddVariableOrder(LatticeDefinition.forSets()); @@ -69,13 +70,14 @@ public void testSS() throws Exception { SimpleSaturationProvider ss = new SimpleSaturationProvider(variableOrder); - final MddHandle stateSpace = ss.compute(system.getInitializer(), - system.getTransitions(), - variableOrder.getDefaultSetSignature().getTopVariableHandle() - ); + final MddHandle stateSpace = + ss.compute( + system.getInitializer(), + system.getTransitions(), + variableOrder.getDefaultSetSignature().getTopVariableHandle()); - //String dot = GraphvizSerializer.serialize(stateSpace); - //System.out.println(dot); + // String dot = GraphvizSerializer.serialize(stateSpace); + // System.out.println(dot); System.out.println(ss.getSaturatedNodes().size()); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/TestData.java b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/TestData.java index 1fb502d870..b2054904fe 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/TestData.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-analysis/src/test/java/hu/bme/mit/theta/frontend/petrinet/analysis/TestData.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/build.gradle.kts b/subprojects/frontends/petrinet-frontend/petrinet-model/build.gradle.kts index f1e7bb33f2..d8dbfee8d7 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/build.gradle.kts +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -34,4 +34,4 @@ dependencies { implementation(project(":theta-core")) implementation(project(":theta-common")) -} \ No newline at end of file +} diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Identified.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Identified.java index d173a6fe8a..3129f36d9d 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Identified.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Identified.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PTArc.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PTArc.java index 1ccc0f58dc..0162cb9bd0 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PTArc.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PTArc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PetriNet.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PetriNet.java index 79a6c68546..b02a939834 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PetriNet.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/PetriNet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -56,6 +56,13 @@ public List getTpArcs() { @Override public String toString() { - return getId() + "(" + places.size() + " places, " + transitions.size() + " transitions, " + (ptArcs.size() + tpArcs.size()) + " arcs)"; + return getId() + + "(" + + places.size() + + " places, " + + transitions.size() + + " transitions, " + + (ptArcs.size() + tpArcs.size()) + + " arcs)"; } } diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Place.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Place.java index 82ea9dcf73..a1815ee172 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Place.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Place.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/TPArc.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/TPArc.java index fd6f7a75df..7f51182a43 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/TPArc.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/TPArc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Transition.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Transition.java index e4a05ae8d0..ec3cbba500 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Transition.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/Transition.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/utils/GraphVizSerializer.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/utils/GraphVizSerializer.java index 831b812cb6..a6ee1665bf 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/utils/GraphVizSerializer.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/model/utils/GraphVizSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,18 +23,28 @@ public static String toDot(PetriNet pn) { sb.append("digraph PN {\n"); for (Place p : pn.getPlaces()) { - sb.append("\"" + - p.getId() + - "\" [label=\"" + - p.getId() + - (p.getInitialMarking() != 0 ? "\\n(" + p.getInitialMarking() + ")" : "") + - "\"];\n"); + sb.append( + "\"" + + p.getId() + + "\" [label=\"" + + p.getId() + + (p.getInitialMarking() != 0 + ? "\\n(" + p.getInitialMarking() + ")" + : "") + + "\"];\n"); } for (Transition t : pn.getTransitions()) { sb.append("\"" + t.getId() + "\" [shape=box,label=\"" + t.getId() + "\"];\n"); } for (PTArc pt : pn.getPtArcs()) { - sb.append("\"" + pt.getSource().getId() + "\" -> \"" + pt.getTarget().getId() + "\" [label=\"" + (pt.getWeight() != 1 ? pt.getWeight() : "") + "\""); + sb.append( + "\"" + + pt.getSource().getId() + + "\" -> \"" + + pt.getTarget().getId() + + "\" [label=\"" + + (pt.getWeight() != 1 ? pt.getWeight() : "") + + "\""); if (pt.isInhibitor()) { sb.append(",arrowhead=dot"); @@ -43,7 +53,14 @@ public static String toDot(PetriNet pn) { sb.append("];\n"); } for (TPArc tp : pn.getTpArcs()) { - sb.append("\"" + tp.getSource().getId() + "\" -> \"" + tp.getTarget().getId() + "\" [label=\"" + (tp.getWeight() != 1 ? tp.getWeight() : "") + "\"];\n"); + sb.append( + "\"" + + tp.getSource().getId() + + "\" -> \"" + + tp.getTarget().getId() + + "\" [label=\"" + + (tp.getWeight() != 1 ? tp.getWeight() : "") + + "\"];\n"); } sb.append("}\n"); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/Lip6PnmlToPetrinet.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/Lip6PnmlToPetrinet.java index ee06a2e436..a932b4cc51 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/Lip6PnmlToPetrinet.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/Lip6PnmlToPetrinet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,7 +21,6 @@ import hu.bme.mit.theta.frontend.petrinet.model.PetriNet; import hu.bme.mit.theta.frontend.petrinet.model.Place; import hu.bme.mit.theta.frontend.petrinet.model.Transition; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -52,11 +51,11 @@ public List parse() throws PnmlParseException { if (object instanceof fr.lip6.move.pnml.ptnet.Place) { places.add((fr.lip6.move.pnml.ptnet.Place) object); } else if (object instanceof RefPlace) { - //refPlaces.add((RefPlace) object); + // refPlaces.add((RefPlace) object); } else if (object instanceof fr.lip6.move.pnml.ptnet.Transition) { transitions.add((fr.lip6.move.pnml.ptnet.Transition) object); } else if (object instanceof RefTransition) { - //refTransitions.add((RefTransition) object); + // refTransitions.add((RefTransition) object); } else if (object instanceof Arc) { arcs.add((Arc) object); } else { @@ -93,10 +92,14 @@ public List parse() throws PnmlParseException { PTArc arc = new PTArc(arcDOM.getId()); // TODO inhibitor?? - String sourceId = arcDOM.getSource() instanceof RefPlace ? - ((RefPlace) arcDOM.getSource()).getRef().getId() : arcDOM.getSource().getId(); - String targetId = arcDOM.getTarget() instanceof RefTransition ? - ((RefTransition) arcDOM.getTarget()).getRef().getId() : arcDOM.getTarget().getId(); + String sourceId = + arcDOM.getSource() instanceof RefPlace + ? ((RefPlace) arcDOM.getSource()).getRef().getId() + : arcDOM.getSource().getId(); + String targetId = + arcDOM.getTarget() instanceof RefTransition + ? ((RefTransition) arcDOM.getTarget()).getRef().getId() + : arcDOM.getTarget().getId(); Place sourcePlace = placeMap.get(sourceId); Transition targetTransition = transitionMap.get(targetId); arc.setSource(sourcePlace); @@ -113,10 +116,14 @@ public List parse() throws PnmlParseException { TPArc arc = new TPArc(arcDOM.getId()); // TODO inhibitor?? - String sourceId = arcDOM.getSource() instanceof RefTransition ? - ((RefTransition) arcDOM.getSource()).getRef().getId() : arcDOM.getSource().getId(); - String targetId = arcDOM.getTarget() instanceof RefPlace ? - ((RefPlace) arcDOM.getTarget()).getRef().getId() : arcDOM.getTarget().getId(); + String sourceId = + arcDOM.getSource() instanceof RefTransition + ? ((RefTransition) arcDOM.getSource()).getRef().getId() + : arcDOM.getSource().getId(); + String targetId = + arcDOM.getTarget() instanceof RefPlace + ? ((RefPlace) arcDOM.getTarget()).getRef().getId() + : arcDOM.getTarget().getId(); Transition sourceTransition = transitionMap.get(sourceId); Place targetPlace = placeMap.get(targetId); arc.setSource(sourceTransition); diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PetriNetParser.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PetriNetParser.java index d3c372ba91..1b976b7e8e 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PetriNetParser.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PetriNetParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import fr.lip6.move.pnml.framework.utils.PNMLUtils; import fr.lip6.move.pnml.ptnet.hlapi.PetriNetDocHLAPI; import hu.bme.mit.theta.frontend.petrinet.model.PetriNet; - import java.io.File; import java.util.List; import java.util.Objects; diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PnmlParseException.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PnmlParseException.java index a2593ff1bb..c80cce3540 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PnmlParseException.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/PnmlParseException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/XMLPnmlToPetrinet.java b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/XMLPnmlToPetrinet.java index adcf8e193b..a7932920a7 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/XMLPnmlToPetrinet.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-model/src/main/java/hu/bme/mit/theta/frontend/petrinet/pnml/XMLPnmlToPetrinet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,32 +15,33 @@ */ package hu.bme.mit.theta.frontend.petrinet.pnml; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.frontend.petrinet.model.*; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.*; import java.io.IOException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.*; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; public class XMLPnmlToPetrinet { - private XMLPnmlToPetrinet() { - } + private XMLPnmlToPetrinet() {} public static PetriNet parse(final String fileName, final String initialMarkingString) - throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { + throws ParserConfigurationException, + IOException, + SAXException, + XPathExpressionException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); @@ -70,30 +71,34 @@ public static PetriNet parse(final String fileName, final String initialMarkingS // Find all places final XPathExpression childPlacesExpr = xPath.compile("./place"); - final NodeList placeList = (NodeList) childPlacesExpr.evaluate(netElement, - XPathConstants.NODESET); + final NodeList placeList = + (NodeList) childPlacesExpr.evaluate(netElement, XPathConstants.NODESET); for (int i = 0; i < placeList.getLength(); i++) { final Element placeElement = (Element) placeList.item(i); final String id = placeElement.getAttribute("id"); -// final String name; -// final XPathExpression nameTextExpr = xPath.compile("./name/text/text()"); -// final XPathExpression nameValueExpr = xPath.compile("./name/value/text()"); -// final String nameText = (String) nameTextExpr.evaluate(placeElement,XPathConstants.STRING); -// if(nameText.equals("")){ -// name = (String) nameValueExpr.evaluate(placeElement,XPathConstants.STRING); -// } else { -// name = nameText; -// } + // final String name; + // final XPathExpression nameTextExpr = xPath.compile("./name/text/text()"); + // final XPathExpression nameValueExpr = xPath.compile("./name/value/text()"); + // final String nameText = (String) + // nameTextExpr.evaluate(placeElement,XPathConstants.STRING); + // if(nameText.equals("")){ + // name = (String) nameValueExpr.evaluate(placeElement,XPathConstants.STRING); + // } else { + // name = nameText; + // } final int initialMarking; if (overrideInitialMarking) { initialMarking = values[i]; } else { - final XPathExpression initialMarkingTextExpr = xPath.compile( - "./initialMarking/text/text()"); - initialMarking = ((Double) initialMarkingTextExpr.evaluate(placeElement, - XPathConstants.NUMBER)).intValue(); + final XPathExpression initialMarkingTextExpr = + xPath.compile("./initialMarking/text/text()"); + initialMarking = + ((Double) + initialMarkingTextExpr.evaluate( + placeElement, XPathConstants.NUMBER)) + .intValue(); } final Place place = new Place(id); @@ -104,21 +109,22 @@ public static PetriNet parse(final String fileName, final String initialMarkingS // Find all transitions final XPathExpression childTransitionsExpr = xPath.compile("./transition"); - final NodeList transitionList = (NodeList) childTransitionsExpr.evaluate(netElement, - XPathConstants.NODESET); + final NodeList transitionList = + (NodeList) childTransitionsExpr.evaluate(netElement, XPathConstants.NODESET); for (int i = 0; i < transitionList.getLength(); i++) { final Element transitionElement = (Element) transitionList.item(i); final String id = transitionElement.getAttribute("id"); -// final String name; -// final XPathExpression nameTextExpr = xPath.compile("./name/text/text()"); -// final XPathExpression nameValueExpr = xPath.compile("./name/value/text()"); -// final String nameText = (String) nameTextExpr.evaluate(transitionElement,XPathConstants.STRING); -// if(nameText.equals("")){ -// name = (String) nameValueExpr.evaluate(transitionElement,XPathConstants.STRING); -// } else { -// name = nameText; -// } + // final String name; + // final XPathExpression nameTextExpr = xPath.compile("./name/text/text()"); + // final XPathExpression nameValueExpr = xPath.compile("./name/value/text()"); + // final String nameText = (String) + // nameTextExpr.evaluate(transitionElement,XPathConstants.STRING); + // if(nameText.equals("")){ + // name = (String) nameValueExpr.evaluate(transitionElement,XPathConstants.STRING); + // } else { + // name = nameText; + // } final Transition transition = new Transition(id); idMap.put(id, transition); @@ -127,8 +133,8 @@ public static PetriNet parse(final String fileName, final String initialMarkingS // Find all arcs final XPathExpression childArcsExpr = xPath.compile("./arc"); - final NodeList arcList = (NodeList) childArcsExpr.evaluate(netElement, - XPathConstants.NODESET); + final NodeList arcList = + (NodeList) childArcsExpr.evaluate(netElement, XPathConstants.NODESET); for (int i = 0; i < arcList.getLength(); i++) { final Element arcElement = (Element) arcList.item(i); final String id = arcElement.getAttribute("id"); @@ -141,10 +147,11 @@ public static PetriNet parse(final String fileName, final String initialMarkingS final Identified target = idMap.get(targetId); checkNotNull(source, "Target node not found of arc " + id); - final XPathExpression toolspecificWeightExpr = xPath.compile( - "./toolspecific/weight/text()"); - final int toolspecificWeight = ((Double) toolspecificWeightExpr.evaluate(arcElement, - XPathConstants.NUMBER)).intValue(); + final XPathExpression toolspecificWeightExpr = + xPath.compile("./toolspecific/weight/text()"); + final int toolspecificWeight = + ((Double) toolspecificWeightExpr.evaluate(arcElement, XPathConstants.NUMBER)) + .intValue(); final int weight = toolspecificWeight == 0 ? 1 : toolspecificWeight; if (source instanceof Place) { @@ -168,5 +175,4 @@ public static PetriNet parse(final String fileName, final String initialMarkingS return ptNet; } - } diff --git a/subprojects/frontends/petrinet-frontend/petrinet-xsts/build.gradle.kts b/subprojects/frontends/petrinet-frontend/petrinet-xsts/build.gradle.kts index 1ce9dc4050..3879f0515f 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-xsts/build.gradle.kts +++ b/subprojects/frontends/petrinet-frontend/petrinet-xsts/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,4 +27,4 @@ dependencies { testImplementation(project(":theta-solver-z3-legacy")) testImplementation(project(":theta-solver")) testImplementation(project(":theta-analysis")) -} \ No newline at end of file +} diff --git a/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/main/java/hu/bme/mit/theta/frontend/petrinet/xsts/PetriNetToXSTS.java b/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/main/java/hu/bme/mit/theta/frontend/petrinet/xsts/PetriNetToXSTS.java index 216111100a..dcf40203cd 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/main/java/hu/bme/mit/theta/frontend/petrinet/xsts/PetriNetToXSTS.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/main/java/hu/bme/mit/theta/frontend/petrinet/xsts/PetriNetToXSTS.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.frontend.petrinet.xsts; +import static com.google.common.base.Preconditions.checkArgument; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.common.container.Containers; @@ -29,22 +34,15 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.frontend.petrinet.model.*; import hu.bme.mit.theta.xsts.XSTS; - import java.io.InputStream; import java.math.BigInteger; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static com.google.common.base.Preconditions.checkArgument; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public class PetriNetToXSTS { - private PetriNetToXSTS() { - } + private PetriNetToXSTS() {} public static XSTS createXSTS(final PetriNet net, final InputStream propStream) { final Map> placeIdToVar = Containers.createMap(); @@ -54,7 +52,10 @@ public static XSTS createXSTS(final PetriNet net, final InputStream propStream) for (Place place : net.getPlaces()) { final VarDecl placeVar = Decls.Var(place.getId(), IntType.getInstance()); placeIdToVar.put(place.getId(), placeVar); - initExprs.add(Eq(placeVar.getRef(), IntExprs.Int(BigInteger.valueOf(place.getInitialMarking())))); + initExprs.add( + Eq( + placeVar.getRef(), + IntExprs.Int(BigInteger.valueOf(place.getInitialMarking())))); } final Expr initExpr = And(initExprs); @@ -71,13 +72,16 @@ public static XSTS createXSTS(final PetriNet net, final InputStream propStream) final VarDecl placeVar = placeIdToVar.get(sourcePlace.getId()); final long weight = inArc.getWeight(); - final Stmt enoughTokens = AssumeStmt.of( - GeqExpr.create2(placeVar.getRef(), Int(BigInteger.valueOf(weight)))); + final Stmt enoughTokens = + AssumeStmt.of( + GeqExpr.create2( + placeVar.getRef(), Int(BigInteger.valueOf(weight)))); stmts.add(enoughTokens); takesPutsMap.merge(placeVar, -weight, Long::sum); -// final Stmt removeTokens = AssignStmt.of(placeVar,Sub(placeVar.getRef(),Int(BigInteger.valueOf(weight)))); -// stmts.add(removeTokens); + // final Stmt removeTokens = + // AssignStmt.of(placeVar,Sub(placeVar.getRef(),Int(BigInteger.valueOf(weight)))); + // stmts.add(removeTokens); } // Place output tokens @@ -88,13 +92,19 @@ public static XSTS createXSTS(final PetriNet net, final InputStream propStream) final long weight = outArc.getWeight(); takesPutsMap.merge(placeVar, weight, Long::sum); -// final Stmt placeTokens = AssignStmt.of(placeVar,Add(placeVar.getRef(),Int(BigInteger.valueOf(weight)))); -// stmts.add(placeTokens); + // final Stmt placeTokens = + // AssignStmt.of(placeVar,Add(placeVar.getRef(),Int(BigInteger.valueOf(weight)))); + // stmts.add(placeTokens); } takesPutsMap.forEach( - (placeVar, weight) -> stmts.add(AssignStmt.of(placeVar, Add(placeVar.getRef(), Int(BigInteger.valueOf(weight))))) - ); + (placeVar, weight) -> + stmts.add( + AssignStmt.of( + placeVar, + Add( + placeVar.getRef(), + Int(BigInteger.valueOf(weight)))))); tranStmts.add(SequenceStmt.of(stmts)); } @@ -113,15 +123,18 @@ public static XSTS createXSTS(final PetriNet net, final InputStream propStream) final Pattern markingPattern = Pattern.compile("([0-9]+\\s)*[0-9]+"); final Matcher markingMatcher = markingPattern.matcher(property); - if (markingMatcher.matches()) { final String[] valueStrings = property.split("\\s"); - final Integer[] values = Arrays.stream(valueStrings).map(Integer::parseInt).toArray(Integer[]::new); + final Integer[] values = + Arrays.stream(valueStrings).map(Integer::parseInt).toArray(Integer[]::new); checkArgument(values.length == net.getPlaces().size()); final List> exprs = new ArrayList<>(); for (int i = 0; i < values.length; i++) { - exprs.add(Eq(placeIdToVar.get(net.getPlaces().get(i).getId()).getRef(), Int(values[i]))); + exprs.add( + Eq( + placeIdToVar.get(net.getPlaces().get(i).getId()).getRef(), + Int(values[i]))); } propExpr = Not(And(exprs)); } else { @@ -151,9 +164,10 @@ private static String stripPropFromPropFile(final String propertyFile) { endingCurlyIndex = i; } } - checkArgument(startingCurlyIndex > -1 && endingCurlyIndex < propertyFile.length(), - "Illegally formatted property %s", propertyFile); + checkArgument( + startingCurlyIndex > -1 && endingCurlyIndex < propertyFile.length(), + "Illegally formatted property %s", + propertyFile); return propertyFile.substring(startingCurlyIndex, endingCurlyIndex); } - } diff --git a/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/test/java/hu.bme.mit.theta.frontend.petrinet.xsts/PnmlTest.java b/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/test/java/hu.bme.mit.theta.frontend.petrinet.xsts/PnmlTest.java index 6b0cb0d5f4..3b71ea438f 100644 --- a/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/test/java/hu.bme.mit.theta.frontend.petrinet.xsts/PnmlTest.java +++ b/subprojects/frontends/petrinet-frontend/petrinet-xsts/src/test/java/hu.bme.mit.theta.frontend.petrinet.xsts/PnmlTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.frontend.petrinet.xsts; +import static org.junit.Assert.assertTrue; + import hu.bme.mit.theta.analysis.algorithm.SafetyResult; import hu.bme.mit.theta.common.logging.ConsoleLogger; import hu.bme.mit.theta.common.logging.Logger; @@ -25,20 +27,17 @@ import hu.bme.mit.theta.xsts.XSTS; import hu.bme.mit.theta.xsts.analysis.config.XstsConfig; import hu.bme.mit.theta.xsts.analysis.config.XstsConfigBuilder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.xml.sax.SAXException; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; - -import static org.junit.Assert.assertTrue; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.xml.sax.SAXException; @RunWith(value = Parameterized.class) public class PnmlTest { @@ -60,41 +59,85 @@ public class PnmlTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}, {4}") public static Collection data() { - return Arrays.asList(new Object[][]{ - -// { "src/test/resources/model/pnml/DPhil-10.pnml", "0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0", "0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1", true, XstsConfigBuilder.Domain.EXPL}, - -// { "src/test/resources/model/pnml/DPhil-100.pnml", "0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0", "0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1", true, XstsConfigBuilder.Domain.EXPL}, - - }); + return Arrays.asList( + new Object[][] { + + // { "src/test/resources/model/pnml/DPhil-10.pnml", "0 0 1 1 0 0 + // 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 + // 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0", "0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1", + // true, XstsConfigBuilder.Domain.EXPL}, + + // { "src/test/resources/model/pnml/DPhil-100.pnml", "0 0 1 1 0 0 + // 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 + // 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 + // 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 + // 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 + // 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 + // 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 + // 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 + // 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 + // 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 + // 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 + // 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 + // 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 + // 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 + // 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 + // 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 + // 1 0 0 0 0 0 0 1 0", "0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 + // 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 + // 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1", true, + // XstsConfigBuilder.Domain.EXPL}, + + }); } @Test public void test() - throws IOException, XPathExpressionException, SAXException, ParserConfigurationException { + throws IOException, + XPathExpressionException, + SAXException, + ParserConfigurationException { final Logger logger = new ConsoleLogger(Level.SUBSTEP); final PetriNet petriNet = XMLPnmlToPetrinet.parse(filePath, initialMarking); XSTS xsts; - try (InputStream propStream = new ByteArrayInputStream( - ("prop { " + targetMarking + " }").getBytes())) { + try (InputStream propStream = + new ByteArrayInputStream(("prop { " + targetMarking + " }").getBytes())) { xsts = PetriNetToXSTS.createXSTS(petriNet, propStream); } - final XstsConfig configuration = new XstsConfigBuilder(domain, - XstsConfigBuilder.Refinement.SEQ_ITP, Z3LegacySolverFactory.getInstance(), - Z3LegacySolverFactory.getInstance()).predSplit(XstsConfigBuilder.PredSplit.CONJUNCTS) - .maxEnum(250).initPrec(XstsConfigBuilder.InitPrec.ALLVARS).logger(logger).build(xsts); + final XstsConfig configuration = + new XstsConfigBuilder( + domain, + XstsConfigBuilder.Refinement.SEQ_ITP, + Z3LegacySolverFactory.getInstance(), + Z3LegacySolverFactory.getInstance()) + .predSplit(XstsConfigBuilder.PredSplit.CONJUNCTS) + .maxEnum(250) + .initPrec(XstsConfigBuilder.InitPrec.ALLVARS) + .logger(logger) + .build(xsts); final SafetyResult status = configuration.check(); if (safe) { assertTrue(status.isSafe()); } else { assertTrue(status.isUnsafe()); } - - } - } diff --git a/subprojects/solver/graph-solver/build.gradle.kts b/subprojects/solver/graph-solver/build.gradle.kts index 449e02d691..7e294f064e 100644 --- a/subprojects/solver/graph-solver/build.gradle.kts +++ b/subprojects/solver/graph-solver/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/3VL.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/3VL.kt index 54c8e87296..e510458ca8 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/3VL.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/3VL.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver enum class ThreeVL { - TRUE, - UNKNOWN, - FALSE -} \ No newline at end of file + TRUE, + UNKNOWN, + FALSE, +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/Utils.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/Utils.kt index ca2fb42b50..a8f6f994d7 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/Utils.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/Utils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver import hu.bme.mit.theta.graphsolver.patterns.constraints.* import hu.bme.mit.theta.graphsolver.patterns.patterns.* -fun GraphConstraint.collectSubRelations(): Set = when (this) { +fun GraphConstraint.collectSubRelations(): Set = + when (this) { is Acyclic -> this.constrainedRule.collectSubRelations() is Cyclic -> this.constrainedRule.collectSubRelations() is Empty -> this.constrainedRule.collectSubRelations() @@ -27,9 +27,10 @@ fun GraphConstraint.collectSubRelations(): Set = when (this) { is Nonempty -> this.constrainedRule.collectSubRelations() is Reflexive -> this.constrainedRule.collectSubRelations() else -> error("") // this should not be necessary, but the compiler complains otherwise -} + } -fun GraphPattern.collectSubRelations(): Set = when (this) { +fun GraphPattern.collectSubRelations(): Set = + when (this) { is BasicRelation -> emptySet() is CartesianProduct -> op1.collectSubRelations() union op2.collectSubRelations() is Complement -> op.collectSubRelations() @@ -53,4 +54,4 @@ fun GraphPattern.collectSubRelations(): Set = when (this) { is Range -> op.collectSubRelations() is UnionNode -> op1.collectSubRelations() union op2.collectSubRelations() else -> error("Should not be here") -} union if (patternName != null) setOf(this) else emptySet() \ No newline at end of file + } union if (patternName != null) setOf(this) else emptySet() 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 aec2b261b9..d7a31436fe 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 8a7e2045b0..d3db637fd8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 9ef99e4e24..a01e511885 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Acyclic.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Acyclic.kt index 63d87693d3..242c9e6a7e 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Acyclic.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Acyclic.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -21,5 +20,5 @@ import hu.bme.mit.theta.graphsolver.patterns.patterns.EdgePattern class Acyclic(val constrainedRule: EdgePattern) : GraphConstraint { - override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Cyclic.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Cyclic.kt index 67b7ed7d17..d5e34cf34c 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Cyclic.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Cyclic.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -21,5 +20,5 @@ import hu.bme.mit.theta.graphsolver.patterns.patterns.EdgePattern class Cyclic(val constrainedRule: EdgePattern) : GraphConstraint { - override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Empty.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Empty.kt index 4f85c01673..48e85468a0 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Empty.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Empty.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -21,5 +20,5 @@ import hu.bme.mit.theta.graphsolver.patterns.patterns.GraphPattern class Empty(val constrainedRule: GraphPattern) : GraphConstraint { - override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/GraphConstraint.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/GraphConstraint.kt index 6eee697866..37f16176ee 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/GraphConstraint.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/GraphConstraint.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -22,5 +21,5 @@ typealias MCM = Collection sealed interface GraphConstraint { - fun accept(compiler: GraphPatternCompiler): T -} \ No newline at end of file + fun accept(compiler: GraphPatternCompiler): T +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Irreflexive.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Irreflexive.kt index 69ad6bedf9..3a410b0fc2 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Irreflexive.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Irreflexive.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -21,5 +20,5 @@ import hu.bme.mit.theta.graphsolver.patterns.patterns.EdgePattern class Irreflexive(val constrainedRule: EdgePattern) : GraphConstraint { - override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Nonempty.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Nonempty.kt index 1b1edf8bec..5d4376e76f 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Nonempty.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Nonempty.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -21,5 +20,5 @@ import hu.bme.mit.theta.graphsolver.patterns.patterns.GraphPattern class Nonempty(val constrainedRule: GraphPattern) : GraphConstraint { - override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Reflexive.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Reflexive.kt index 3c5adb30c9..88fea9b9ed 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Reflexive.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/constraints/Reflexive.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.constraints import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler @@ -21,5 +20,5 @@ import hu.bme.mit.theta.graphsolver.patterns.patterns.EdgePattern class Reflexive(val constrainedRule: EdgePattern) : GraphConstraint { - override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicEventSet.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicEventSet.kt index cc17383497..aff4967447 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicEventSet.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicEventSet.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,9 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class BasicEventSet(val name: String) : NodePattern() { - init { - patternName = name - } + init { + patternName = name + } - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicRelation.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicRelation.kt index afb9bfd245..447f9de58d 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicRelation.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/BasicRelation.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,9 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class BasicRelation(val name: String) : EdgePattern() { - init { - patternName = name - } + init { + patternName = name + } - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/CartesianProduct.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/CartesianProduct.kt index 60de277a41..c7dbb0c1e3 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/CartesianProduct.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/CartesianProduct.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class CartesianProduct(val op1: NodePattern, val op2: NodePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Complement.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Complement.kt index 2a01805da2..f72c74cd99 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Complement.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Complement.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Complement(val op: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ComplementNode.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ComplementNode.kt index f4eee77433..461d479a23 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ComplementNode.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ComplementNode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class ComplementNode(val op: NodePattern) : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Difference.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Difference.kt index 3a65be0fab..c65ed42417 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Difference.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Difference.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Difference(val op1: EdgePattern, val op2: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/DifferenceNode.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/DifferenceNode.kt index b89c6d1aeb..287dac15c7 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/DifferenceNode.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/DifferenceNode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class DifferenceNode(val op1: NodePattern, val op2: NodePattern) : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Domain.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Domain.kt index 48c8e1cbc9..765cf0852c 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Domain.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Domain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Domain(val op: EdgePattern) : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EdgePattern.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EdgePattern.kt index 63cb17a026..b2e3db5535 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EdgePattern.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EdgePattern.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.patterns -sealed class EdgePattern : GraphPattern() \ No newline at end of file +sealed class EdgePattern : GraphPattern() diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptyRel.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptyRel.kt index 1c46977063..0e058b569a 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptyRel.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptyRel.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler object EmptyRel : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptySet.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptySet.kt index 98f724c866..c713e0bc97 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptySet.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/EmptySet.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler object EmptySet : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/GraphPattern.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/GraphPattern.kt index 64a1213b4b..c723f74e87 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/GraphPattern.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/GraphPattern.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.patterns import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler sealed class GraphPattern { - var patternName: String? = null - abstract fun accept(compiler: GraphPatternCompiler<*, T>): T -} \ No newline at end of file + var patternName: String? = null + + abstract fun accept(compiler: GraphPatternCompiler<*, T>): T +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IdentityClosure.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IdentityClosure.kt index 76bfde4769..b5168959fb 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IdentityClosure.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IdentityClosure.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class IdentityClosure(val op: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Intersection.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Intersection.kt index 323fecea64..977e8ffe70 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Intersection.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Intersection.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Intersection(val op1: EdgePattern, val op2: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IntersectionNode.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IntersectionNode.kt index cc4b854e5f..a94ebee3ff 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IntersectionNode.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/IntersectionNode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class IntersectionNode(val op1: NodePattern, val op2: NodePattern) : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Inverse.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Inverse.kt index 3330d81e71..4d4d43f685 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Inverse.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Inverse.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Inverse(val op: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/NodePattern.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/NodePattern.kt index 87f01acc9e..a92bf8fe54 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/NodePattern.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/NodePattern.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.patterns.patterns -sealed class NodePattern : GraphPattern() \ No newline at end of file +sealed class NodePattern : GraphPattern() diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Range.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Range.kt index ea0992b5e0..db1c83641b 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Range.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Range.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Range(val op: EdgePattern) : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ReflexiveTransitiveClosure.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ReflexiveTransitiveClosure.kt index 8ace4ecf73..1f0d14e232 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ReflexiveTransitiveClosure.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/ReflexiveTransitiveClosure.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class ReflexiveTransitiveClosure(val op: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Self.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Self.kt index d9ffbdc610..82a5f20af7 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Self.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Self.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Self(val op: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Sequence.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Sequence.kt index 66ac8062a5..186b5ed136 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Sequence.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Sequence.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Sequence(val op1: EdgePattern, val op2: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Toid.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Toid.kt index c55eb95a34..8d98b61542 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Toid.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Toid.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Toid(val op: NodePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/TransitiveClosure.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/TransitiveClosure.kt index 1774abfa32..920024384d 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/TransitiveClosure.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/TransitiveClosure.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class TransitiveClosure(val op: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Union.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Union.kt index cfc83ee0d4..5e9143e97e 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Union.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/Union.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class Union(val op1: EdgePattern, val op2: EdgePattern) : EdgePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/UnionNode.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/UnionNode.kt index d3d87c3e6b..0d4abf3da6 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/UnionNode.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/patterns/patterns/UnionNode.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,5 @@ import hu.bme.mit.theta.graphsolver.compilers.GraphPatternCompiler class UnionNode(val op1: NodePattern, val op2: NodePattern) : NodePattern() { - override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) -} \ No newline at end of file + override fun accept(compiler: GraphPatternCompiler<*, T>): T = compiler.compile(this) +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/GraphSolver.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/GraphSolver.kt index 4f7fe25cf1..d7e975ba0c 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/GraphSolver.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/GraphSolver.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.solvers import hu.bme.mit.theta.core.model.Valuation @@ -21,12 +20,11 @@ import hu.bme.mit.theta.solver.SolverStatus interface GraphSolver { - fun add(t: T) - - fun getAll(): Collection + fun add(t: T) - fun check(): SolverStatus + fun getAll(): Collection - fun getModel(): Valuation + fun check(): SolverStatus -} \ No newline at end of file + fun getModel(): Valuation +} diff --git a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/SATGraphSolver.kt b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/SATGraphSolver.kt index a1b150491c..852f79b7a6 100644 --- a/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/SATGraphSolver.kt +++ b/subprojects/solver/graph-solver/src/main/java/hu/bme/mit/theta/graphsolver/solvers/SATGraphSolver.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.graphsolver.solvers import hu.bme.mit.theta.core.model.Valuation @@ -24,10 +23,11 @@ import hu.bme.mit.theta.solver.SolverStatus class SATGraphSolver(val solver: Solver) : GraphSolver> { - override fun add(t: Expr) = solver.add(t) + override fun add(t: Expr) = solver.add(t) + + override fun getAll(): Collection> = solver.assertions - override fun getAll(): Collection> = solver.assertions + override fun check(): SolverStatus = solver.check() - override fun check(): SolverStatus = solver.check() - override fun getModel(): Valuation = solver.model -} \ No newline at end of file + override fun getModel(): Valuation = solver.model +} diff --git a/subprojects/solver/graph-solver/src/test/java/hu/bme/mit/theta/graphsolver/GraphSolverTest.kt b/subprojects/solver/graph-solver/src/test/java/hu/bme/mit/theta/graphsolver/GraphSolverTest.kt index 23e7ab23ba..0db67839d8 100644 --- a/subprojects/solver/graph-solver/src/test/java/hu/bme/mit/theta/graphsolver/GraphSolverTest.kt +++ b/subprojects/solver/graph-solver/src/test/java/hu/bme/mit/theta/graphsolver/GraphSolverTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-javasmt/build.gradle.kts b/subprojects/solver/solver-javasmt/build.gradle.kts index babcca831b..3840f712d3 100644 --- a/subprojects/solver/solver-javasmt/build.gradle.kts +++ b/subprojects/solver/solver-javasmt/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTDeclTransformer.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTDeclTransformer.java index ff81f913e6..24adeba148 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTDeclTransformer.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTDeclTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.functype.FuncType; +import java.util.List; import org.sosy_lab.java_smt.api.Formula; import org.sosy_lab.java_smt.api.FormulaType; import org.sosy_lab.java_smt.api.SolverContext; -import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; - final class JavaSMTDeclTransformer { private final JavaSMTTransformationManager transformer; @@ -37,8 +36,10 @@ final class JavaSMTDeclTransformer { private int symbolCount; - JavaSMTDeclTransformer(final JavaSMTTransformationManager transformer, final JavaSMTSymbolTable symbolTable, - final SolverContext context) { + JavaSMTDeclTransformer( + final JavaSMTTransformationManager transformer, + final JavaSMTSymbolTable symbolTable, + final SolverContext context) { this.transformer = transformer; this.symbolTable = symbolTable; this.context = context; @@ -66,10 +67,8 @@ private Formula transformConst(final ConstDecl decl) { final Type returnType = extractedTypes.get2(); final FormulaType returnSort = transformer.toSort(returnType); - final List> paramSorts = paramTypes.stream() - .map(transformer::toSort) - .toList(); - + final List> paramSorts = + paramTypes.stream().map(transformer::toSort).toList(); if (!paramSorts.isEmpty()) { throw new JavaSMTSolverException("Function consts not yet supported."); @@ -77,7 +76,12 @@ private Formula transformConst(final ConstDecl decl) { // Enums can't be yet handled by formulamanager directly if (returnSort.isEnumerationType()) { - symbol = context.getFormulaManager().getEnumerationFormulaManager().makeVariable(symbolNameFor(decl), (FormulaType.EnumerationFormulaType) returnSort); + symbol = + context.getFormulaManager() + .getEnumerationFormulaManager() + .makeVariable( + symbolNameFor(decl), + (FormulaType.EnumerationFormulaType) returnSort); } else { symbol = context.getFormulaManager().makeVariable(returnSort, symbolNameFor(decl)); } @@ -99,8 +103,8 @@ private Tuple2, Type> extractTypes(final Type type) { final Tuple2, Type> subResult = extractTypes(resultType); final List paramTypes = subResult.get1(); final Type newResultType = subResult.get2(); - final List newParamTypes = ImmutableList.builder().add(paramType) - .addAll(paramTypes).build(); + final List newParamTypes = + ImmutableList.builder().add(paramType).addAll(paramTypes).build(); return Tuple2.of(newParamTypes, newResultType); } else { return Tuple2.of(ImmutableList.of(), type); @@ -110,5 +114,4 @@ private Tuple2, Type> extractTypes(final Type type) { private String symbolNameFor(final Decl decl) { return String.format("%s_%d", decl.getName(), symbolCount++); } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTExprTransformer.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTExprTransformer.java index 2e2cf0c32c..2fb06b2417 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTExprTransformer.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; + import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import hu.bme.mit.theta.common.DispatchTable; @@ -144,6 +148,12 @@ import hu.bme.mit.theta.core.type.rattype.RatSubExpr; import hu.bme.mit.theta.core.type.rattype.RatToIntExpr; import hu.bme.mit.theta.core.utils.BvUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.sosy_lab.java_smt.api.ArrayFormula; import org.sosy_lab.java_smt.api.ArrayFormulaManager; import org.sosy_lab.java_smt.api.BitvectorFormula; @@ -167,17 +177,6 @@ import org.sosy_lab.java_smt.api.RationalFormulaManager; import org.sosy_lab.java_smt.api.SolverContext; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; - final class JavaSMTExprTransformer { private static final int CACHE_SIZE = 1000; @@ -198,270 +197,177 @@ final class JavaSMTExprTransformer { private final DispatchTable table; private final Env env; - public JavaSMTExprTransformer(final JavaSMTTransformationManager transformer, final JavaSMTSymbolTable symbolTable, final SolverContext context) { + public JavaSMTExprTransformer( + final JavaSMTTransformationManager transformer, + final JavaSMTSymbolTable symbolTable, + final SolverContext context) { this.symbolTable = symbolTable; this.context = context; this.transformer = transformer; this.env = new Env(); - booleanFormulaManager = orElseNull(() -> context.getFormulaManager().getBooleanFormulaManager()); - integerFormulaManager = orElseNull(() -> context.getFormulaManager().getIntegerFormulaManager()); - rationalFormulaManager = orElseNull(() -> context.getFormulaManager().getRationalFormulaManager()); - bitvectorFormulaManager = orElseNull(() -> context.getFormulaManager().getBitvectorFormulaManager()); - floatingPointFormulaManager = orElseNull(() -> context.getFormulaManager().getFloatingPointFormulaManager()); - quantifiedFormulaManager = orElseNull(() -> context.getFormulaManager().getQuantifiedFormulaManager()); - arrayFormulaManager = orElseNull(() -> context.getFormulaManager().getArrayFormulaManager()); - enumFormulaManager = orElseNull(() -> context.getFormulaManager().getEnumerationFormulaManager()); + booleanFormulaManager = + orElseNull(() -> context.getFormulaManager().getBooleanFormulaManager()); + integerFormulaManager = + orElseNull(() -> context.getFormulaManager().getIntegerFormulaManager()); + rationalFormulaManager = + orElseNull(() -> context.getFormulaManager().getRationalFormulaManager()); + bitvectorFormulaManager = + orElseNull(() -> context.getFormulaManager().getBitvectorFormulaManager()); + floatingPointFormulaManager = + orElseNull(() -> context.getFormulaManager().getFloatingPointFormulaManager()); + quantifiedFormulaManager = + orElseNull(() -> context.getFormulaManager().getQuantifiedFormulaManager()); + arrayFormulaManager = + orElseNull(() -> context.getFormulaManager().getArrayFormulaManager()); + enumFormulaManager = + orElseNull(() -> context.getFormulaManager().getEnumerationFormulaManager()); exprToTerm = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(); - table = DispatchTable.builder() - - // General - - .addCase(RefExpr.class, this::transformRef) - - .addCase(IteExpr.class, this::transformIte) - - // Boolean - - .addCase(FalseExpr.class, this::transformFalse) - - .addCase(TrueExpr.class, this::transformTrue) - - .addCase(NotExpr.class, this::transformNot) - - .addCase(ImplyExpr.class, this::transformImply) - - .addCase(IffExpr.class, this::transformIff) - - .addCase(XorExpr.class, this::transformXor) - - .addCase(AndExpr.class, this::transformAnd) - - .addCase(OrExpr.class, this::transformOr) - - .addCase(ExistsExpr.class, this::transformExists) - - .addCase(ForallExpr.class, this::transformForall) - - // Rationals - - .addCase(RatLitExpr.class, this::transformRatLit) - - .addCase(RatAddExpr.class, this::transformRatAdd) - - .addCase(RatSubExpr.class, this::transformRatSub) - - .addCase(RatPosExpr.class, this::transformRatPos) - - .addCase(RatNegExpr.class, this::transformRatNeg) - - .addCase(RatMulExpr.class, this::transformRatMul) - - .addCase(RatDivExpr.class, this::transformRatDiv) - - .addCase(RatEqExpr.class, this::transformRatEq) - - .addCase(RatNeqExpr.class, this::transformRatNeq) - - .addCase(RatGeqExpr.class, this::transformRatGeq) - - .addCase(RatGtExpr.class, this::transformRatGt) - - .addCase(RatLeqExpr.class, this::transformRatLeq) - - .addCase(RatLtExpr.class, this::transformRatLt) - - .addCase(RatToIntExpr.class, this::transformRatToInt) - - // Integers - - .addCase(IntLitExpr.class, this::transformIntLit) - - .addCase(IntAddExpr.class, this::transformIntAdd) - - .addCase(IntSubExpr.class, this::transformIntSub) - - .addCase(IntPosExpr.class, this::transformIntPos) - - .addCase(IntNegExpr.class, this::transformIntNeg) - - .addCase(IntMulExpr.class, this::transformIntMul) - - .addCase(IntDivExpr.class, this::transformIntDiv) - - .addCase(IntModExpr.class, this::transformIntMod) - - .addCase(IntRemExpr.class, this::transformIntRem) - - .addCase(IntEqExpr.class, this::transformIntEq) - - .addCase(IntNeqExpr.class, this::transformIntNeq) - - .addCase(IntGeqExpr.class, this::transformIntGeq) - - .addCase(IntGtExpr.class, this::transformIntGt) - - .addCase(IntLeqExpr.class, this::transformIntLeq) - - .addCase(IntLtExpr.class, this::transformIntLt) - - .addCase(IntToRatExpr.class, this::transformIntToRat) - - // Bitvectors - - .addCase(BvLitExpr.class, this::transformBvLit) - - .addCase(BvConcatExpr.class, this::transformBvConcat) - - .addCase(BvExtractExpr.class, this::transformBvExtract) - - .addCase(BvZExtExpr.class, this::transformBvZExt) - - .addCase(BvSExtExpr.class, this::transformBvSExt) - - .addCase(BvAddExpr.class, this::transformBvAdd) - - .addCase(BvSubExpr.class, this::transformBvSub) - - .addCase(BvPosExpr.class, this::transformBvPos) - - .addCase(BvSignChangeExpr.class, this::transformBvSignChange) - - .addCase(BvNegExpr.class, this::transformBvNeg) - - .addCase(BvMulExpr.class, this::transformBvMul) - - .addCase(BvUDivExpr.class, this::transformBvUDiv) - - .addCase(BvSDivExpr.class, this::transformBvSDiv) - - .addCase(BvSModExpr.class, this::transformBvSMod) - - .addCase(BvURemExpr.class, this::transformBvURem) - - .addCase(BvSRemExpr.class, this::transformBvSRem) - - .addCase(BvAndExpr.class, this::transformBvAnd) - - .addCase(BvOrExpr.class, this::transformBvOr) - - .addCase(BvXorExpr.class, this::transformBvXor) - - .addCase(BvNotExpr.class, this::transformBvNot) - - .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) - - .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) - - .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) - - .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) - - .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) - - .addCase(BvEqExpr.class, this::transformBvEq) - - .addCase(BvNeqExpr.class, this::transformBvNeq) - - .addCase(BvUGeqExpr.class, this::transformBvUGeq) - - .addCase(BvUGtExpr.class, this::transformBvUGt) - - .addCase(BvULeqExpr.class, this::transformBvULeq) - - .addCase(BvULtExpr.class, this::transformBvULt) - - .addCase(BvSGeqExpr.class, this::transformBvSGeq) - - .addCase(BvSGtExpr.class, this::transformBvSGt) - - .addCase(BvSLeqExpr.class, this::transformBvSLeq) - - .addCase(BvSLtExpr.class, this::transformBvSLt) - - // Floating points - - .addCase(FpLitExpr.class, this::transformFpLit) - - .addCase(FpAddExpr.class, this::transformFpAdd) - - .addCase(FpSubExpr.class, this::transformFpSub) - - .addCase(FpPosExpr.class, this::transformFpPos) - - .addCase(FpNegExpr.class, this::transformFpNeg) - - .addCase(FpMulExpr.class, this::transformFpMul) - - .addCase(FpDivExpr.class, this::transformFpDiv) - - .addCase(FpEqExpr.class, this::transformFpEq) - - .addCase(FpAssignExpr.class, this::transformFpAssign) - - .addCase(FpGeqExpr.class, this::transformFpGeq) - - .addCase(FpLeqExpr.class, this::transformFpLeq) - - .addCase(FpGtExpr.class, this::transformFpGt) - - .addCase(FpLtExpr.class, this::transformFpLt) - - .addCase(FpNeqExpr.class, this::transformFpNeq) - - .addCase(FpAbsExpr.class, this::transformFpAbs) - - .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) - - .addCase(FpMaxExpr.class, this::transformFpMax) - - .addCase(FpMinExpr.class, this::transformFpMin) - - .addCase(FpSqrtExpr.class, this::transformFpSqrt) - - .addCase(FpRemExpr.class, this::transformFpRem) - - .addCase(FpIsNanExpr.class, this::transformFpIsNan) - - .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) - - .addCase(FpFromBvExpr.class, this::transformFpFromBv) - - .addCase(FpToBvExpr.class, this::transformFpToBv) - - .addCase(FpToFpExpr.class, this::transformFpToFp) - - // Functions - - .addCase(FuncAppExpr.class, this::transformFuncApp) - - // Arrays - - .addCase(ArrayReadExpr.class, this::transformArrayRead) - - .addCase(ArrayWriteExpr.class, this::transformArrayWrite) - - .addCase(ArrayEqExpr.class, this::transformArrayEq) - - .addCase(ArrayNeqExpr.class, this::transformArrayNeq) - - .addCase(ArrayLitExpr.class, this::transformArrayLit) - - .addCase(ArrayInitExpr.class, this::transformArrayInit) - - .addCase(Dereference.class, this::transformDereference) - - // Enums - - .addCase(EnumLitExpr.class, this::transformEnumLit) - - .addCase(EnumNeqExpr.class, this::transformEnumNeq) - - .addCase(EnumEqExpr.class, this::transformEnumEq) - - .build(); + table = + DispatchTable.builder() + + // General + + .addCase(RefExpr.class, this::transformRef) + .addCase(IteExpr.class, this::transformIte) + + // Boolean + + .addCase(FalseExpr.class, this::transformFalse) + .addCase(TrueExpr.class, this::transformTrue) + .addCase(NotExpr.class, this::transformNot) + .addCase(ImplyExpr.class, this::transformImply) + .addCase(IffExpr.class, this::transformIff) + .addCase(XorExpr.class, this::transformXor) + .addCase(AndExpr.class, this::transformAnd) + .addCase(OrExpr.class, this::transformOr) + .addCase(ExistsExpr.class, this::transformExists) + .addCase(ForallExpr.class, this::transformForall) + + // Rationals + + .addCase(RatLitExpr.class, this::transformRatLit) + .addCase(RatAddExpr.class, this::transformRatAdd) + .addCase(RatSubExpr.class, this::transformRatSub) + .addCase(RatPosExpr.class, this::transformRatPos) + .addCase(RatNegExpr.class, this::transformRatNeg) + .addCase(RatMulExpr.class, this::transformRatMul) + .addCase(RatDivExpr.class, this::transformRatDiv) + .addCase(RatEqExpr.class, this::transformRatEq) + .addCase(RatNeqExpr.class, this::transformRatNeq) + .addCase(RatGeqExpr.class, this::transformRatGeq) + .addCase(RatGtExpr.class, this::transformRatGt) + .addCase(RatLeqExpr.class, this::transformRatLeq) + .addCase(RatLtExpr.class, this::transformRatLt) + .addCase(RatToIntExpr.class, this::transformRatToInt) + + // Integers + + .addCase(IntLitExpr.class, this::transformIntLit) + .addCase(IntAddExpr.class, this::transformIntAdd) + .addCase(IntSubExpr.class, this::transformIntSub) + .addCase(IntPosExpr.class, this::transformIntPos) + .addCase(IntNegExpr.class, this::transformIntNeg) + .addCase(IntMulExpr.class, this::transformIntMul) + .addCase(IntDivExpr.class, this::transformIntDiv) + .addCase(IntModExpr.class, this::transformIntMod) + .addCase(IntRemExpr.class, this::transformIntRem) + .addCase(IntEqExpr.class, this::transformIntEq) + .addCase(IntNeqExpr.class, this::transformIntNeq) + .addCase(IntGeqExpr.class, this::transformIntGeq) + .addCase(IntGtExpr.class, this::transformIntGt) + .addCase(IntLeqExpr.class, this::transformIntLeq) + .addCase(IntLtExpr.class, this::transformIntLt) + .addCase(IntToRatExpr.class, this::transformIntToRat) + + // Bitvectors + + .addCase(BvLitExpr.class, this::transformBvLit) + .addCase(BvConcatExpr.class, this::transformBvConcat) + .addCase(BvExtractExpr.class, this::transformBvExtract) + .addCase(BvZExtExpr.class, this::transformBvZExt) + .addCase(BvSExtExpr.class, this::transformBvSExt) + .addCase(BvAddExpr.class, this::transformBvAdd) + .addCase(BvSubExpr.class, this::transformBvSub) + .addCase(BvPosExpr.class, this::transformBvPos) + .addCase(BvSignChangeExpr.class, this::transformBvSignChange) + .addCase(BvNegExpr.class, this::transformBvNeg) + .addCase(BvMulExpr.class, this::transformBvMul) + .addCase(BvUDivExpr.class, this::transformBvUDiv) + .addCase(BvSDivExpr.class, this::transformBvSDiv) + .addCase(BvSModExpr.class, this::transformBvSMod) + .addCase(BvURemExpr.class, this::transformBvURem) + .addCase(BvSRemExpr.class, this::transformBvSRem) + .addCase(BvAndExpr.class, this::transformBvAnd) + .addCase(BvOrExpr.class, this::transformBvOr) + .addCase(BvXorExpr.class, this::transformBvXor) + .addCase(BvNotExpr.class, this::transformBvNot) + .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) + .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) + .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) + .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) + .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) + .addCase(BvEqExpr.class, this::transformBvEq) + .addCase(BvNeqExpr.class, this::transformBvNeq) + .addCase(BvUGeqExpr.class, this::transformBvUGeq) + .addCase(BvUGtExpr.class, this::transformBvUGt) + .addCase(BvULeqExpr.class, this::transformBvULeq) + .addCase(BvULtExpr.class, this::transformBvULt) + .addCase(BvSGeqExpr.class, this::transformBvSGeq) + .addCase(BvSGtExpr.class, this::transformBvSGt) + .addCase(BvSLeqExpr.class, this::transformBvSLeq) + .addCase(BvSLtExpr.class, this::transformBvSLt) + + // Floating points + + .addCase(FpLitExpr.class, this::transformFpLit) + .addCase(FpAddExpr.class, this::transformFpAdd) + .addCase(FpSubExpr.class, this::transformFpSub) + .addCase(FpPosExpr.class, this::transformFpPos) + .addCase(FpNegExpr.class, this::transformFpNeg) + .addCase(FpMulExpr.class, this::transformFpMul) + .addCase(FpDivExpr.class, this::transformFpDiv) + .addCase(FpEqExpr.class, this::transformFpEq) + .addCase(FpAssignExpr.class, this::transformFpAssign) + .addCase(FpGeqExpr.class, this::transformFpGeq) + .addCase(FpLeqExpr.class, this::transformFpLeq) + .addCase(FpGtExpr.class, this::transformFpGt) + .addCase(FpLtExpr.class, this::transformFpLt) + .addCase(FpNeqExpr.class, this::transformFpNeq) + .addCase(FpAbsExpr.class, this::transformFpAbs) + .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) + .addCase(FpMaxExpr.class, this::transformFpMax) + .addCase(FpMinExpr.class, this::transformFpMin) + .addCase(FpSqrtExpr.class, this::transformFpSqrt) + .addCase(FpRemExpr.class, this::transformFpRem) + .addCase(FpIsNanExpr.class, this::transformFpIsNan) + .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) + .addCase(FpFromBvExpr.class, this::transformFpFromBv) + .addCase(FpToBvExpr.class, this::transformFpToBv) + .addCase(FpToFpExpr.class, this::transformFpToFp) + + // Functions + + .addCase(FuncAppExpr.class, this::transformFuncApp) + + // Arrays + + .addCase(ArrayReadExpr.class, this::transformArrayRead) + .addCase(ArrayWriteExpr.class, this::transformArrayWrite) + .addCase(ArrayEqExpr.class, this::transformArrayEq) + .addCase(ArrayNeqExpr.class, this::transformArrayNeq) + .addCase(ArrayLitExpr.class, this::transformArrayLit) + .addCase(ArrayInitExpr.class, this::transformArrayInit) + .addCase(Dereference.class, this::transformDereference) + + // Enums + + .addCase(EnumLitExpr.class, this::transformEnumLit) + .addCase(EnumNeqExpr.class, this::transformEnumNeq) + .addCase(EnumEqExpr.class, this::transformEnumEq) + .build(); } private static T orElseNull(Supplier supplier) { @@ -472,7 +378,8 @@ private static T orElseNull(Supplier supplier) { } } - private static FloatingPointRoundingMode transformRoundingMode(final FpRoundingMode fpRoundingMode) { + private static FloatingPointRoundingMode transformRoundingMode( + final FpRoundingMode fpRoundingMode) { return switch (fpRoundingMode) { case RNE -> FloatingPointRoundingMode.NEAREST_TIES_TO_EVEN; case RNA -> FloatingPointRoundingMode.NEAREST_TIES_AWAY; @@ -521,7 +428,6 @@ private Formula transformIte(final IteExpr expr) { private Formula transformFalse(final FalseExpr expr) { return booleanFormulaManager.makeFalse(); - } private Formula transformTrue(final TrueExpr expr) { @@ -552,16 +458,14 @@ private Formula transformXor(final XorExpr expr) { } private Formula transformAnd(final AndExpr expr) { - final List opTerms = expr.getOps().stream() - .map(e -> (BooleanFormula) toTerm(e)) - .toList(); + final List opTerms = + expr.getOps().stream().map(e -> (BooleanFormula) toTerm(e)).toList(); return booleanFormulaManager.and(opTerms); } private Formula transformOr(final OrExpr expr) { - final List opTerms = expr.getOps().stream() - .map(e -> (BooleanFormula) toTerm(e)) - .toList(); + final List opTerms = + expr.getOps().stream().map(e -> (BooleanFormula) toTerm(e)).toList(); return booleanFormulaManager.or(opTerms); } @@ -614,17 +518,14 @@ private Formula transformRatLit(final RatLitExpr expr) { } private Formula transformRatAdd(final RatAddExpr expr) { - final List opTerms = expr.getOps().stream() - .map(e -> (RationalFormula) toTerm(e)) - .toList(); + final List opTerms = + expr.getOps().stream().map(e -> (RationalFormula) toTerm(e)).toList(); return opTerms.stream().reduce(rationalFormulaManager::add).get(); } private Formula transformRatSub(final RatSubExpr expr) { - final RationalFormula leftOpTerm = (RationalFormula) toTerm( - expr.getLeftOp()); - final RationalFormula rightOpTerm = (RationalFormula) toTerm( - expr.getRightOp()); + final RationalFormula leftOpTerm = (RationalFormula) toTerm(expr.getLeftOp()); + final RationalFormula rightOpTerm = (RationalFormula) toTerm(expr.getRightOp()); return rationalFormulaManager.subtract(leftOpTerm, rightOpTerm); } @@ -638,17 +539,14 @@ private Formula transformRatNeg(final RatNegExpr expr) { } private Formula transformRatMul(final RatMulExpr expr) { - final List opTerms = expr.getOps().stream() - .map(e -> (RationalFormula) toTerm(e)) - .toList(); + final List opTerms = + expr.getOps().stream().map(e -> (RationalFormula) toTerm(e)).toList(); return opTerms.stream().reduce(rationalFormulaManager::multiply).get(); } private Formula transformRatDiv(final RatDivExpr expr) { - final RationalFormula leftOpTerm = (RationalFormula) toTerm( - expr.getLeftOp()); - final RationalFormula rightOpTerm = (RationalFormula) toTerm( - expr.getRightOp()); + final RationalFormula leftOpTerm = (RationalFormula) toTerm(expr.getLeftOp()); + final RationalFormula rightOpTerm = (RationalFormula) toTerm(expr.getRightOp()); return rationalFormulaManager.divide(leftOpTerm, rightOpTerm); } @@ -665,18 +563,14 @@ private Formula transformRatNeq(final RatNeqExpr expr) { } private Formula transformRatGeq(final RatGeqExpr expr) { - final RationalFormula leftOpTerm = (RationalFormula) toTerm( - expr.getLeftOp()); - final RationalFormula rightOpTerm = (RationalFormula) toTerm( - expr.getRightOp()); + final RationalFormula leftOpTerm = (RationalFormula) toTerm(expr.getLeftOp()); + final RationalFormula rightOpTerm = (RationalFormula) toTerm(expr.getRightOp()); return rationalFormulaManager.greaterOrEquals(leftOpTerm, rightOpTerm); } private Formula transformRatGt(final RatGtExpr expr) { - final RationalFormula leftOpTerm = (RationalFormula) toTerm( - expr.getLeftOp()); - final RationalFormula rightOpTerm = (RationalFormula) toTerm( - expr.getRightOp()); + final RationalFormula leftOpTerm = (RationalFormula) toTerm(expr.getLeftOp()); + final RationalFormula rightOpTerm = (RationalFormula) toTerm(expr.getRightOp()); return rationalFormulaManager.greaterThan(leftOpTerm, rightOpTerm); } @@ -685,18 +579,14 @@ private Formula transformRatGt(final RatGtExpr expr) { */ private Formula transformRatLeq(final RatLeqExpr expr) { - final RationalFormula leftOpTerm = (RationalFormula) toTerm( - expr.getLeftOp()); - final RationalFormula rightOpTerm = (RationalFormula) toTerm( - expr.getRightOp()); + final RationalFormula leftOpTerm = (RationalFormula) toTerm(expr.getLeftOp()); + final RationalFormula rightOpTerm = (RationalFormula) toTerm(expr.getRightOp()); return rationalFormulaManager.lessOrEquals(leftOpTerm, rightOpTerm); } private Formula transformRatLt(final RatLtExpr expr) { - final RationalFormula leftOpTerm = (RationalFormula) toTerm( - expr.getLeftOp()); - final RationalFormula rightOpTerm = (RationalFormula) toTerm( - expr.getRightOp()); + final RationalFormula leftOpTerm = (RationalFormula) toTerm(expr.getLeftOp()); + final RationalFormula rightOpTerm = (RationalFormula) toTerm(expr.getRightOp()); return rationalFormulaManager.lessThan(leftOpTerm, rightOpTerm); } @@ -709,17 +599,14 @@ private Formula transformIntLit(final IntLitExpr expr) { } private Formula transformIntAdd(final IntAddExpr expr) { - final List opTerms = expr.getOps().stream() - .map(e -> (IntegerFormula) toTerm(e)) - .toList(); + final List opTerms = + expr.getOps().stream().map(e -> (IntegerFormula) toTerm(e)).toList(); return opTerms.stream().reduce(integerFormulaManager::add).get(); } private Formula transformIntSub(final IntSubExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.subtract(leftOpTerm, rightOpTerm); } @@ -733,38 +620,32 @@ private Formula transformIntNeg(final IntNegExpr expr) { } private Formula transformIntMul(final IntMulExpr expr) { - final List opTerms = expr.getOps().stream() - .map(e -> (IntegerFormula) toTerm(e)) - .toList(); + final List opTerms = + expr.getOps().stream().map(e -> (IntegerFormula) toTerm(e)).toList(); return opTerms.stream().reduce(integerFormulaManager::multiply).get(); } private Formula transformIntDiv(final IntDivExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.divide(leftOpTerm, rightOpTerm); } private Formula transformIntMod(final IntModExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.modulo(leftOpTerm, rightOpTerm); } private Formula transformIntRem(final IntRemExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return booleanFormulaManager.ifThenElse( - integerFormulaManager.greaterOrEquals(rightOpTerm, integerFormulaManager.makeNumber(0)), + integerFormulaManager.greaterOrEquals( + rightOpTerm, integerFormulaManager.makeNumber(0)), integerFormulaManager.modulo(leftOpTerm, rightOpTerm), - integerFormulaManager.negate(integerFormulaManager.modulo(leftOpTerm, rightOpTerm)) - ); + integerFormulaManager.negate( + integerFormulaManager.modulo(leftOpTerm, rightOpTerm))); } private Formula transformIntEq(final IntEqExpr expr) { @@ -780,26 +661,20 @@ private Formula transformIntNeq(final IntNeqExpr expr) { } private Formula transformIntGeq(final IntGeqExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.greaterOrEquals(leftOpTerm, rightOpTerm); } private Formula transformIntGt(final IntGtExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.greaterThan(leftOpTerm, rightOpTerm); } private Formula transformIntLeq(final IntLeqExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.lessOrEquals(leftOpTerm, rightOpTerm); } @@ -808,10 +683,8 @@ private Formula transformIntLeq(final IntLeqExpr expr) { */ private Formula transformIntLt(final IntLtExpr expr) { - final IntegerFormula leftOpTerm = (IntegerFormula) toTerm( - expr.getLeftOp()); - final IntegerFormula rightOpTerm = (IntegerFormula) toTerm( - expr.getRightOp()); + final IntegerFormula leftOpTerm = (IntegerFormula) toTerm(expr.getLeftOp()); + final IntegerFormula rightOpTerm = (IntegerFormula) toTerm(expr.getRightOp()); return integerFormulaManager.lessThan(leftOpTerm, rightOpTerm); } @@ -821,8 +694,7 @@ private Formula transformIntToRat(final IntToRatExpr expr) { private Formula transformBvLit(final BvLitExpr expr) { return bitvectorFormulaManager.makeBitvector( - expr.getType().getSize(), - BvUtils.neutralBvLitExprToBigInteger(expr)); + expr.getType().getSize(), BvUtils.neutralBvLitExprToBigInteger(expr)); } private Formula transformBvEq(final BvEqExpr expr) { @@ -838,9 +710,10 @@ private Formula transformBvNeq(final BvNeqExpr expr) { } private Formula transformBvConcat(final BvConcatExpr expr) { - final BitvectorFormula[] opTerms = expr.getOps().stream() - .map(e -> (BitvectorFormula) toTerm(e)) - .toArray(BitvectorFormula[]::new); + final BitvectorFormula[] opTerms = + expr.getOps().stream() + .map(e -> (BitvectorFormula) toTerm(e)) + .toArray(BitvectorFormula[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], bitvectorFormulaManager::concat); } @@ -868,9 +741,10 @@ private Formula transformBvSExt(final BvSExtExpr expr) { } private Formula transformBvAdd(final BvAddExpr expr) { - final BitvectorFormula[] opTerms = expr.getOps().stream() - .map(e -> (BitvectorFormula) toTerm(e)) - .toArray(BitvectorFormula[]::new); + final BitvectorFormula[] opTerms = + expr.getOps().stream() + .map(e -> (BitvectorFormula) toTerm(e)) + .toArray(BitvectorFormula[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], bitvectorFormulaManager::add); } @@ -895,9 +769,10 @@ private Formula transformBvNeg(final BvNegExpr expr) { } private Formula transformBvMul(final BvMulExpr expr) { - final BitvectorFormula[] opTerms = expr.getOps().stream() - .map(e -> (BitvectorFormula) toTerm(e)) - .toArray(BitvectorFormula[]::new); + final BitvectorFormula[] opTerms = + expr.getOps().stream() + .map(e -> (BitvectorFormula) toTerm(e)) + .toArray(BitvectorFormula[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], bitvectorFormulaManager::multiply); } @@ -938,25 +813,28 @@ private Formula transformBvSRem(final BvSRemExpr expr) { } private Formula transformBvAnd(final BvAndExpr expr) { - final BitvectorFormula[] opTerms = expr.getOps().stream() - .map(e -> (BitvectorFormula) toTerm(e)) - .toArray(BitvectorFormula[]::new); + final BitvectorFormula[] opTerms = + expr.getOps().stream() + .map(e -> (BitvectorFormula) toTerm(e)) + .toArray(BitvectorFormula[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], bitvectorFormulaManager::and); } private Formula transformBvOr(final BvOrExpr expr) { - final BitvectorFormula[] opTerms = expr.getOps().stream() - .map(e -> (BitvectorFormula) toTerm(e)) - .toArray(BitvectorFormula[]::new); + final BitvectorFormula[] opTerms = + expr.getOps().stream() + .map(e -> (BitvectorFormula) toTerm(e)) + .toArray(BitvectorFormula[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], bitvectorFormulaManager::or); } private Formula transformBvXor(final BvXorExpr expr) { - final BitvectorFormula[] opTerms = expr.getOps().stream() - .map(e -> (BitvectorFormula) toTerm(e)) - .toArray(BitvectorFormula[]::new); + final BitvectorFormula[] opTerms = + expr.getOps().stream() + .map(e -> (BitvectorFormula) toTerm(e)) + .toArray(BitvectorFormula[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], bitvectorFormulaManager::xor); } @@ -1067,25 +945,30 @@ private Formula transformFpLit(final FpLitExpr expr) { BvUtils.neutralBvLitExprToBigInteger(expr.getExponent()), BvUtils.neutralBvLitExprToBigInteger(expr.getSignificand()), expr.getHidden(), - FloatingPointType.getFloatingPointType(expr.getType().getExponent(), expr.getType().getSignificand() - 1) - ); + FloatingPointType.getFloatingPointType( + expr.getType().getExponent(), expr.getType().getSignificand() - 1)); } private Formula transformFpAdd(final FpAddExpr expr) { - final FloatingPointFormula[] opTerms = expr.getOps().stream() - .map(e -> (FloatingPointFormula) toTerm(e)) - .toArray(FloatingPointFormula[]::new); + final FloatingPointFormula[] opTerms = + expr.getOps().stream() + .map(e -> (FloatingPointFormula) toTerm(e)) + .toArray(FloatingPointFormula[]::new); - return Stream.of(opTerms).skip(1).reduce(opTerms[0], - (op1, op2) -> floatingPointFormulaManager.add(op1, op2, - transformFpRoundingMode(expr.getRoundingMode()) - )); + return Stream.of(opTerms) + .skip(1) + .reduce( + opTerms[0], + (op1, op2) -> + floatingPointFormulaManager.add( + op1, op2, transformFpRoundingMode(expr.getRoundingMode()))); } private Formula transformFpSub(final FpSubExpr expr) { final FloatingPointFormula leftOpTerm = (FloatingPointFormula) toTerm(expr.getLeftOp()); final FloatingPointFormula rightOpTerm = (FloatingPointFormula) toTerm(expr.getRightOp()); - return floatingPointFormulaManager.subtract(leftOpTerm, rightOpTerm, transformFpRoundingMode(expr.getRoundingMode())); + return floatingPointFormulaManager.subtract( + leftOpTerm, rightOpTerm, transformFpRoundingMode(expr.getRoundingMode())); } private Formula transformFpPos(final FpPosExpr expr) { @@ -1114,28 +997,37 @@ private Formula transformFpIsInfinite(final FpIsInfiniteExpr expr) { private Formula transformFpSqrt(final FpSqrtExpr expr) { final FloatingPointFormula opTerm = (FloatingPointFormula) toTerm(expr.getOp()); - return floatingPointFormulaManager.sqrt(opTerm, transformFpRoundingMode(expr.getRoundingMode())); + return floatingPointFormulaManager.sqrt( + opTerm, transformFpRoundingMode(expr.getRoundingMode())); } private Formula transformFpRoundToIntegral(final FpRoundToIntegralExpr expr) { final FloatingPointFormula opTerm = (FloatingPointFormula) toTerm(expr.getOp()); - return floatingPointFormulaManager.round(opTerm, transformFpRoundingMode(expr.getRoundingMode())); + return floatingPointFormulaManager.round( + opTerm, transformFpRoundingMode(expr.getRoundingMode())); } private Formula transformFpMul(final FpMulExpr expr) { - final FloatingPointFormula[] opTerms = expr.getOps().stream() - .map(e -> (FloatingPointFormula) toTerm(e)) - .toArray(FloatingPointFormula[]::new); + final FloatingPointFormula[] opTerms = + expr.getOps().stream() + .map(e -> (FloatingPointFormula) toTerm(e)) + .toArray(FloatingPointFormula[]::new); - return Stream.of(opTerms).skip(1).reduce(opTerms[0], - (op1, op2) -> floatingPointFormulaManager.multiply(op1, op2, transformFpRoundingMode(expr.getRoundingMode()))); + return Stream.of(opTerms) + .skip(1) + .reduce( + opTerms[0], + (op1, op2) -> + floatingPointFormulaManager.multiply( + op1, op2, transformFpRoundingMode(expr.getRoundingMode()))); } private Formula transformFpDiv(final FpDivExpr expr) { final FloatingPointFormula leftOpTerm = (FloatingPointFormula) toTerm(expr.getLeftOp()); final FloatingPointFormula rightOpTerm = (FloatingPointFormula) toTerm(expr.getRightOp()); - return floatingPointFormulaManager.divide(leftOpTerm, rightOpTerm, transformFpRoundingMode(expr.getRoundingMode())); + return floatingPointFormulaManager.divide( + leftOpTerm, rightOpTerm, transformFpRoundingMode(expr.getRoundingMode())); } private Formula transformFpRem(final FpRemExpr expr) { @@ -1147,43 +1039,51 @@ private Formula transformFpRem(final FpRemExpr expr) { private Formula transformFpEq(final FpEqExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return floatingPointFormulaManager.equalWithFPSemantics((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); + return floatingPointFormulaManager.equalWithFPSemantics( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); } private Formula transformFpAssign(final FpAssignExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return floatingPointFormulaManager.assignment((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); + return floatingPointFormulaManager.assignment( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); } private Formula transformFpNeq(final FpNeqExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return booleanFormulaManager.not(floatingPointFormulaManager.equalWithFPSemantics((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm)); + return booleanFormulaManager.not( + floatingPointFormulaManager.equalWithFPSemantics( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm)); } private Formula transformFpGeq(final FpGeqExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return floatingPointFormulaManager.greaterOrEquals((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); + return floatingPointFormulaManager.greaterOrEquals( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); } private Formula transformFpLeq(final FpLeqExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return floatingPointFormulaManager.lessOrEquals((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); + return floatingPointFormulaManager.lessOrEquals( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); } private Formula transformFpGt(final FpGtExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return floatingPointFormulaManager.greaterThan((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); + return floatingPointFormulaManager.greaterThan( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); } private Formula transformFpLt(final FpLtExpr expr) { final Formula leftOpTerm = toTerm(expr.getLeftOp()); final Formula rightOpTerm = toTerm(expr.getRightOp()); - return floatingPointFormulaManager.lessThan((FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); + return floatingPointFormulaManager.lessThan( + (FloatingPointFormula) leftOpTerm, (FloatingPointFormula) rightOpTerm); } private FloatingPointRoundingMode transformFpRoundingMode(final FpRoundingMode roundingMode) { @@ -1210,20 +1110,26 @@ private Formula transformFpMin(final FpMinExpr expr) { private Formula transformFpFromBv(final FpFromBvExpr expr) { final BitvectorFormula val = (BitvectorFormula) toTerm(expr.getOp()); - final FloatingPointType fpSort = FloatingPointType.getFloatingPointType( - expr.getFpType().getExponent(), - expr.getFpType().getSignificand() - 1); + final FloatingPointType fpSort = + FloatingPointType.getFloatingPointType( + expr.getFpType().getExponent(), expr.getFpType().getSignificand() - 1); return floatingPointFormulaManager.castFrom(val, expr.isSigned(), fpSort); } + /* * Arrays */ private Formula transformFpToBv(final FpToBvExpr expr) { final FloatingPointFormula op = (FloatingPointFormula) toTerm(expr.getOp()); - final FloatingPointRoundingMode roundingMode = transformRoundingMode(expr.getRoundingMode()); + final FloatingPointRoundingMode roundingMode = + transformRoundingMode(expr.getRoundingMode()); - return floatingPointFormulaManager.castTo(op, expr.getSgn(), FormulaType.getBitvectorTypeWithSize(expr.getSize()), roundingMode); + return floatingPointFormulaManager.castTo( + op, + expr.getSgn(), + FormulaType.getBitvectorTypeWithSize(expr.getSize()), + roundingMode); } private Formula transformFpToFp(final FpToFpExpr expr) { @@ -1237,21 +1143,20 @@ private Formula transformFpToFp(final FpToFpExpr expr) { } private Formula transformArrayRead(final ArrayReadExpr expr) { - final ArrayFormula arrayTerm = (ArrayFormula) toTerm( - expr.getArray()); + final ArrayFormula arrayTerm = (ArrayFormula) toTerm(expr.getArray()); final Formula indexTerm = toTerm(expr.getIndex()); return arrayFormulaManager.select(arrayTerm, indexTerm); } private Formula transformArrayWrite(final ArrayWriteExpr expr) { - final ArrayFormula arrayTerm = (ArrayFormula) toTerm( - expr.getArray()); + final ArrayFormula arrayTerm = (ArrayFormula) toTerm(expr.getArray()); final Formula indexTerm = toTerm(expr.getIndex()); final Formula elemTerm = toTerm(expr.getElem()); return arrayFormulaManager.store(arrayTerm, indexTerm, elemTerm); } - private Formula transformArrayEq(final ArrayEqExpr expr) { + private Formula transformArrayEq( + final ArrayEqExpr expr) { final ArrayFormula leftOpTerm = (ArrayFormula) toTerm(expr.getLeftOp()); final ArrayFormula rightOpTerm = (ArrayFormula) toTerm(expr.getRightOp()); return arrayFormulaManager.equivalence(leftOpTerm, rightOpTerm); @@ -1259,18 +1164,18 @@ private Formula transformArrayEq(final private Formula transformArrayNeq(final ArrayNeqExpr expr) { return booleanFormulaManager.not( - (BooleanFormula) transformArrayEq(ArrayEqExpr.create(expr.getLeftOp(), expr.getRightOp())) - ); + (BooleanFormula) + transformArrayEq(ArrayEqExpr.create(expr.getLeftOp(), expr.getRightOp()))); } - private Formula transformArrayLit(final ArrayLitExpr expr) { + private Formula transformArrayLit( + final ArrayLitExpr expr) { final TE elseElem = (TE) toTerm(expr.getElseElem()); - final FormulaType elemType = (FormulaType) transformer.toSort(expr.getType().getElemType()); - final FormulaType indexType = (FormulaType) transformer.toSort(expr.getType().getIndexType()); - var arr = arrayFormulaManager.makeArray( - elseElem, - indexType, - elemType); + final FormulaType elemType = + (FormulaType) transformer.toSort(expr.getType().getElemType()); + final FormulaType indexType = + (FormulaType) transformer.toSort(expr.getType().getIndexType()); + var arr = arrayFormulaManager.makeArray(elseElem, indexType, elemType); for (Tuple2, ? extends LitExpr> element : expr.getElements()) { final TI index = (TI) toTerm(element.get1()); final TE elem = (TE) toTerm(element.get2()); @@ -1279,19 +1184,18 @@ private Formula transformArrayLit(final return arr; } - /* * Functions */ - private Formula transformArrayInit(final ArrayInitExpr expr) { + private Formula transformArrayInit( + final ArrayInitExpr expr) { final TE elseElem = (TE) toTerm(expr.getElseElem()); - final FormulaType elemType = (FormulaType) transformer.toSort(expr.getType().getElemType()); - final FormulaType indexType = (FormulaType) transformer.toSort(expr.getType().getIndexType()); - var arr = arrayFormulaManager.makeArray( - elseElem, - indexType, - elemType); + final FormulaType elemType = + (FormulaType) transformer.toSort(expr.getType().getElemType()); + final FormulaType indexType = + (FormulaType) transformer.toSort(expr.getType().getIndexType()); + var arr = arrayFormulaManager.makeArray(elseElem, indexType, elemType); for (Tuple2, ? extends Expr> element : expr.getElements()) { final TI index = (TI) toTerm(element.get1()); final TE elem = (TE) toTerm(element.get2()); @@ -1309,19 +1213,21 @@ private Formula transformFuncApp(final FuncAppExpr expr) { final String name = decl.getName(); final List> args = funcAndArgs.get2(); - final List argTerms = args.stream() - .map(this::toTerm) - .toList(); - + final List argTerms = args.stream().map(this::toTerm).toList(); final FunctionDeclaration funcDecl; if (symbolTable.definesConstAsFunction(decl)) { funcDecl = symbolTable.getSymbolAsFunction(decl); } else { - funcDecl = context.getFormulaManager().getUFManager().declareUF( - name, - transformer.toSort(expr.getType()), - argTerms.stream().map(context.getFormulaManager()::getFormulaType).collect(Collectors.toList())); + funcDecl = + context.getFormulaManager() + .getUFManager() + .declareUF( + name, + transformer.toSort(expr.getType()), + argTerms.stream() + .map(context.getFormulaManager()::getFormulaType) + .collect(Collectors.toList())); symbolTable.put(decl, funcDecl); } @@ -1334,37 +1240,53 @@ private Formula transformFuncApp(final FuncAppExpr expr) { } private Formula transformDereference(final Dereference expr) { - checkState(expr.getUniquenessIdx().isPresent(), "Incomplete dereferences (missing uniquenessIdx) are not handled properly."); + checkState( + expr.getUniquenessIdx().isPresent(), + "Incomplete dereferences (missing uniquenessIdx) are not handled properly."); final var sort = transformer.toSort(expr.getArray().getType()); final var sortName = expr.getArray().getType().toString() + "-" + expr.getType().toString(); final var constSort = transformer.toSort(Int()); - final var funcDecl = context.getFormulaManager().getUFManager().declareUF( - "deref-" + sortName.replaceAll(" ", "_"), - transformer.toSort(expr.getType()), - List.of(sort, sort, constSort)); - - final var func = context.getFormulaManager().getUFManager() - .callUF(funcDecl, toTerm(expr.getArray()), toTerm(expr.getOffset()), toTerm(expr.getUniquenessIdx().get())); + final var funcDecl = + context.getFormulaManager() + .getUFManager() + .declareUF( + "deref-" + sortName.replaceAll(" ", "_"), + transformer.toSort(expr.getType()), + List.of(sort, sort, constSort)); + + final var func = + context.getFormulaManager() + .getUFManager() + .callUF( + funcDecl, + toTerm(expr.getArray()), + toTerm(expr.getOffset()), + toTerm(expr.getUniquenessIdx().get())); return func; } // Enums private Formula transformEnumEq(EnumEqExpr enumEqExpr) { - return enumFormulaManager.equivalence((EnumerationFormula) toTerm(enumEqExpr.getLeftOp()), (EnumerationFormula) toTerm(enumEqExpr.getRightOp())); + return enumFormulaManager.equivalence( + (EnumerationFormula) toTerm(enumEqExpr.getLeftOp()), + (EnumerationFormula) toTerm(enumEqExpr.getRightOp())); } private Formula transformEnumLit(EnumLitExpr enumLitExpr) { - return enumFormulaManager.makeConstant(EnumType.makeLongName(enumLitExpr.getType(), enumLitExpr.getValue()), (FormulaType.EnumerationFormulaType) transformer.toSort(enumLitExpr.getType())); + return enumFormulaManager.makeConstant( + EnumType.makeLongName(enumLitExpr.getType(), enumLitExpr.getValue()), + (FormulaType.EnumerationFormulaType) transformer.toSort(enumLitExpr.getType())); } private Formula transformEnumNeq(EnumNeqExpr enumNeqExpr) { - return booleanFormulaManager.not(enumFormulaManager.equivalence((EnumerationFormula) toTerm(enumNeqExpr.getLeftOp()), (EnumerationFormula) toTerm(enumNeqExpr.getRightOp()))); + return booleanFormulaManager.not( + enumFormulaManager.equivalence( + (EnumerationFormula) toTerm(enumNeqExpr.getLeftOp()), + (EnumerationFormula) toTerm(enumNeqExpr.getRightOp()))); } - public void reset() { exprToTerm.invalidateAll(); } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTInterpolant.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTInterpolant.java index 8c8f3b6682..c294b225a9 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTInterpolant.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTInterpolant.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Interpolant; import hu.bme.mit.theta.solver.ItpMarker; - import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; - final class JavaSMTInterpolant implements Interpolant { private final Map> itpMap; @@ -39,5 +38,4 @@ public Expr eval(final ItpMarker marker) { checkNotNull(itpExpr); return itpExpr; } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpMarker.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpMarker.java index ca5e6abe20..618b7b2745 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpMarker.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - final class JavaSMTItpMarker implements ItpMarker { private final Stack terms; @@ -46,5 +45,4 @@ public void pop(final int n) { public Collection getTerms() { return terms.toCollection(); } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpPattern.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpPattern.java index 29ab0c5bbd..ef21eb60c2 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpPattern.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpPattern.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,20 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.Lists; import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.ItpMarkerTree; import hu.bme.mit.theta.solver.ItpPattern; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - -public class JavaSMTItpPattern implements ItpPattern.Binary, - ItpPattern.Sequence, ItpPattern.Tree { +public class JavaSMTItpPattern + implements ItpPattern.Binary, + ItpPattern.Sequence, + ItpPattern.Tree { final ItpMarkerTree markerTree; @@ -89,11 +90,10 @@ public E visit(ItpPatternVisitor visitor) { } private boolean isBinary() { - return - markerTree != null && - markerTree.getChildrenNumber() == 1 && - markerTree.getChild(0) != null && - markerTree.getChild(0).getChildrenNumber() == 0; + return markerTree != null + && markerTree.getChildrenNumber() == 1 + && markerTree.getChild(0) != null + && markerTree.getChild(0).getChildrenNumber() == 0; } private boolean isSequence() { diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolver.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolver.java index d5546a90e3..fade4d1266 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolver.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.model.Valuation; @@ -29,21 +34,15 @@ import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; -import org.sosy_lab.java_smt.api.BooleanFormula; -import org.sosy_lab.java_smt.api.InterpolatingProverEnvironment; -import org.sosy_lab.java_smt.api.SolverContext; -import org.sosy_lab.java_smt.api.SolverException; - import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import org.sosy_lab.java_smt.api.BooleanFormula; +import org.sosy_lab.java_smt.api.InterpolatingProverEnvironment; +import org.sosy_lab.java_smt.api.SolverContext; +import org.sosy_lab.java_smt.api.SolverException; final class JavaSMTItpSolver implements ItpSolver, Solver { @@ -59,16 +58,23 @@ final class JavaSMTItpSolver implements ItpSolver, Solver { private final JavaSMTTermTransformer termTransformer; private final SolverContext context; - public JavaSMTItpSolver(final JavaSMTSymbolTable symbolTable, - final JavaSMTTransformationManager transformationManager, - final JavaSMTTermTransformer termTransformer, - final SolverContext context, - final InterpolatingProverEnvironment interpolatingProverEnvironment) { + public JavaSMTItpSolver( + final JavaSMTSymbolTable symbolTable, + final JavaSMTTransformationManager transformationManager, + final JavaSMTTermTransformer termTransformer, + final SolverContext context, + final InterpolatingProverEnvironment interpolatingProverEnvironment) { this.transformationManager = transformationManager; this.termTransformer = termTransformer; this.context = context; - this.solver = new JavaSMTSolver(symbolTable, transformationManager, termTransformer, context, interpolatingProverEnvironment); + this.solver = + new JavaSMTSolver( + symbolTable, + transformationManager, + termTransformer, + context, + interpolatingProverEnvironment); this.interpolatingProverEnvironment = interpolatingProverEnvironment; markers = new StackImpl<>(); @@ -99,7 +105,9 @@ public void add(final ItpMarker marker, final Expr assertion) { Object c = solver.add(assertion, term); jsmtMarker.add(c); termMap.add(Tuple2.of(assertion, c)); - combinedTermMap = termMap.toCollection().stream().collect(Collectors.toMap(Tuple2::get1, Tuple2::get2)); + combinedTermMap = + termMap.toCollection().stream() + .collect(Collectors.toMap(Tuple2::get1, Tuple2::get2)); } else { jsmtMarker.add(combinedTermMap.get(assertion)); } @@ -107,7 +115,8 @@ public void add(final ItpMarker marker, final Expr assertion) { @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(solver.getStatus() == SolverStatus.UNSAT, + checkState( + solver.getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof JavaSMTItpPattern); @@ -125,7 +134,9 @@ public Interpolant getInterpolant(final ItpPattern pattern) { if (indexList.stream().allMatch(i -> i == 0)) { interpolants = interpolatingProverEnvironment.getSeqInterpolants(termList); } else { - interpolants = interpolatingProverEnvironment.getTreeInterpolants(termList, indexList.stream().mapToInt(i -> i).toArray()); + interpolants = + interpolatingProverEnvironment.getTreeInterpolants( + termList, indexList.stream().mapToInt(i -> i).toArray()); } Map> itpMap = Containers.createMap(); @@ -141,7 +152,11 @@ public Interpolant getInterpolant(final ItpPattern pattern) { } } - private int getInterpolantParams(final ItpMarkerTree root, List markerList, final List> terms, final List indices) { + private int getInterpolantParams( + final ItpMarkerTree root, + List markerList, + final List> terms, + final List indices) { int leftmostIndex = -1; for (ItpMarkerTree child : root.getChildren()) { final int index = getInterpolantParams(child, markerList, terms, indices); @@ -158,7 +173,6 @@ private int getInterpolantParams(final ItpMarkerTree root, Lis return leftmostIndex; } - @Override public Collection getMarkers() { return markers.toCollection(); @@ -185,7 +199,9 @@ public void push() { marker.push(); } solver.push(); - combinedTermMap = termMap.toCollection().stream().collect(Collectors.toMap(Tuple2::get1, Tuple2::get2)); + combinedTermMap = + termMap.toCollection().stream() + .collect(Collectors.toMap(Tuple2::get1, Tuple2::get2)); } @Override @@ -196,7 +212,9 @@ public void pop(final int n) { marker.pop(n); } solver.pop(n); - combinedTermMap = termMap.toCollection().stream().collect(Collectors.toMap(Tuple2::get1, Tuple2::get2)); + combinedTermMap = + termMap.toCollection().stream() + .collect(Collectors.toMap(Tuple2::get1, Tuple2::get2)); } @Override diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolver.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolver.java index 032fced121..032aeb7e51 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolver.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverException.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverException.java index 06ead8f05b..0e75ec66cc 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverException.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.javasmt; public class JavaSMTSolverException extends RuntimeException { @@ -29,5 +28,4 @@ public JavaSMTSolverException(String message, Throwable cause) { public JavaSMTSolverException(Throwable cause) { super(cause); } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFactory.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFactory.java index ed3c2a2008..3828196142 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFactory.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,6 +19,9 @@ import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.UCSolver; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; import org.sosy_lab.common.ShutdownManager; import org.sosy_lab.common.configuration.Configuration; import org.sosy_lab.common.configuration.InvalidConfigurationException; @@ -31,10 +34,6 @@ import org.sosy_lab.java_smt.api.SolverContext; import org.sosy_lab.java_smt.api.SolverContext.ProverOptions; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - public final class JavaSMTSolverFactory implements SolverFactory { private final Solvers solver; @@ -43,60 +42,42 @@ public final class JavaSMTSolverFactory implements SolverFactory { private final ShutdownManager shutdownManager; /** - * Available options (mined from javasmt sources): - * Prefix: solver - * Options: - * * private boolean logAllQueries Export solver queries in SmtLib format into a file. - * * @FileOption(FileOption.Type.OUTPUT_FILE) private @Nullable PathCounterTemplate logfile Export solver queries in SmtLib format into a file. - * * private boolean renameLogfileToAvoidConflicts If logging from the same application, avoid conflicting logfile names. - * * private long randomSeed Random seed for SMT solver. - * * private Solvers solver Which SMT solver to use. - * * private boolean useLogger Log solver actions, this may be slow! - * * private boolean synchronize Sequentialize all solver actions to allow concurrent access! - * * private boolean collectStatistics Counts all operations and interactions towards the SMT solver. - * * private FloatingPointRoundingMode floatingPointRoundingMode Default rounding mode for floating point operations. - * * private NonLinearArithmetic nonLinearArithmetic Use non-linear arithmetic of the solver if supported and throw exception otherwise, - * Prefix: solver.synchronized - * Options: - * * private boolean useSeperateProvers Use provers from a seperate context to solve queries. - * Prefix: solver.boolector - * Options: - * * private SatSolver satSolver The SAT solver used by Boolector. - * * private String furtherOptions Further options for Boolector in addition to the default options. - * Prefix: solver.cvc5 - * Options: - * * private boolean validateInterpolants apply additional validation checks for interpolation results - * Prefix: solver.mathsat5 - * Options: - * * private String furtherOptions Further options that will be passed to Mathsat in addition to the default options. - * * boolean loadOptimathsat5 Load less stable optimizing version of mathsat5 solver. - * Prefix: solver.opensmt - * Options: - * * Logics logic SMT-LIB2 name of the logic to be used by the solver. - * * int algBool Algorithm for boolean interpolation - * * int algUf Algorithm for UF interpolation - * * int algLra Algorithm for LRA interpolation - * Prefix: solver.princess - * Options: - * * private int minAtomsForAbbreviation The number of atoms a term has to have before - * * private boolean enableAssertions Enable additional assertion checks within Princess. - * * private boolean logAllQueriesAsScala log all queries as Princess-specific Scala code - * * @FileOption(FileOption.Type.OUTPUT_FILE) private PathCounterTemplate logAllQueriesAsScalaFile file for Princess-specific dump of queries as Scala code - * Prefix: solver.smtinterpol - * Options: - * * private boolean checkResults Double check generated results like interpolants and models whether they are correct - * * private List furtherOptions Further options that will be set to true for SMTInterpol - * Prefix: solver.z3 - * Options: - * * private boolean usePhantomReferences Whether to use PhantomReferences for discarding Z3 AST - * Prefix: solver.z3 - * Options: - * * boolean requireProofs Require proofs from SMT solver - * * @FileOption(FileOption.Type.OUTPUT_FILE) @Nullable Path log Activate replayable logging in Z3. - * * String optimizationEngine Engine to use for the optimization - * * String objectivePrioritizationMode Ordering for objectives in the optimization context + * Available options (mined from javasmt sources): Prefix: solver Options: * private boolean + * logAllQueries Export solver queries in SmtLib format into a file. + * * @FileOption(FileOption.Type.OUTPUT_FILE) private @Nullable PathCounterTemplate logfile + * Export solver queries in SmtLib format into a file. * private boolean + * renameLogfileToAvoidConflicts If logging from the same application, avoid conflicting logfile + * names. * private long randomSeed Random seed for SMT solver. * private Solvers solver Which + * SMT solver to use. * private boolean useLogger Log solver actions, this may be slow! * + * private boolean synchronize Sequentialize all solver actions to allow concurrent access! * + * private boolean collectStatistics Counts all operations and interactions towards the SMT + * solver. * private FloatingPointRoundingMode floatingPointRoundingMode Default rounding mode + * for floating point operations. * private NonLinearArithmetic nonLinearArithmetic Use + * non-linear arithmetic of the solver if supported and throw exception otherwise, Prefix: + * solver.synchronized Options: * private boolean useSeperateProvers Use provers from a seperate + * context to solve queries. Prefix: solver.boolector Options: * private SatSolver satSolver The + * SAT solver used by Boolector. * private String furtherOptions Further options for Boolector + * in addition to the default options. Prefix: solver.cvc5 Options: * private boolean + * validateInterpolants apply additional validation checks for interpolation results Prefix: + * solver.mathsat5 Options: * private String furtherOptions Further options that will be passed + * to Mathsat in addition to the default options. * boolean loadOptimathsat5 Load less stable + * optimizing version of mathsat5 solver. Prefix: solver.opensmt Options: * Logics logic + * SMT-LIB2 name of the logic to be used by the solver. * int algBool Algorithm for boolean + * interpolation * int algUf Algorithm for UF interpolation * int algLra Algorithm for LRA + * interpolation Prefix: solver.princess Options: * private int minAtomsForAbbreviation The + * number of atoms a term has to have before * private boolean enableAssertions Enable + * additional assertion checks within Princess. * private boolean logAllQueriesAsScala log all + * queries as Princess-specific Scala code * @FileOption(FileOption.Type.OUTPUT_FILE) private + * PathCounterTemplate logAllQueriesAsScalaFile file for Princess-specific dump of queries as + * Scala code Prefix: solver.smtinterpol Options: * private boolean checkResults Double check + * generated results like interpolants and models whether they are correct * private + * List furtherOptions Further options that will be set to true for SMTInterpol Prefix: + * solver.z3 Options: * private boolean usePhantomReferences Whether to use PhantomReferences + * for discarding Z3 AST Prefix: solver.z3 Options: * boolean requireProofs Require proofs from + * SMT solver * @FileOption(FileOption.Type.OUTPUT_FILE) @Nullable Path log Activate replayable + * logging in Z3. * String optimizationEngine Engine to use for the optimization * String + * objectivePrioritizationMode Ordering for objectives in the optimization context */ - private JavaSMTSolverFactory(Solvers solver, String[] args) { try { this.solver = solver; @@ -109,11 +90,15 @@ private JavaSMTSolverFactory(Solvers solver, String[] args) { } public static JavaSMTSolverFactory create(Solvers solver, Map args) { - return create(solver, args.entrySet().stream().flatMap(e -> Stream.of(e.getKey(), e.getValue())).toList()); + return create( + solver, + args.entrySet().stream() + .flatMap(e -> Stream.of(e.getKey(), e.getValue())) + .toList()); } public static JavaSMTSolverFactory create(Solvers solver, List args) { - return create(solver, args.toArray(new String[]{})); + return create(solver, args.toArray(new String[] {})); } public static JavaSMTSolverFactory create(Solvers solver, String[] args) { @@ -123,37 +108,49 @@ public static JavaSMTSolverFactory create(Solvers solver, String[] args) { @Override public Solver createSolver() { try { - final SolverContext context = SolverContextFactory.createSolverContext(config, logger, shutdownManager.getNotifier(), solver); + final SolverContext context = + SolverContextFactory.createSolverContext( + config, logger, shutdownManager.getNotifier(), solver); final JavaSMTSymbolTable symbolTable = new JavaSMTSymbolTable(); - final JavaSMTTransformationManager transformationManager = new JavaSMTTransformationManager(symbolTable, context); - final JavaSMTTermTransformer termTransformer = new JavaSMTTermTransformer(symbolTable, context); + final JavaSMTTransformationManager transformationManager = + new JavaSMTTransformationManager(symbolTable, context); + final JavaSMTTermTransformer termTransformer = + new JavaSMTTermTransformer(symbolTable, context); - final ProverEnvironment prover = context.newProverEnvironment(ProverOptions.GENERATE_MODELS); + final ProverEnvironment prover = + context.newProverEnvironment(ProverOptions.GENERATE_MODELS); - return new JavaSMTSolver(symbolTable, transformationManager, termTransformer, context, prover); + return new JavaSMTSolver( + symbolTable, transformationManager, termTransformer, context, prover); } catch (InvalidConfigurationException e) { throw new JavaSMTSolverException(e); } } - public Solver createSolverWithPropagators(JavaSMTUserPropagator... propagators) { try { - final SolverContext context = SolverContextFactory.createSolverContext(config, logger, shutdownManager.getNotifier(), solver); + final SolverContext context = + SolverContextFactory.createSolverContext( + config, logger, shutdownManager.getNotifier(), solver); final JavaSMTSymbolTable symbolTable = new JavaSMTSymbolTable(); - final JavaSMTTransformationManager transformationManager = new JavaSMTTransformationManager(symbolTable, context); - final JavaSMTTermTransformer termTransformer = new JavaSMTTermTransformer(symbolTable, context); + final JavaSMTTransformationManager transformationManager = + new JavaSMTTransformationManager(symbolTable, context); + final JavaSMTTermTransformer termTransformer = + new JavaSMTTermTransformer(symbolTable, context); - final ProverEnvironment prover = context.newProverEnvironment(ProverOptions.GENERATE_MODELS); + final ProverEnvironment prover = + context.newProverEnvironment(ProverOptions.GENERATE_MODELS); for (JavaSMTUserPropagator propagator : propagators) { if (!prover.registerUserPropagator(propagator)) { - throw new JavaSMTSolverException("Could not register user propagator " + propagator); + throw new JavaSMTSolverException( + "Could not register user propagator " + propagator); } propagator.setToExpr(termTransformer::toExpr); propagator.setToTerm(transformationManager::toTerm); } - return new JavaSMTSolver(symbolTable, transformationManager, termTransformer, context, prover); + return new JavaSMTSolver( + symbolTable, transformationManager, termTransformer, context, prover); } catch (InvalidConfigurationException e) { throw new JavaSMTSolverException(e); } @@ -162,14 +159,21 @@ public Solver createSolverWithPropagators(JavaSMTUserPropagator... propagators) @Override public UCSolver createUCSolver() { try { - final SolverContext context = SolverContextFactory.createSolverContext(config, logger, shutdownManager.getNotifier(), solver); + final SolverContext context = + SolverContextFactory.createSolverContext( + config, logger, shutdownManager.getNotifier(), solver); final JavaSMTSymbolTable symbolTable = new JavaSMTSymbolTable(); - final JavaSMTTransformationManager transformationManager = new JavaSMTTransformationManager(symbolTable, context); - final JavaSMTTermTransformer termTransformer = new JavaSMTTermTransformer(symbolTable, context); + final JavaSMTTransformationManager transformationManager = + new JavaSMTTransformationManager(symbolTable, context); + final JavaSMTTermTransformer termTransformer = + new JavaSMTTermTransformer(symbolTable, context); - final ProverEnvironment prover = context.newProverEnvironment(ProverOptions.GENERATE_MODELS, ProverOptions.GENERATE_UNSAT_CORE); + final ProverEnvironment prover = + context.newProverEnvironment( + ProverOptions.GENERATE_MODELS, ProverOptions.GENERATE_UNSAT_CORE); - return new JavaSMTSolver(symbolTable, transformationManager, termTransformer, context, prover); + return new JavaSMTSolver( + symbolTable, transformationManager, termTransformer, context, prover); } catch (InvalidConfigurationException e) { throw new JavaSMTSolverException(e); } @@ -178,17 +182,22 @@ public UCSolver createUCSolver() { @Override public ItpSolver createItpSolver() { try { - final SolverContext context = SolverContextFactory.createSolverContext(config, logger, shutdownManager.getNotifier(), solver); + final SolverContext context = + SolverContextFactory.createSolverContext( + config, logger, shutdownManager.getNotifier(), solver); final JavaSMTSymbolTable symbolTable = new JavaSMTSymbolTable(); - final JavaSMTTransformationManager transformationManager = new JavaSMTTransformationManager(symbolTable, context); - final JavaSMTTermTransformer termTransformer = new JavaSMTTermTransformer(symbolTable, context); + final JavaSMTTransformationManager transformationManager = + new JavaSMTTransformationManager(symbolTable, context); + final JavaSMTTermTransformer termTransformer = + new JavaSMTTermTransformer(symbolTable, context); - final InterpolatingProverEnvironment prover = context.newProverEnvironmentWithInterpolation(ProverOptions.GENERATE_MODELS); + final InterpolatingProverEnvironment prover = + context.newProverEnvironmentWithInterpolation(ProverOptions.GENERATE_MODELS); - return new JavaSMTItpSolver(symbolTable, transformationManager, termTransformer, context, prover); + return new JavaSMTItpSolver( + symbolTable, transformationManager, termTransformer, context, prover); } catch (InvalidConfigurationException e) { throw new JavaSMTSolverException(e); } } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverManager.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverManager.java index c50859b282..dc2ab6e5dc 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverManager.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,21 +15,20 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverBase; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.SolverManager; import hu.bme.mit.theta.solver.UCSolver; -import org.sosy_lab.common.configuration.InvalidConfigurationException; -import org.sosy_lab.java_smt.SolverContextFactory.Solvers; - import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; +import org.sosy_lab.common.configuration.InvalidConfigurationException; +import org.sosy_lab.java_smt.SolverContextFactory.Solvers; public final class JavaSMTSolverManager extends SolverManager { @@ -38,8 +37,7 @@ public final class JavaSMTSolverManager extends SolverManager { private boolean closed = false; private final Set instantiatedSolvers = new HashSet<>(); - private JavaSMTSolverManager() { - } + private JavaSMTSolverManager() {} public static JavaSMTSolverManager create() { return new JavaSMTSolverManager(); @@ -57,7 +55,8 @@ public SolverFactory getSolverFactory(final String name) throws InvalidConfigura final var solverName = matcher.group(1); final var solver = Solvers.valueOf(solverName); - return new ManagedFactory(JavaSMTSolverFactory.create(solver, new String[]{"--nonLinearArithmetic=USE"})); + return new ManagedFactory( + JavaSMTSolverFactory.create(solver, new String[] {"--nonLinearArithmetic=USE"})); } @Override diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSymbolTable.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSymbolTable.java index e081b5b8ef..1fcfcb77b4 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSymbolTable.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSymbolTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; @@ -22,10 +26,6 @@ import org.sosy_lab.java_smt.api.Formula; import org.sosy_lab.java_smt.api.FunctionDeclaration; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - final class JavaSMTSymbolTable { private final BiMap, Formula> constToSymbol; @@ -53,13 +53,17 @@ public boolean definesSymbol(final FunctionDeclaration symbol) { } public Formula getSymbolAsFormula(final ConstDecl constDecl) { - checkArgument(definesConstAsFormula(constDecl), "Declaration %s not found in symbol table", + checkArgument( + definesConstAsFormula(constDecl), + "Declaration %s not found in symbol table", constDecl); return constToSymbol.get(constDecl); } public FunctionDeclaration getSymbolAsFunction(final ConstDecl constDecl) { - checkArgument(definesConstAsFunction(constDecl), "Declaration %s not found in symbol table", + checkArgument( + definesConstAsFunction(constDecl), + "Declaration %s not found in symbol table", constDecl); return constToFuncDecl.get(constDecl); } @@ -92,5 +96,4 @@ public void clear() { constToSymbol.clear(); constToFuncDecl.clear(); } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTermTransformer.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTermTransformer.java index c0c17aeed0..710bc57dad 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTermTransformer.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTermTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,22 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpAssign; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import com.google.common.collect.Lists; import hu.bme.mit.theta.common.QuadFunction; import hu.bme.mit.theta.common.TernaryOperator; @@ -48,6 +64,18 @@ import hu.bme.mit.theta.core.type.inttype.IntLitExpr; import hu.bme.mit.theta.core.utils.BvUtils; import hu.bme.mit.theta.core.utils.TypeUtils; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.sosy_lab.common.rationals.Rational; import org.sosy_lab.java_smt.api.BitvectorFormula; import org.sosy_lab.java_smt.api.BooleanFormula; @@ -65,43 +93,20 @@ import org.sosy_lab.java_smt.api.SolverContext; import org.sosy_lab.java_smt.api.visitors.FormulaVisitor; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.FpAssign; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - final class JavaSMTTermTransformer { private static final String PARAM_NAME_FORMAT = "_p%d"; private final JavaSMTSymbolTable symbolTable; private final SolverContext context; - private final Map, QuadFunction, Model, List>, Expr>> environment; - private final Map, QuadFunction, Model, List>, Expr>> otherFuncs; + private final Map< + Tuple2, + QuadFunction, Model, List>, Expr>> + environment; + private final Map< + Tuple2, + QuadFunction, Model, List>, Expr>> + otherFuncs; public JavaSMTTermTransformer(final JavaSMTSymbolTable symbolTable, SolverContext context) { this.symbolTable = symbolTable; @@ -109,183 +114,426 @@ public JavaSMTTermTransformer(final JavaSMTSymbolTable symbolTable, SolverContex environment = Containers.createMap(); otherFuncs = Containers.createMap(); - addEnvFunc(FunctionDeclarationKind.AND, exprMultiaryOperator(hu.bme.mit.theta.core.type.booltype.AndExpr::create)); -// addEnvFunc("false", exprNullaryOperator(hu.bme.mit.theta.core.type.booltype.FalseExpr::getInstance)); -// addEnvFunc("true", exprNullaryOperator(hu.bme.mit.theta.core.type.booltype.TrueExpr::getInstance)); - addEnvFunc(FunctionDeclarationKind.IFF, exprBinaryOperator(hu.bme.mit.theta.core.type.booltype.IffExpr::create)); - addEnvFunc(FunctionDeclarationKind.NOT, exprUnaryOperator(hu.bme.mit.theta.core.type.booltype.NotExpr::create)); - addEnvFunc(FunctionDeclarationKind.IMPLIES, exprBinaryOperator(hu.bme.mit.theta.core.type.booltype.ImplyExpr::create)); - addEnvFunc(FunctionDeclarationKind.XOR, exprBinaryOperator(hu.bme.mit.theta.core.type.booltype.XorExpr::create)); - addEnvFunc(FunctionDeclarationKind.OR, exprMultiaryOperator(hu.bme.mit.theta.core.type.booltype.OrExpr::create)); - addEnvFunc(FunctionDeclarationKind.ITE, exprTernaryOperator(hu.bme.mit.theta.core.type.anytype.IteExpr::create)); -// addEnvFunc("if", exprTernaryOperator(hu.bme.mit.theta.core.type.anytype.IteExpr::create)); -// addEnvFunc("prime", exprUnaryOperator(hu.bme.mit.theta.core.type.anytype.PrimeExpr::of)); - addEnvFunc(FunctionDeclarationKind.EQ, exprBinaryOperator((expr, expr2) -> expr.getType() instanceof FpType ? FpAssign((Expr) expr, (Expr) expr2) : Eq(expr, expr2))); - addEnvFunc(FunctionDeclarationKind.GTE, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Geq)); - addEnvFunc(FunctionDeclarationKind.GT, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Gt)); - addEnvFunc(FunctionDeclarationKind.LTE, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Leq)); - addEnvFunc(FunctionDeclarationKind.LT, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Lt)); - addEnvFunc(FunctionDeclarationKind.ADD, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Add)); - addEnvFunc(FunctionDeclarationKind.SUB, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Sub)); - addEnvFunc(FunctionDeclarationKind.ADD, exprUnaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Pos)); - addEnvFunc(FunctionDeclarationKind.UMINUS, exprUnaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Neg)); - addEnvFunc(FunctionDeclarationKind.MUL, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Mul)); - addEnvFunc(FunctionDeclarationKind.DIV, exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Div)); - addEnvFunc(FunctionDeclarationKind.FLOOR, exprUnaryOperator(hu.bme.mit.theta.core.type.rattype.RatToIntExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_ROUND_TO_INTEGRAL, exprUnaryOperator(hu.bme.mit.theta.core.type.rattype.RatToIntExpr::create)); -// addEnvFunc("div", exprBinaryOperator(hu.bme.mit.theta.core.type.inttype.IntDivExpr::create)); - addEnvFunc(FunctionDeclarationKind.TO_REAL, exprUnaryOperator(hu.bme.mit.theta.core.type.inttype.IntToRatExpr::create)); - addEnvFunc(FunctionDeclarationKind.MODULO, exprBinaryOperator(hu.bme.mit.theta.core.type.inttype.IntModExpr::create)); -// addEnvFunc("rem", exprBinaryOperator(hu.bme.mit.theta.core.type.inttype.IntRemExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_ADD, exprFpMultiaryOperator(hu.bme.mit.theta.core.type.fptype.FpAddExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_SUB, exprFpBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpSubExpr::create)); -// addEnvFunc("fp.pos", exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpPosExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_NEG, exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpNegExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_MUL, exprFpMultiaryOperator(hu.bme.mit.theta.core.type.fptype.FpMulExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_DIV, exprFpBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpDivExpr::create)); - addOtherFunc("fp.rem", exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpRemExpr::create)); - addOtherFunc("fprem", exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpRemExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_ABS, exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpAbsExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_LE, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpLeqExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_LT, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpLtExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_GE, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpGeqExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_GT, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpGtExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_EQ, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpEqExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_IS_NAN, exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsNanExpr::create)); -// addEnvFunc("fp.isNaN", exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsNanExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_IS_INF, exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsInfiniteExpr::create)); -// addEnvFunc("fp.isInfinite", exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsInfiniteExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_ROUND_TO_INTEGRAL, exprFpUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpRoundToIntegralExpr::create)); -// addEnvFunc("fp.roundToIntegral", exprFpUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpRoundToIntegralExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_SQRT, exprFpUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpSqrtExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_MAX, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpMaxExpr::create)); - addEnvFunc(FunctionDeclarationKind.FP_MIN, exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpMinExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_CONCAT, exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvConcatExpr::create)); -// addEnvFunc("concat", exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvConcatExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_ADD, exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvAddExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SUB, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSubExpr::create)); -// addEnvFunc("bvpos", exprUnaryOperator(hu.bme.mit.theta.core.type.bvtype.BvPosExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_NEG, exprUnaryOperator(hu.bme.mit.theta.core.type.bvtype.BvNegExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_MUL, exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvMulExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_UDIV, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvUDivExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SDIV, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSDivExpr::create)); - addOtherFunc("bvsmod", exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSModExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_UREM, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvURemExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SREM, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSRemExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_OR, exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvOrExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_AND, exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvAndExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_XOR, exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvXorExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_NOT, exprUnaryOperator(hu.bme.mit.theta.core.type.bvtype.BvNotExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SHL, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_ASHR, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_LSHR, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr::create)); -// addEnvFunc("bvrol", exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr::create)); - addOtherFunc("ext_rotate_left", exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr::create)); -// addEnvFunc("bvror", exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr::create)); - addOtherFunc("ext_rotate_right", exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_ULT, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvULtExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_ULE, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvULeqExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_UGT, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvUGtExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_UGE, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SLT, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSLtExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SLE, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SGT, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSGtExpr::create)); - addEnvFunc(FunctionDeclarationKind.BV_SGE, exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr::create)); -// addEnvFunc("read", exprBinaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr::create)); -// addEnvFunc("write", exprTernaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr::create)); - addEnvFunc(FunctionDeclarationKind.SELECT, exprBinaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr::create)); - addEnvFunc(FunctionDeclarationKind.STORE, exprTernaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr::create)); - - environment.put(Tuple2.of(FunctionDeclarationKind.FP_FROM_IEEEBV, 1), (term, args, model, vars) -> { - FloatingPointType type = (FloatingPointType) context.getFormulaManager().getFormulaType((FloatingPointFormula) term); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op = (Expr) transform(args.get(1), model, vars); - return FpFromBvExpr.of(roundingmode, op, FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), true); - }); - environment.put(Tuple2.of(FunctionDeclarationKind.FP_CASTTO_SBV, 2), (term, args, model, vars) -> { - BitvectorType type = (BitvectorType) context.getFormulaManager().getFormulaType((BitvectorFormula) term); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op = (Expr) transform(args.get(1), model, vars); - return FpToBvExpr.of(roundingmode, op, type.getSize(), true); - }); - environment.put(Tuple2.of(FunctionDeclarationKind.FP_CASTTO_UBV, 2), (term, args, model, vars) -> { - BitvectorType type = (BitvectorType) context.getFormulaManager().getFormulaType((BitvectorFormula) term); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op = (Expr) transform(args.get(1), model, vars); - return FpToBvExpr.of(roundingmode, op, type.getSize(), false); - }); - environment.put(Tuple2.of(FunctionDeclarationKind.BV_SCASTTO_FP, 2), (term, args, model, vars) -> { - FloatingPointType type = (FloatingPointType) context.getFormulaManager().getFormulaType((FloatingPointFormula) term); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op = transform(args.get(1), model, vars); - if (op.getType() instanceof FpType) { - return FpToFpExpr.of(roundingmode, (Expr) op, type.getExponentSize(), type.getMantissaSize() + 1); - } else if (op.getType() instanceof BvType) { - return FpFromBvExpr.of(roundingmode, (Expr) op, FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), false); - } else { - throw new JavaSMTSolverException("Unsupported:" + op.getType()); - } - }); - environment.put(Tuple2.of(FunctionDeclarationKind.FP_CASTTO_FP, 2), (term, args, model, vars) -> { - FloatingPointType type = (FloatingPointType) context.getFormulaManager().getFormulaType((FloatingPointFormula) term); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op = transform(args.get(1), model, vars); - if (op.getType() instanceof FpType) { - return FpToFpExpr.of(roundingmode, (Expr) op, type.getExponentSize(), type.getMantissaSize() + 1); - } else if (op.getType() instanceof BvType) { - return FpFromBvExpr.of(roundingmode, (Expr) op, FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), false); - } else { - throw new JavaSMTSolverException("Unsupported:" + op.getType()); - } - }); - otherFuncs.put(Tuple2.of("to_fp", 1), (term, args, model, vars) -> { - FloatingPointType type = (FloatingPointType) context.getFormulaManager().getFormulaType((FloatingPointFormula) term); - final Expr op = (Expr) transform(args.get(0), model, vars); - return FpFromBvExpr.of(FpRoundingMode.getDefaultRoundingMode(), op, FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), true); - }); - - environment.put(Tuple2.of(FunctionDeclarationKind.BV_EXTRACT, 1), (term, args, model, vars) -> { - final Pattern pattern = Pattern.compile("extract ([0-9]+) ([0-9]+)"); - final String termStr = term.toString(); - final Matcher match = pattern.matcher(termStr); - if (match.find()) { - final int to = Integer.parseInt(match.group(1)) + 1; - final int from = Integer.parseInt(match.group(2)); - final Expr op = (Expr) transform(args.get(0), model, vars); - return BvExtractExpr.of(op, Int(from), Int(to)); - } - throw new JavaSMTSolverException("Not supported: " + term); - }); - environment.put(Tuple2.of(FunctionDeclarationKind.BV_ZERO_EXTENSION, 1), (term, args, model, vars) -> { - BitvectorType type = (BitvectorType) context.getFormulaManager().getFormulaType((BitvectorFormula) term); - final Expr op = (Expr) transform(args.get(0), model, vars); - return BvZExtExpr.of(op, BvType.of(type.getSize())); - }); - environment.put(Tuple2.of(FunctionDeclarationKind.BV_SIGN_EXTENSION, 1), (term, args, model, vars) -> { - BitvectorType type = (BitvectorType) context.getFormulaManager().getFormulaType((BitvectorFormula) term); - final Expr op = (Expr) transform(args.get(0), model, vars); - return BvSExtExpr.of(op, BvType.of(type.getSize())); - }); - environment.put(Tuple2.of(FunctionDeclarationKind.EQ_ZERO, 1), (term, args, model, vars) -> { - final Expr op = transform(args.get(0), model, vars); - return Eq(op, TypeUtils.getDefaultValue(op.getType())); - }); - otherFuncs.put(Tuple2.of("const", 1), (term, args, model, vars) -> transformLit(term, transform(args.get(0), model, vars))); - otherFuncs.put(Tuple2.of("fp", 3), (term, args, model, vars) -> { - final Expr op1 = (Expr) transform(args.get(0), model, vars); - final Expr op2 = (Expr) transform(args.get(1), model, vars); - final Expr op3 = (Expr) transform(args.get(2), model, vars); - return FpLitExpr.of((BvLitExpr) op1, (BvLitExpr) op2, (BvLitExpr) op3); - }); + addEnvFunc( + FunctionDeclarationKind.AND, + exprMultiaryOperator(hu.bme.mit.theta.core.type.booltype.AndExpr::create)); + // addEnvFunc("false", + // exprNullaryOperator(hu.bme.mit.theta.core.type.booltype.FalseExpr::getInstance)); + // addEnvFunc("true", + // exprNullaryOperator(hu.bme.mit.theta.core.type.booltype.TrueExpr::getInstance)); + addEnvFunc( + FunctionDeclarationKind.IFF, + exprBinaryOperator(hu.bme.mit.theta.core.type.booltype.IffExpr::create)); + addEnvFunc( + FunctionDeclarationKind.NOT, + exprUnaryOperator(hu.bme.mit.theta.core.type.booltype.NotExpr::create)); + addEnvFunc( + FunctionDeclarationKind.IMPLIES, + exprBinaryOperator(hu.bme.mit.theta.core.type.booltype.ImplyExpr::create)); + addEnvFunc( + FunctionDeclarationKind.XOR, + exprBinaryOperator(hu.bme.mit.theta.core.type.booltype.XorExpr::create)); + addEnvFunc( + FunctionDeclarationKind.OR, + exprMultiaryOperator(hu.bme.mit.theta.core.type.booltype.OrExpr::create)); + addEnvFunc( + FunctionDeclarationKind.ITE, + exprTernaryOperator(hu.bme.mit.theta.core.type.anytype.IteExpr::create)); + // addEnvFunc("if", + // exprTernaryOperator(hu.bme.mit.theta.core.type.anytype.IteExpr::create)); + // addEnvFunc("prime", + // exprUnaryOperator(hu.bme.mit.theta.core.type.anytype.PrimeExpr::of)); + addEnvFunc( + FunctionDeclarationKind.EQ, + exprBinaryOperator( + (expr, expr2) -> + expr.getType() instanceof FpType + ? FpAssign((Expr) expr, (Expr) expr2) + : Eq(expr, expr2))); + addEnvFunc( + FunctionDeclarationKind.GTE, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Geq)); + addEnvFunc( + FunctionDeclarationKind.GT, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Gt)); + addEnvFunc( + FunctionDeclarationKind.LTE, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Leq)); + addEnvFunc( + FunctionDeclarationKind.LT, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Lt)); + addEnvFunc( + FunctionDeclarationKind.ADD, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Add)); + addEnvFunc( + FunctionDeclarationKind.SUB, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Sub)); + addEnvFunc( + FunctionDeclarationKind.ADD, + exprUnaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Pos)); + addEnvFunc( + FunctionDeclarationKind.UMINUS, + exprUnaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Neg)); + addEnvFunc( + FunctionDeclarationKind.MUL, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Mul)); + addEnvFunc( + FunctionDeclarationKind.DIV, + exprBinaryOperator(hu.bme.mit.theta.core.type.abstracttype.AbstractExprs::Div)); + addEnvFunc( + FunctionDeclarationKind.FLOOR, + exprUnaryOperator(hu.bme.mit.theta.core.type.rattype.RatToIntExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_ROUND_TO_INTEGRAL, + exprUnaryOperator(hu.bme.mit.theta.core.type.rattype.RatToIntExpr::create)); + // addEnvFunc("div", + // exprBinaryOperator(hu.bme.mit.theta.core.type.inttype.IntDivExpr::create)); + addEnvFunc( + FunctionDeclarationKind.TO_REAL, + exprUnaryOperator(hu.bme.mit.theta.core.type.inttype.IntToRatExpr::create)); + addEnvFunc( + FunctionDeclarationKind.MODULO, + exprBinaryOperator(hu.bme.mit.theta.core.type.inttype.IntModExpr::create)); + // addEnvFunc("rem", + // exprBinaryOperator(hu.bme.mit.theta.core.type.inttype.IntRemExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_ADD, + exprFpMultiaryOperator(hu.bme.mit.theta.core.type.fptype.FpAddExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_SUB, + exprFpBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpSubExpr::create)); + // addEnvFunc("fp.pos", + // exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpPosExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_NEG, + exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpNegExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_MUL, + exprFpMultiaryOperator(hu.bme.mit.theta.core.type.fptype.FpMulExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_DIV, + exprFpBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpDivExpr::create)); + addOtherFunc( + "fp.rem", exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpRemExpr::create)); + addOtherFunc( + "fprem", exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpRemExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_ABS, + exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpAbsExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_LE, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpLeqExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_LT, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpLtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_GE, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpGeqExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_GT, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpGtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_EQ, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpEqExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_IS_NAN, + exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsNanExpr::create)); + // addEnvFunc("fp.isNaN", + // exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsNanExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_IS_INF, + exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsInfiniteExpr::create)); + // addEnvFunc("fp.isInfinite", + // exprUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpIsInfiniteExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_ROUND_TO_INTEGRAL, + exprFpUnaryOperator( + hu.bme.mit.theta.core.type.fptype.FpRoundToIntegralExpr::create)); + // addEnvFunc("fp.roundToIntegral", + // exprFpUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpRoundToIntegralExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_SQRT, + exprFpUnaryOperator(hu.bme.mit.theta.core.type.fptype.FpSqrtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_MAX, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpMaxExpr::create)); + addEnvFunc( + FunctionDeclarationKind.FP_MIN, + exprBinaryOperator(hu.bme.mit.theta.core.type.fptype.FpMinExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_CONCAT, + exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvConcatExpr::create)); + // addEnvFunc("concat", + // exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvConcatExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_ADD, + exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvAddExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SUB, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSubExpr::create)); + // addEnvFunc("bvpos", + // exprUnaryOperator(hu.bme.mit.theta.core.type.bvtype.BvPosExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_NEG, + exprUnaryOperator(hu.bme.mit.theta.core.type.bvtype.BvNegExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_MUL, + exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvMulExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_UDIV, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvUDivExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SDIV, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSDivExpr::create)); + addOtherFunc( + "bvsmod", exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSModExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_UREM, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvURemExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SREM, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSRemExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_OR, + exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvOrExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_AND, + exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvAndExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_XOR, + exprMultiaryOperator(hu.bme.mit.theta.core.type.bvtype.BvXorExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_NOT, + exprUnaryOperator(hu.bme.mit.theta.core.type.bvtype.BvNotExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SHL, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvShiftLeftExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_ASHR, + exprBinaryOperator( + hu.bme.mit.theta.core.type.bvtype.BvArithShiftRightExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_LSHR, + exprBinaryOperator( + hu.bme.mit.theta.core.type.bvtype.BvLogicShiftRightExpr::create)); + // addEnvFunc("bvrol", + // exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr::create)); + addOtherFunc( + "ext_rotate_left", + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateLeftExpr::create)); + // addEnvFunc("bvror", + // exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr::create)); + addOtherFunc( + "ext_rotate_right", + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvRotateRightExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_ULT, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvULtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_ULE, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvULeqExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_UGT, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvUGtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_UGE, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvUGeqExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SLT, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSLtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SLE, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSLeqExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SGT, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSGtExpr::create)); + addEnvFunc( + FunctionDeclarationKind.BV_SGE, + exprBinaryOperator(hu.bme.mit.theta.core.type.bvtype.BvSGeqExpr::create)); + // addEnvFunc("read", + // exprBinaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr::create)); + // addEnvFunc("write", + // exprTernaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr::create)); + addEnvFunc( + FunctionDeclarationKind.SELECT, + exprBinaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr::create)); + addEnvFunc( + FunctionDeclarationKind.STORE, + exprTernaryOperator(hu.bme.mit.theta.core.type.arraytype.ArrayWriteExpr::create)); + + environment.put( + Tuple2.of(FunctionDeclarationKind.FP_FROM_IEEEBV, 1), + (term, args, model, vars) -> { + FloatingPointType type = + (FloatingPointType) + context.getFormulaManager() + .getFormulaType((FloatingPointFormula) term); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op = (Expr) transform(args.get(1), model, vars); + return FpFromBvExpr.of( + roundingmode, + op, + FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), + true); + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.FP_CASTTO_SBV, 2), + (term, args, model, vars) -> { + BitvectorType type = + (BitvectorType) + context.getFormulaManager() + .getFormulaType((BitvectorFormula) term); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op = (Expr) transform(args.get(1), model, vars); + return FpToBvExpr.of(roundingmode, op, type.getSize(), true); + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.FP_CASTTO_UBV, 2), + (term, args, model, vars) -> { + BitvectorType type = + (BitvectorType) + context.getFormulaManager() + .getFormulaType((BitvectorFormula) term); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op = (Expr) transform(args.get(1), model, vars); + return FpToBvExpr.of(roundingmode, op, type.getSize(), false); + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.BV_SCASTTO_FP, 2), + (term, args, model, vars) -> { + FloatingPointType type = + (FloatingPointType) + context.getFormulaManager() + .getFormulaType((FloatingPointFormula) term); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op = transform(args.get(1), model, vars); + if (op.getType() instanceof FpType) { + return FpToFpExpr.of( + roundingmode, + (Expr) op, + type.getExponentSize(), + type.getMantissaSize() + 1); + } else if (op.getType() instanceof BvType) { + return FpFromBvExpr.of( + roundingmode, + (Expr) op, + FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), + false); + } else { + throw new JavaSMTSolverException("Unsupported:" + op.getType()); + } + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.FP_CASTTO_FP, 2), + (term, args, model, vars) -> { + FloatingPointType type = + (FloatingPointType) + context.getFormulaManager() + .getFormulaType((FloatingPointFormula) term); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op = transform(args.get(1), model, vars); + if (op.getType() instanceof FpType) { + return FpToFpExpr.of( + roundingmode, + (Expr) op, + type.getExponentSize(), + type.getMantissaSize() + 1); + } else if (op.getType() instanceof BvType) { + return FpFromBvExpr.of( + roundingmode, + (Expr) op, + FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), + false); + } else { + throw new JavaSMTSolverException("Unsupported:" + op.getType()); + } + }); + otherFuncs.put( + Tuple2.of("to_fp", 1), + (term, args, model, vars) -> { + FloatingPointType type = + (FloatingPointType) + context.getFormulaManager() + .getFormulaType((FloatingPointFormula) term); + final Expr op = (Expr) transform(args.get(0), model, vars); + return FpFromBvExpr.of( + FpRoundingMode.getDefaultRoundingMode(), + op, + FpType.of(type.getExponentSize(), type.getMantissaSize() + 1), + true); + }); + + environment.put( + Tuple2.of(FunctionDeclarationKind.BV_EXTRACT, 1), + (term, args, model, vars) -> { + final Pattern pattern = Pattern.compile("extract ([0-9]+) ([0-9]+)"); + final String termStr = term.toString(); + final Matcher match = pattern.matcher(termStr); + if (match.find()) { + final int to = Integer.parseInt(match.group(1)) + 1; + final int from = Integer.parseInt(match.group(2)); + final Expr op = (Expr) transform(args.get(0), model, vars); + return BvExtractExpr.of(op, Int(from), Int(to)); + } + throw new JavaSMTSolverException("Not supported: " + term); + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.BV_ZERO_EXTENSION, 1), + (term, args, model, vars) -> { + BitvectorType type = + (BitvectorType) + context.getFormulaManager() + .getFormulaType((BitvectorFormula) term); + final Expr op = (Expr) transform(args.get(0), model, vars); + return BvZExtExpr.of(op, BvType.of(type.getSize())); + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.BV_SIGN_EXTENSION, 1), + (term, args, model, vars) -> { + BitvectorType type = + (BitvectorType) + context.getFormulaManager() + .getFormulaType((BitvectorFormula) term); + final Expr op = (Expr) transform(args.get(0), model, vars); + return BvSExtExpr.of(op, BvType.of(type.getSize())); + }); + environment.put( + Tuple2.of(FunctionDeclarationKind.EQ_ZERO, 1), + (term, args, model, vars) -> { + final Expr op = transform(args.get(0), model, vars); + return Eq(op, TypeUtils.getDefaultValue(op.getType())); + }); + otherFuncs.put( + Tuple2.of("const", 1), + (term, args, model, vars) -> + transformLit(term, transform(args.get(0), model, vars))); + otherFuncs.put( + Tuple2.of("fp", 3), + (term, args, model, vars) -> { + final Expr op1 = (Expr) transform(args.get(0), model, vars); + final Expr op2 = (Expr) transform(args.get(1), model, vars); + final Expr op3 = (Expr) transform(args.get(2), model, vars); + return FpLitExpr.of((BvLitExpr) op1, (BvLitExpr) op2, (BvLitExpr) op3); + }); } - private void addEnvFunc(FunctionDeclarationKind declarationKind, Tuple2, Model, List>, Expr>> func) { - checkArgument(!environment.containsKey(Tuple2.of(declarationKind, func.get1())), "Duplicate key: " + Tuple2.of(declarationKind, func.get1())); + private void addEnvFunc( + FunctionDeclarationKind declarationKind, + Tuple2, Model, List>, Expr>> + func) { + checkArgument( + !environment.containsKey(Tuple2.of(declarationKind, func.get1())), + "Duplicate key: " + Tuple2.of(declarationKind, func.get1())); environment.put(Tuple2.of(declarationKind, func.get1()), func.get2()); } - private void addOtherFunc(String name, Tuple2, Model, List>, Expr>> func) { - checkArgument(!otherFuncs.containsKey(Tuple2.of(name, func.get1())), "Duplicate key: " + Tuple2.of(name, func.get1())); + private void addOtherFunc( + String name, + Tuple2, Model, List>, Expr>> + func) { + checkArgument( + !otherFuncs.containsKey(Tuple2.of(name, func.get1())), + "Duplicate key: " + Tuple2.of(name, func.get1())); otherFuncs.put(Tuple2.of(name, func.get1()), func.get2()); } @@ -295,36 +543,49 @@ public Expr toExpr(final Formula term) { //////// - private Expr transform(final Formula term, final Model model, - final List> vars) { + private Expr transform(final Formula term, final Model model, final List> vars) { try { - return context.getFormulaManager().visit(term, new FormulaVisitor<>() { - @Override - public Expr visitFreeVariable(Formula f, String name) { - return transformVar(f, name, vars); - } - - @Override - public Expr visitBoundVariable(Formula f, int deBruijnIdx) { - return Lists.reverse(vars).get(deBruijnIdx).getRef(); // I think the reverse list is necessary here. - } - - @Override - public Expr visitConstant(Formula f, Object value) { - return transformLit(f, value); - } - - @Override - public Expr visitFunction(Formula f, List args, FunctionDeclaration functionDeclaration) { - return transformApp(f, functionDeclaration, args, model, vars); - } - - @Override - public Expr visitQuantifier(BooleanFormula f, Quantifier quantifier, List boundVariables, BooleanFormula body) { - return transformQuantifier(quantifier, boundVariables, model, body, vars); - } - }); + return context.getFormulaManager() + .visit( + term, + new FormulaVisitor<>() { + @Override + public Expr visitFreeVariable(Formula f, String name) { + return transformVar(f, name, vars); + } + + @Override + public Expr visitBoundVariable(Formula f, int deBruijnIdx) { + return Lists.reverse(vars) + .get(deBruijnIdx) + .getRef(); // I think the reverse list is necessary + // here. + } + + @Override + public Expr visitConstant(Formula f, Object value) { + return transformLit(f, value); + } + + @Override + public Expr visitFunction( + Formula f, + List args, + FunctionDeclaration functionDeclaration) { + return transformApp(f, functionDeclaration, args, model, vars); + } + + @Override + public Expr visitQuantifier( + BooleanFormula f, + Quantifier quantifier, + List boundVariables, + BooleanFormula body) { + return transformQuantifier( + quantifier, boundVariables, model, body, vars); + } + }); } catch (JavaSMTSolverException e) { throw new JavaSMTSolverException("Not supported: " + term, e); } @@ -333,23 +594,53 @@ public Expr visitQuantifier(BooleanFormula f, Quantifier quantifier, List transformLit(Formula f, Object value) { FormulaType type = context.getFormulaManager().getFormulaType(f); if (type.isIntegerType()) { - checkArgument(value instanceof BigInteger, "Type mismatch (Expected BigInteger): " + value + " (" + value.getClass().getSimpleName() + ")"); + checkArgument( + value instanceof BigInteger, + "Type mismatch (Expected BigInteger): " + + value + + " (" + + value.getClass().getSimpleName() + + ")"); return transformIntLit(f, (BigInteger) value); } else if (type.isRationalType()) { - checkArgument(value instanceof Rational || value instanceof BigInteger, "Type mismatch (Expected Rational or BigInteger): " + value + " (" + value.getClass().getSimpleName() + ")"); + checkArgument( + value instanceof Rational || value instanceof BigInteger, + "Type mismatch (Expected Rational or BigInteger): " + + value + + " (" + + value.getClass().getSimpleName() + + ")"); if (value instanceof Rational) { return transformRatLit(f, (Rational) value); } else if (value instanceof BigInteger) { return transformRatLit(f, (BigInteger) value); } } else if (type.isBitvectorType()) { - checkArgument(value instanceof BigInteger, "Type mismatch (Expected BigInteger): " + value + " (" + value.getClass().getSimpleName() + ")"); + checkArgument( + value instanceof BigInteger, + "Type mismatch (Expected BigInteger): " + + value + + " (" + + value.getClass().getSimpleName() + + ")"); return transformBvLit(f, (BigInteger) value); } else if (type.isFloatingPointType()) { - checkArgument(value instanceof FloatingPointNumber, "Type mismatch (Expected FloatingPointNumber): " + value + " (" + value.getClass().getSimpleName() + ")"); + checkArgument( + value instanceof FloatingPointNumber, + "Type mismatch (Expected FloatingPointNumber): " + + value + + " (" + + value.getClass().getSimpleName() + + ")"); return transformFpLit((FloatingPointNumber) value); } else if (type.isArrayType()) { - checkArgument(value instanceof Expr, "Typ mismatch (Expected Expr): " + value + " (" + value.getClass().getSimpleName() + ")"); + checkArgument( + value instanceof Expr, + "Typ mismatch (Expected Expr): " + + value + + " (" + + value.getClass().getSimpleName() + + ")"); return transformArrLit(f, (Expr) value); } else if (type.isBooleanType()) { if (Boolean.TRUE.equals(value)) { @@ -376,7 +667,8 @@ private Expr transformRatLit(final Formula term, Rational value) { } private Expr transformArrLit(final Formula term, Expr value) { - final ArrayType type = (ArrayType) transformType(context.getFormulaManager().getFormulaType(term)); + final ArrayType type = + (ArrayType) transformType(context.getFormulaManager().getFormulaType(term)); if (value instanceof LitExpr) { return ArrayLitExpr.of(List.of(), value, type); } else { @@ -386,7 +678,8 @@ private Expr transformArrLit(final Formula term, Expr val private Expr transformBvLit(final Formula term, BigInteger value) { final var bvNum = (BitvectorFormula) term; - BitvectorType formulaType = (BitvectorType) context.getFormulaManager().getFormulaType(bvNum); + BitvectorType formulaType = + (BitvectorType) context.getFormulaManager().getFormulaType(bvNum); return BvUtils.bigIntegerToNeutralBvLitExpr(value, formulaType.getSize()); } @@ -398,10 +691,12 @@ private Expr transformFpLit(FloatingPointNumber value) { BvUtils.bigIntegerToNeutralBvLitExpr(value.getMantissa(), value.getMantissaSize())); } - private Expr transformApp(Formula f, final FunctionDeclaration funcDecl, - final List args, - final Model model, - final List> vars) { + private Expr transformApp( + Formula f, + final FunctionDeclaration funcDecl, + final List args, + final Model model, + final List> vars) { final var key1 = Tuple2.of(funcDecl.getKind(), args.size()); final var key2 = Tuple2.of(funcDecl.getKind(), -1); @@ -416,27 +711,44 @@ private Expr transformApp(Formula f, final FunctionDeclaration funcDecl, } else if (otherFuncs.containsKey(key4)) { return otherFuncs.get(key4).apply(f, args, model, vars); } else { - final var paramExprs = args.stream().map((Formula term) -> (Expr) toExpr(term)).toList(); + final var paramExprs = + args.stream().map((Formula term) -> (Expr) toExpr(term)).toList(); final Expr> funcExpr; if (symbolTable.definesSymbol(funcDecl)) { - funcExpr = (Expr>) checkNotNull(symbolTable.getConst(funcDecl).getRef()); + funcExpr = + (Expr>) + checkNotNull(symbolTable.getConst(funcDecl).getRef()); } else { - funcExpr = Const(funcDecl.getName(), getFuncType( - transformType(context.getFormulaManager().getFormulaType(f)), - args.stream().map(context.getFormulaManager()::getFormulaType).map(this::transformType).toList() - )).getRef(); + funcExpr = + Const( + funcDecl.getName(), + getFuncType( + transformType( + context.getFormulaManager() + .getFormulaType(f)), + args.stream() + .map( + context.getFormulaManager() + ::getFormulaType) + .map(this::transformType) + .toList())) + .getRef(); } return FuncExprs.App(funcExpr, paramExprs); } } - private

FuncType getFuncType(final R resultType, final List

paramTypes) { + private

FuncType getFuncType( + final R resultType, final List

paramTypes) { if (paramTypes.size() == 1) { return FuncType.of(paramTypes.get(0), resultType); } else { - return (FuncType) FuncType.of(paramTypes.get(0), getFuncType(resultType, paramTypes.subList(1, paramTypes.size()))); + return (FuncType) + FuncType.of( + paramTypes.get(0), + getFuncType(resultType, paramTypes.subList(1, paramTypes.size()))); } } @@ -446,13 +758,15 @@ private ParamDecl transformParam(Formula term) { return Param(term.toString(), thetaType); } - private Expr transformQuantifier(final Quantifier term, final List boundVars, - final Model model, final BooleanFormula body, final List> vars) { + private Expr transformQuantifier( + final Quantifier term, + final List boundVars, + final Model model, + final BooleanFormula body, + final List> vars) { - final List> params = boundVars - .stream() - .map(this::transformParam) - .collect(Collectors.toList()); + final List> params = + boundVars.stream().map(this::transformParam).collect(Collectors.toList()); final Expr ret; pushParams(vars, params); @@ -512,114 +826,146 @@ private Type transformType(FormulaType type) { //// - private Tuple2, Model, List>, Expr>> exprNullaryOperator( - final Supplier> function) { - return Tuple2.of(0, (term, args, model, vars) -> { - checkArgument(args.isEmpty(), "Number of arguments must be zero"); - return function.get(); - }); + private Tuple2, Model, List>, Expr>> + exprNullaryOperator(final Supplier> function) { + return Tuple2.of( + 0, + (term, args, model, vars) -> { + checkArgument(args.isEmpty(), "Number of arguments must be zero"); + return function.get(); + }); } - private Tuple2, Model, List>, Expr>> exprUnaryOperator( - final UnaryOperator> function) { - return Tuple2.of(1, (term, args, model, vars) -> { - checkArgument(args.size() == 1, "Number of arguments must be one"); - final Expr op = transform(args.get(0), model, vars); - return function.apply(op); - }); + private Tuple2, Model, List>, Expr>> + exprUnaryOperator(final UnaryOperator> function) { + return Tuple2.of( + 1, + (term, args, model, vars) -> { + checkArgument(args.size() == 1, "Number of arguments must be one"); + final Expr op = transform(args.get(0), model, vars); + return function.apply(op); + }); } - private Tuple2, Model, List>, Expr>> exprBinaryOperator( - final BinaryOperator> function) { - return Tuple2.of(2, (term, args, model, vars) -> { - checkArgument(args.size() == 2, "Number of arguments must be two"); - if (context.getFormulaManager().getFormulaType(args.get(0)).isEnumerationType()) { - // binary operator is on enum types - // if either arg is a literal, we need special handling to get its type - int litIndex = -1; - for (int i = 0; i < 2; i++) { - if (context.getFormulaManager().extractVariables(args.get(i)).isEmpty()) { - litIndex = i; + private Tuple2, Model, List>, Expr>> + exprBinaryOperator(final BinaryOperator> function) { + return Tuple2.of( + 2, + (term, args, model, vars) -> { + checkArgument(args.size() == 2, "Number of arguments must be two"); + if (context.getFormulaManager() + .getFormulaType(args.get(0)) + .isEnumerationType()) { + // binary operator is on enum types + // if either arg is a literal, we need special handling to get its type + int litIndex = -1; + for (int i = 0; i < 2; i++) { + if (context.getFormulaManager() + .extractVariables(args.get(i)) + .isEmpty()) { + litIndex = i; + } + } + if (litIndex > -1) { + // one is a literal + int refIndex = Math.abs(litIndex - 1); + final Expr refOp = transform(args.get(refIndex), model, vars); + final Expr litExpr = + transformEnumLit( + args.get(litIndex), (EnumType) refOp.getType()); + return function.apply(refOp, litExpr); + } } - } - if (litIndex > -1) { - // one is a literal - int refIndex = Math.abs(litIndex - 1); - final Expr refOp = transform(args.get(refIndex), model, vars); - final Expr litExpr = transformEnumLit(args.get(litIndex), (EnumType) refOp.getType()); - return function.apply(refOp, litExpr); - } - } - final Expr op1 = transform(args.get(0), model, vars); - final Expr op2 = transform(args.get(1), model, vars); - return function.apply(op1, op2); - }); + final Expr op1 = transform(args.get(0), model, vars); + final Expr op2 = transform(args.get(1), model, vars); + return function.apply(op1, op2); + }); } private Expr transformEnumLit(Formula formula, EnumType type) { return EnumLitExpr.of(type, EnumType.getShortName(formula.toString())); } - private Tuple2, Model, List>, Expr>> exprTernaryOperator( - final TernaryOperator> function) { - return Tuple2.of(3, (term, args, model, vars) -> { - checkArgument(args.size() == 3, "Number of arguments must be three"); - final Expr op1 = transform(args.get(0), model, vars); - final Expr op2 = transform(args.get(1), model, vars); - final Expr op3 = transform(args.get(2), model, vars); - return function.apply(op1, op2, op3); - }); + private Tuple2, Model, List>, Expr>> + exprTernaryOperator(final TernaryOperator> function) { + return Tuple2.of( + 3, + (term, args, model, vars) -> { + checkArgument(args.size() == 3, "Number of arguments must be three"); + final Expr op1 = transform(args.get(0), model, vars); + final Expr op2 = transform(args.get(1), model, vars); + final Expr op3 = transform(args.get(2), model, vars); + return function.apply(op1, op2, op3); + }); } - private Tuple2, Model, List>, Expr>> exprMultiaryOperator( - final Function>, Expr> function) { - return Tuple2.of(-1, (term, args, model, vars) -> { - final List> ops = args.stream().map(arg -> transform(arg, model, vars)) - .collect(toImmutableList()); - return function.apply(ops); - }); + private Tuple2, Model, List>, Expr>> + exprMultiaryOperator(final Function>, Expr> function) { + return Tuple2.of( + -1, + (term, args, model, vars) -> { + final List> ops = + args.stream() + .map(arg -> transform(arg, model, vars)) + .collect(toImmutableList()); + return function.apply(ops); + }); } - - private Tuple2, Model, List>, Expr>> exprFpUnaryOperator( - final BiFunction, Expr> function) { - return Tuple2.of(2, (term, args, model, vars) -> { - checkArgument(args.size() == 2, "Number of arguments must be two"); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op2 = transform(args.get(1), model, vars); - return function.apply(roundingmode, op2); - }); + private Tuple2, Model, List>, Expr>> + exprFpUnaryOperator(final BiFunction, Expr> function) { + return Tuple2.of( + 2, + (term, args, model, vars) -> { + checkArgument(args.size() == 2, "Number of arguments must be two"); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op2 = transform(args.get(1), model, vars); + return function.apply(roundingmode, op2); + }); } - private Tuple2, Model, List>, Expr>> exprFpBinaryOperator( - final TriFunction, Expr, Expr> function) { - return Tuple2.of(3, (term, args, model, vars) -> { - checkArgument(args.size() == 3, "Number of arguments must be three"); - final var roundingmode = getRoundingMode(args.get(0).toString()); - final Expr op1 = transform(args.get(1), model, vars); - final Expr op2 = transform(args.get(2), model, vars); - return function.apply(roundingmode, op1, op2); - }); + private Tuple2, Model, List>, Expr>> + exprFpBinaryOperator( + final TriFunction, Expr, Expr> function) { + return Tuple2.of( + 3, + (term, args, model, vars) -> { + checkArgument(args.size() == 3, "Number of arguments must be three"); + final var roundingmode = getRoundingMode(args.get(0).toString()); + final Expr op1 = transform(args.get(1), model, vars); + final Expr op2 = transform(args.get(2), model, vars); + return function.apply(roundingmode, op1, op2); + }); } - private Tuple2, Model, List>, Expr>> exprFpMultiaryOperator( - final BiFunction>, Expr> function) { - return Tuple2.of(-1, (term, args, model, vars) -> { - final var roundingmode = getRoundingMode(args.get(0).toString()); - final List> ops = args.stream().skip(1).map(arg -> transform(arg, model, vars)) - .collect(toImmutableList()); - return function.apply(roundingmode, ops); - }); + private Tuple2, Model, List>, Expr>> + exprFpMultiaryOperator( + final BiFunction>, Expr> function) { + return Tuple2.of( + -1, + (term, args, model, vars) -> { + final var roundingmode = getRoundingMode(args.get(0).toString()); + final List> ops = + args.stream() + .skip(1) + .map(arg -> transform(arg, model, vars)) + .collect(toImmutableList()); + return function.apply(roundingmode, ops); + }); } - private Tuple2, Model, List>, Expr>> exprFpLitUnaryOperator( - final BiFunction> function) { - return Tuple2.of(3, (term, args, model, vars) -> { - final BvLitExpr op1 = (BvLitExpr) transform(args.get(0), model, vars); - final IntLitExpr op2 = (IntLitExpr) transform(args.get(1), model, vars); - final IntLitExpr op3 = (IntLitExpr) transform(args.get(2), model, vars); - return function.apply(op1, FpType.of(op2.getValue().intValue(), op3.getValue().intValue() + 1)); - }); + private Tuple2, Model, List>, Expr>> + exprFpLitUnaryOperator(final BiFunction> function) { + return Tuple2.of( + 3, + (term, args, model, vars) -> { + final BvLitExpr op1 = (BvLitExpr) transform(args.get(0), model, vars); + final IntLitExpr op2 = (IntLitExpr) transform(args.get(1), model, vars); + final IntLitExpr op3 = (IntLitExpr) transform(args.get(2), model, vars); + return function.apply( + op1, + FpType.of(op2.getValue().intValue(), op3.getValue().intValue() + 1)); + }); } private FpRoundingMode getRoundingMode(String s) { @@ -630,7 +976,4 @@ private FpRoundingMode getRoundingMode(String s) { default -> throw new JavaSMTSolverException("Unexpected value: " + s); }; } - - } - diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformationManager.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformationManager.java index 0b3f45224f..fad47f576c 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformationManager.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,7 +28,8 @@ final class JavaSMTTransformationManager { private final JavaSMTDeclTransformer declTransformer; private final JavaSMTExprTransformer exprTransformer; - public JavaSMTTransformationManager(final JavaSMTSymbolTable symbolTable, final SolverContext context) { + public JavaSMTTransformationManager( + final JavaSMTSymbolTable symbolTable, final SolverContext context) { this.typeTransformer = new JavaSMTTypeTransformer(context); this.declTransformer = new JavaSMTDeclTransformer(this, symbolTable, context); this.exprTransformer = new JavaSMTExprTransformer(this, symbolTable, context); diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTypeTransformer.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTypeTransformer.java index 8f994c4ca0..02107c5928 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTypeTransformer.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTypeTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,6 +23,8 @@ import hu.bme.mit.theta.core.type.fptype.FpType; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatType; +import java.util.HashMap; +import java.util.Map; import org.sosy_lab.java_smt.api.BooleanFormula; import org.sosy_lab.java_smt.api.EnumerationFormula; import org.sosy_lab.java_smt.api.FormulaType; @@ -30,9 +32,6 @@ import org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula; import org.sosy_lab.java_smt.api.SolverContext; -import java.util.HashMap; -import java.util.Map; - final class JavaSMTTypeTransformer { private final SolverContext solverContext; @@ -57,12 +56,17 @@ public FormulaType toSort(final Type type) { } else if (type instanceof RatType) { return realSort; } else if (type instanceof EnumType enumType) { - return enumSorts.computeIfAbsent(enumType.getName(), name -> solverContext.getFormulaManager().getEnumerationFormulaManager().declareEnumeration(name, enumType.getLongValues())); + return enumSorts.computeIfAbsent( + enumType.getName(), + name -> + solverContext + .getFormulaManager() + .getEnumerationFormulaManager() + .declareEnumeration(name, enumType.getLongValues())); } else if (type instanceof BvType bvType) { return FormulaType.getBitvectorTypeWithSize(bvType.getSize()); } else if (type instanceof FpType fpType) { - return FormulaType.getFloatingPointType(fpType.getExponent(), - fpType.getSignificand()); + return FormulaType.getFloatingPointType(fpType.getExponent(), fpType.getSignificand()); } else if (type instanceof ArrayType arrayType) { final FormulaType indexSort = toSort(arrayType.getIndexType()); final FormulaType elemSort = toSort(arrayType.getElemType()); @@ -72,5 +76,4 @@ public FormulaType toSort(final Type type) { "Unsupported type: " + type.getClass().getSimpleName()); } } - } diff --git a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagator.java b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagator.java index 21557f501b..a55337afcb 100644 --- a/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagator.java +++ b/subprojects/solver/solver-javasmt/src/main/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import org.sosy_lab.java_smt.api.BooleanFormula; -import org.sosy_lab.java_smt.api.Formula; -import org.sosy_lab.java_smt.api.PropagatorBackend; -import org.sosy_lab.java_smt.basicimpl.AbstractUserPropagator; - import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; @@ -30,10 +28,10 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Function; - -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import org.sosy_lab.java_smt.api.BooleanFormula; +import org.sosy_lab.java_smt.api.Formula; +import org.sosy_lab.java_smt.api.PropagatorBackend; +import org.sosy_lab.java_smt.basicimpl.AbstractUserPropagator; public abstract class JavaSMTUserPropagator extends AbstractUserPropagator { private Function, Formula> toTerm; @@ -59,33 +57,34 @@ protected final PropagatorBackend getBackend() { } /** - * Gets called when the solver decides on the value for a bool expression. - * Can call propagate* calls from here. - * When overriding, no need to call super. + * Gets called when the solver decides on the value for a bool expression. Can call propagate* + * calls from here. When overriding, no need to call super. * - * @param expr The expression for which a value became available + * @param expr The expression for which a value became available * @param value The value of the expression */ - public void onKnownValue(final Expr expr, final boolean value) { - } + public void onKnownValue(final Expr expr, final boolean value) {} @Override public final void onKnownValue(final BooleanFormula expr, final boolean value) { super.onKnownValue(expr, value); - final var entry = registeredTerms.entrySet().stream().filter(e -> e.getValue().equals(expr)).findAny(); - final var tExpr = entry.isPresent() ? entry.get().getKey() : cast(toExpr.apply(expr), Bool()); + final var entry = + registeredTerms.entrySet().stream() + .filter(e -> e.getValue().equals(expr)) + .findAny(); + final var tExpr = + entry.isPresent() ? entry.get().getKey() : cast(toExpr.apply(expr), Bool()); onKnownValue(tExpr, value); } /** - * Gets called when a branching is done on a registered expression. - * Change the decision by calling propagateNextDecision. + * Gets called when a branching is done on a registered expression. Change the decision by + * calling propagateNextDecision. * * @param expr * @param value */ - public void onDecision(final Expr expr, final boolean value) { - } + public void onDecision(final Expr expr, final boolean value) {} @Override public final void onDecision(final BooleanFormula expr, final boolean value) { @@ -124,19 +123,26 @@ public final void propagateConflict(final List> exprs) { getBackend().propagateConflict(terms); } - public final void propagateConsequence(final List> exprs, final Expr consequence) { + public final void propagateConsequence( + final List> exprs, final Expr consequence) { final var terms = exprs.stream().map(registeredTerms::get).toArray(BooleanFormula[]::new); for (var expr : exprs) { if (registeredTerms.get(expr) == null) { System.err.println(expr); } } - checkState(Arrays.stream(terms).noneMatch(Objects::isNull), "Registered terms failed to look up one or more expressions from %s. Registered terms: %s", exprs, registeredTerms.keySet()); + checkState( + Arrays.stream(terms).noneMatch(Objects::isNull), + "Registered terms failed to look up one or more expressions from %s. Registered" + + " terms: %s", + exprs, + registeredTerms.keySet()); final BooleanFormula consequenceTerm = (BooleanFormula) toTerm.apply(consequence); getBackend().propagateConsequence(terms, consequenceTerm); } - public final boolean propagateNextDecision(final Expr formula, Optional optional) { + public final boolean propagateNextDecision( + final Expr formula, Optional optional) { final BooleanFormula term = (BooleanFormula) toTerm.apply(formula); return getBackend().propagateNextDecision(term, optional); } diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolverTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolverTest.java index b36c03622d..77afdba341 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolverTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTItpSolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,24 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Neq; +import static hu.bme.mit.theta.solver.ItpMarkerTree.Leaf; +import static hu.bme.mit.theta.solver.ItpMarkerTree.Subtree; +import static hu.bme.mit.theta.solver.ItpMarkerTree.Tree; +import static org.junit.Assume.assumeFalse; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.OsHelper.OperatingSystem; @@ -30,6 +48,8 @@ import hu.bme.mit.theta.solver.ItpPattern; import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; +import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -39,31 +59,11 @@ import org.junit.runners.Parameterized.Parameters; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; -import java.util.List; - -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Neq; -import static hu.bme.mit.theta.solver.ItpMarkerTree.Leaf; -import static hu.bme.mit.theta.solver.ItpMarkerTree.Subtree; -import static hu.bme.mit.theta.solver.ItpMarkerTree.Tree; -import static org.junit.Assume.assumeFalse; - @RunWith(Parameterized.class) public final class JavaSMTItpSolverTest { @Parameter(0) public Solvers solver; + @Parameter(1) public ItpSolver itpSolver; @@ -75,20 +75,36 @@ public final class JavaSMTItpSolverTest { Expr> f; Expr> g; - @Parameters(name = "solver: {0}") public static Collection operations() { if (OsHelper.getOs().equals(OperatingSystem.LINUX)) { return List.of( - new Object[]{Solvers.SMTINTERPOL, JavaSMTSolverFactory.create(Solvers.SMTINTERPOL, new String[]{}).createItpSolver()}, - new Object[]{Solvers.PRINCESS, JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[]{}).createItpSolver()}, - new Object[]{Solvers.CVC5, JavaSMTSolverFactory.create(Solvers.CVC5, new String[]{}).createItpSolver()} - ); + new Object[] { + Solvers.SMTINTERPOL, + JavaSMTSolverFactory.create(Solvers.SMTINTERPOL, new String[] {}) + .createItpSolver() + }, + new Object[] { + Solvers.PRINCESS, + JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[] {}) + .createItpSolver() + }, + new Object[] { + Solvers.CVC5, + JavaSMTSolverFactory.create(Solvers.CVC5, new String[] {}).createItpSolver() + }); } else { return List.of( - new Object[]{Solvers.SMTINTERPOL, JavaSMTSolverFactory.create(Solvers.SMTINTERPOL, new String[]{}).createItpSolver()}, - new Object[]{Solvers.PRINCESS, JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[]{}).createItpSolver()} - ); + new Object[] { + Solvers.SMTINTERPOL, + JavaSMTSolverFactory.create(Solvers.SMTINTERPOL, new String[] {}) + .createItpSolver() + }, + new Object[] { + Solvers.PRINCESS, + JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[] {}) + .createItpSolver() + }); } } @@ -167,8 +183,8 @@ public void testTreeInterpolation() { final ItpMarker I3 = itpSolver.createMarker(); final ItpMarker I4 = itpSolver.createMarker(); final ItpMarker I5 = itpSolver.createMarker(); - final ItpPattern pattern = itpSolver.createTreePattern( - Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); + final ItpPattern pattern = + itpSolver.createTreePattern(Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); itpSolver.add(I1, Eq(a, Int(0))); itpSolver.add(I2, Eq(a, b)); @@ -265,5 +281,4 @@ public void testPushPop() { System.out.println(itp.eval(A)); System.out.println("----------"); } - } diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverArrayTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverArrayTest.java index 4d7c433e92..c792d54b46 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverArrayTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverArrayTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,22 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.ArrayTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTSolverArrayTest { @@ -58,19 +57,23 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check - final Solver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver(); + final Solver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver(); solver.push(); solver.add(EqExpr.create2(expected, actual)); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBVTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBVTest.java index 936a5943d1..0b5c7137a8 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBVTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBVTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,24 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.BvTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTSolverBVTest { @@ -52,9 +51,7 @@ public static Collection operations() { BvTestUtils.BasicOperations().stream(), Stream.concat( BvTestUtils.BitvectorOperations().stream(), - BvTestUtils.RelationalOperations().stream() - ) - ) + BvTestUtils.RelationalOperations().stream())) .collect(Collectors.toUnmodifiableList()); } @@ -67,19 +64,23 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check - final Solver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver(); + final Solver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver(); solver.push(); solver.add(EqExpr.create2(expected, actual)); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBooleanTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBooleanTest.java index 014792fc3c..b47632abd3 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBooleanTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverBooleanTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,22 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.BoolTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTSolverBooleanTest { @@ -58,19 +57,23 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check - final Solver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver(); + final Solver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver(); solver.push(); solver.add(EqExpr.create2(expected, actual)); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFPTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFPTest.java index a64cefbd2c..26b8d33518 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFPTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverFPTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,16 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.fptype.FpLeqExpr; @@ -24,25 +34,14 @@ import hu.bme.mit.theta.core.utils.FpUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; +import java.util.stream.Collectors; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.kframework.mpfr.BigFloat; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; -import java.util.stream.Collectors; - -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTSolverFPTest { @@ -57,8 +56,7 @@ public class JavaSMTSolverFPTest { @Parameters(name = "expected: {1}, actual: {2}") public static Collection operations() { - return FpTestUtils.GetOperations() - .collect(Collectors.toUnmodifiableList()); + return FpTestUtils.GetOperations().collect(Collectors.toUnmodifiableList()); } @Test @@ -70,19 +68,23 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check - final Solver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver(); + final Solver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver(); solver.push(); if (expected instanceof FpLitExpr && actual.getType() instanceof FpType) { @@ -95,10 +97,15 @@ public void testOperationEquals() { solver.add(EqExpr.create2(expected, actual)); } else { //noinspection unchecked - FpLeqExpr leq = Leq(Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), - FpUtils.bigFloatToFpLitExpr(new BigFloat("1e-2", - FpUtils.getMathContext((FpType) actual.getType(), RNE)), - (FpType) actual.getType())); + FpLeqExpr leq = + Leq( + Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), + FpUtils.bigFloatToFpLitExpr( + new BigFloat( + "1e-2", + FpUtils.getMathContext( + (FpType) actual.getType(), RNE)), + (FpType) actual.getType())); solver.add(leq); } } else { diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverIntTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverIntTest.java index 4a79168fce..37dd9078f6 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverIntTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverIntTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,22 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.IntTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTSolverIntTest { @@ -58,19 +57,23 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check - final Solver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver(); + final Solver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver(); solver.push(); solver.add(EqExpr.create2(expected, actual)); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverRatTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverRatTest.java index 1566a81a34..cb15d94f1f 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverRatTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverRatTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,22 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.RatTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.sosy_lab.java_smt.SolverContextFactory.Solvers; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTSolverRatTest { @@ -58,19 +57,23 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check - final Solver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver(); + final Solver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver(); solver.push(); solver.add(EqExpr.create2(expected, actual)); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverTest.java index 1ffd955015..e74c79f064 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTSolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,25 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static com.google.common.collect.ImmutableList.of; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.ArrayInit; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.OsHelper.OperatingSystem; import hu.bme.mit.theta.common.Tuple2; @@ -38,41 +57,20 @@ import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.UCSolver; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.sosy_lab.java_smt.SolverContextFactory.Solvers; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Optional; - -import static com.google.common.collect.ImmutableList.of; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.ArrayInit; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.sosy_lab.java_smt.SolverContextFactory.Solvers; @RunWith(Parameterized.class) public final class JavaSMTSolverTest { - @Parameterized.Parameter(0) public Solvers solvers; @@ -82,16 +80,36 @@ public final class JavaSMTSolverTest { @Parameters(name = "solver: {0}") public static Collection operations() { if (OsHelper.getOs().equals(OperatingSystem.LINUX)) { - return Arrays.asList(new Object[][]{ - {Solvers.Z3, JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver()}, - {Solvers.CVC5, JavaSMTSolverFactory.create(Solvers.CVC5, new String[]{}).createSolver()}, - {Solvers.PRINCESS, JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[]{}).createSolver()}, - }); + return Arrays.asList( + new Object[][] { + { + Solvers.Z3, + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver() + }, + { + Solvers.CVC5, + JavaSMTSolverFactory.create(Solvers.CVC5, new String[] {}) + .createSolver() + }, + { + Solvers.PRINCESS, + JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[] {}) + .createSolver() + }, + }); } else { - return Arrays.asList(new Object[][]{ - {Solvers.Z3, JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createSolver()}, - {Solvers.PRINCESS, JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[]{}).createSolver()}, - }); + return Arrays.asList( + new Object[][] { + { + Solvers.Z3, + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createSolver() + }, + { + Solvers.PRINCESS, + JavaSMTSolverFactory.create(Solvers.PRINCESS, new String[] {}) + .createSolver() + }, + }); } } @@ -118,7 +136,8 @@ public void testSimple() { @Test public void testTrack() { - final UCSolver solver = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}).createUCSolver(); + final UCSolver solver = + JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}).createUCSolver(); final ConstDecl ca = Const("a", BoolExprs.Bool()); final Expr expr = BoolExprs.And(ca.getRef(), True()); @@ -144,10 +163,12 @@ public void testFunc() { final ParamDecl px = Param("x", Int()); final Expr x = px.getRef(); - solver.add(BoolExprs.Forall(of(px), - BoolExprs.Imply(IntExprs.Leq(x, Int(0)), Eq(App(a, x), Int(0))))); - solver.add(BoolExprs.Forall(of(px), - BoolExprs.Imply(IntExprs.Geq(x, Int(1)), Eq(App(a, x), Int(1))))); + solver.add( + BoolExprs.Forall( + of(px), BoolExprs.Imply(IntExprs.Leq(x, Int(0)), Eq(App(a, x), Int(0))))); + solver.add( + BoolExprs.Forall( + of(px), BoolExprs.Imply(IntExprs.Geq(x, Int(1)), Eq(App(a, x), Int(1))))); // Act final SolverStatus status = solver.check(); @@ -160,7 +181,7 @@ public void testFunc() { assertEquals(ca.getType(), val.getType()); } - //@Test + // @Test public void testArray() { final ConstDecl> arr = Const("arr", Array(Int(), Int())); @@ -181,7 +202,7 @@ public void testArray() { assertEquals(Int(2), Read(valLit, Int(1)).eval(ImmutableValuation.empty())); } - //@Test + // @Test public void testArrayInit() { final ConstDecl> arr = Const("arr", Array(Int(), Int())); var elems = new ArrayList, Expr>>(); @@ -250,8 +271,8 @@ public void testBV1() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cx.getRef(), cy.getRef())); SolverStatus status = solver.check(); @@ -267,7 +288,7 @@ public void testBV2() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); solver.add(BvExprs.Neq(cx.getRef(), cz.getRef())); SolverStatus status = solver.check(); @@ -287,9 +308,14 @@ public void testBV3() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Add(List.of(cx.getRef(), Bv(new boolean[]{false, false, false, true}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Add( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, false, true}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -308,9 +334,11 @@ public void testBV4() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Sub(cx.getRef(), Bv(new boolean[]{false, false, false, true})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Sub(cx.getRef(), Bv(new boolean[] {false, false, false, true})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -329,7 +357,7 @@ public void testBV5() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Neg(cx.getRef()))); SolverStatus status = solver.check(); @@ -349,9 +377,14 @@ public void testBV6() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Mul(List.of(cx.getRef(), Bv(new boolean[]{false, false, true, false}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Mul( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, true, false}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -370,8 +403,8 @@ public void testBV7() { solver.push(); - solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[]{true, true, true, true}))); - solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[]{true, true, true, true}))); + solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[] {true, true, true, true}))); + solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[] {true, true, true, true}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -390,9 +423,11 @@ public void testBV8() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{true, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.SMod(cx.getRef(), Bv(new boolean[]{false, true, false, false})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {true, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.SMod(cx.getRef(), Bv(new boolean[] {false, true, false, false})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -411,9 +446,11 @@ public void testBV9() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Or(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{true, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Or(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {true, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -432,9 +469,11 @@ public void testBV10() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.And(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.And(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -453,9 +492,11 @@ public void testBV11() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -474,10 +515,12 @@ public void testBV12() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq( - BvExprs.ArithShiftRight(cy.getRef(), Bv(new boolean[]{false, false, false, true})), - cx.getRef())); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.ArithShiftRight( + cy.getRef(), Bv(new boolean[] {false, false, false, true})), + cx.getRef())); SolverStatus status = solver.check(); assertTrue(status.isSat()); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformerTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformerTest.java index dc927846e2..691de74f5a 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformerTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTTransformerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeFalse; +import static org.junit.runners.Parameterized.Parameters; + import com.google.common.collect.Sets; import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.OsHelper.OperatingSystem; @@ -31,6 +36,11 @@ import hu.bme.mit.theta.core.type.functype.FuncType; import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.core.utils.ExpressionUtils; +import java.util.Collection; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.Predicate; +import java.util.stream.Collectors; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,17 +53,6 @@ import org.sosy_lab.java_smt.SolverContextFactory.Solvers; import org.sosy_lab.java_smt.api.SolverContext; -import java.util.Collection; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assume.assumeFalse; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class JavaSMTTransformerTest { @@ -75,11 +74,12 @@ public static Collection operations() { return Sets.cartesianProduct( ExpressionUtils.AllExpressions().values().stream() .collect(Collectors.toSet()), - solvers).stream() - .map(objects -> new Object[]{objects.get(0), objects.get(1)}).toList(); + solvers) + .stream() + .map(objects -> new Object[] {objects.get(0), objects.get(1)}) + .toList(); } - private static boolean hasType(Expr expr, Predicate pred) { if (pred.test(expr.getType())) return true; return expr.getOps().stream().anyMatch((op) -> hasType(op, pred)); @@ -94,19 +94,48 @@ private static boolean hasExpr(Expr expr, Predicate> pred) { public void testRoundtripTransformer() throws Exception { // Sanity check assertNotNull(expr); - assumeFalse(solver == Solvers.CVC5 && hasType(expr, type -> type instanceof FpType && !Set.of(32, 64).contains(((FpType) type).getSignificand() + ((FpType) type).getExponent()))); - assumeFalse(solver == Solvers.PRINCESS && hasType(expr, type -> type instanceof FpType || type instanceof RatType)); - assumeFalse(solver == Solvers.SMTINTERPOL && (hasType(expr, type -> type instanceof BvType || type instanceof FpType) || expr instanceof QuantifiedExpr)); - assumeFalse(solver == Solvers.SMTINTERPOL && (hasType(expr, type -> type instanceof BvType || type instanceof FpType) || expr instanceof QuantifiedExpr)); - assumeFalse((solver == Solvers.SMTINTERPOL || solver == Solvers.PRINCESS) && hasExpr(expr, e -> e instanceof ArrayInitExpr || e instanceof ArrayLitExpr)); + assumeFalse( + solver == Solvers.CVC5 + && hasType( + expr, + type -> + type instanceof FpType + && !Set.of(32, 64) + .contains( + ((FpType) type).getSignificand() + + ((FpType) type) + .getExponent()))); + assumeFalse( + solver == Solvers.PRINCESS + && hasType( + expr, type -> type instanceof FpType || type instanceof RatType)); + assumeFalse( + solver == Solvers.SMTINTERPOL + && (hasType(expr, type -> type instanceof BvType || type instanceof FpType) + || expr instanceof QuantifiedExpr)); + assumeFalse( + solver == Solvers.SMTINTERPOL + && (hasType(expr, type -> type instanceof BvType || type instanceof FpType) + || expr instanceof QuantifiedExpr)); + assumeFalse( + (solver == Solvers.SMTINTERPOL || solver == Solvers.PRINCESS) + && hasExpr( + expr, + e -> + e instanceof ArrayInitExpr + || e instanceof ArrayLitExpr)); final JavaSMTSymbolTable javaSMTSymbolTable = new JavaSMTSymbolTable(); - final var config = Configuration.fromCmdLineArguments(new String[]{}); + final var config = Configuration.fromCmdLineArguments(new String[] {}); final var logger = BasicLogManager.create(config); final var shutdownManager = ShutdownManager.create(); - try (final SolverContext context = SolverContextFactory.createSolverContext(config, logger, shutdownManager.getNotifier(), Solvers.Z3)) { - final JavaSMTTransformationManager javaSMTExprTransformer = new JavaSMTTransformationManager(javaSMTSymbolTable, context); - final JavaSMTTermTransformer javaSMTTermTransformer = new JavaSMTTermTransformer(javaSMTSymbolTable, context); + try (final SolverContext context = + SolverContextFactory.createSolverContext( + config, logger, shutdownManager.getNotifier(), Solvers.Z3)) { + final JavaSMTTransformationManager javaSMTExprTransformer = + new JavaSMTTransformationManager(javaSMTSymbolTable, context); + final JavaSMTTermTransformer javaSMTTermTransformer = + new JavaSMTTermTransformer(javaSMTSymbolTable, context); final var expTerm = javaSMTExprTransformer.toTerm(expr); final var expExpr = javaSMTTermTransformer.toExpr(expTerm); @@ -117,20 +146,31 @@ public void testRoundtripTransformer() throws Exception { if (hasType(expr, type -> type instanceof FuncType)) { throw e; // for functions, we don't want the solver to step in } - try (final var solver = JavaSMTSolverFactory.create(this.solver, new String[]{}).createSolver()) { - BiFunction> eq = expr.getType() instanceof FpType ? FpExprs::FpAssign : AbstractExprs::Eq; + try (final var solver = + JavaSMTSolverFactory.create(this.solver, new String[] {}).createSolver()) { + BiFunction> eq = + expr.getType() instanceof FpType + ? FpExprs::FpAssign + : AbstractExprs::Eq; solver.push(); solver.add(eq.apply(expr, expExpr)); - Assert.assertTrue("(= %s %s) is unsat\n".formatted(expr, expExpr), solver.check().isSat()); + Assert.assertTrue( + "(= %s %s) is unsat\n".formatted(expr, expExpr), + solver.check().isSat()); solver.pop(); solver.push(); solver.add(Not(eq.apply(expr, expExpr))); - Assert.assertTrue("(not (= %s %s)) is sat with model %s\n".formatted(expr, expExpr, solver.check().isSat() ? solver.getModel() : ""), solver.check().isUnsat()); + Assert.assertTrue( + "(not (= %s %s)) is sat with model %s\n" + .formatted( + expr, + expExpr, + solver.check().isSat() ? solver.getModel() : ""), + solver.check().isUnsat()); solver.pop(); } } } - } } diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagatorTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagatorTest.java index 6caab7dae6..6d1de24786 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagatorTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/JavaSMTUserPropagatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,22 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.javasmt; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.functype.FuncAppExpr; -import hu.bme.mit.theta.core.type.functype.FuncType; -import hu.bme.mit.theta.core.type.inttype.IntLitExpr; -import hu.bme.mit.theta.core.type.inttype.IntType; -import org.junit.Test; - -import java.math.BigInteger; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; @@ -41,13 +27,27 @@ import static org.junit.Assert.assertTrue; import static org.sosy_lab.java_smt.SolverContextFactory.Solvers.Z3; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.functype.FuncAppExpr; +import hu.bme.mit.theta.core.type.functype.FuncType; +import hu.bme.mit.theta.core.type.inttype.IntLitExpr; +import hu.bme.mit.theta.core.type.inttype.IntType; +import java.math.BigInteger; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; + public class JavaSMTUserPropagatorTest { @Test public void testUserPropagatorBool() throws Exception { TestKnownValuePropagator testPropagator = new TestKnownValuePropagator(); - try (final var solver = JavaSMTSolverFactory.create(Z3, new String[]{}).createSolverWithPropagators(testPropagator)) { + try (final var solver = + JavaSMTSolverFactory.create(Z3, new String[] {}) + .createSolverWithPropagators(testPropagator)) { final var c1 = Const("x", Bool()); final var c2 = Const("y", Bool()); final var c3 = Const("z", Bool()); @@ -63,12 +63,13 @@ public void testUserPropagatorBool() throws Exception { } } - @Test public void testUserPropagatorFunc() throws Exception { TestConsequencePropagator testPropagator = new TestConsequencePropagator(); - try (final var solver = JavaSMTSolverFactory.create(Z3, new String[]{}).createSolverWithPropagators(testPropagator)) { + try (final var solver = + JavaSMTSolverFactory.create(Z3, new String[] {}) + .createSolverWithPropagators(testPropagator)) { final var c1 = Const("x", Int()); final var c2 = Const("y", Int()); final var c3 = Const("z", Int()); @@ -91,7 +92,10 @@ public void testUserPropagatorFunc() throws Exception { assertTrue("Should be SAT", solver.getStatus().isSat()); final var model = solver.getModel(); - assertEquals("Should only be one.", BigInteger.ONE, ((IntLitExpr) model.eval(c2).get()).getValue()); + assertEquals( + "Should only be one.", + BigInteger.ONE, + ((IntLitExpr) model.eval(c2).get()).getValue()); solver.add(Not(Eq(c2.getRef(), Int(1)))); solver.check(); @@ -99,7 +103,6 @@ public void testUserPropagatorFunc() throws Exception { } } - private static class TestConsequencePropagator extends JavaSMTUserPropagator { @Override public void onKnownValue(Expr expr, boolean value) { @@ -107,7 +110,8 @@ public void onKnownValue(Expr expr, boolean value) { FuncAppExpr appOuter = (FuncAppExpr) expr; FuncAppExpr appInner = (FuncAppExpr) appOuter.getFunc(); - final var consequence = Lt((Expr) appInner.getParam(), (Expr) appOuter.getParam()); + final var consequence = + Lt((Expr) appInner.getParam(), (Expr) appOuter.getParam()); if (value) { System.err.printf("Consequence: %s\n", consequence); @@ -119,7 +123,6 @@ public void onKnownValue(Expr expr, boolean value) { } } - private static class TestKnownValuePropagator extends JavaSMTUserPropagator { private final Map, Boolean> setExpressions = new LinkedHashMap<>(); diff --git a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/SolverUtilsTest.java b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/SolverUtilsTest.java index 30dcbbd179..9f6f7b6e89 100644 --- a/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/SolverUtilsTest.java +++ b/subprojects/solver/solver-javasmt/src/test/java/hu/bme/mit/theta/solver/javasmt/SolverUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.javasmt; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Gt; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; @@ -23,6 +27,8 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.utils.SolverUtils; +import java.math.BigInteger; +import java.util.stream.Stream; import org.junit.Assert; import org.junit.Test; import org.sosy_lab.common.ShutdownManager; @@ -37,19 +43,12 @@ import org.sosy_lab.java_smt.api.SolverContext; import org.sosy_lab.java_smt.api.visitors.DefaultFormulaVisitor; -import java.math.BigInteger; -import java.util.stream.Stream; - -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Gt; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class SolverUtilsTest { @Test public void testModels() { // Arrange - final SolverFactory factory = JavaSMTSolverFactory.create(Solvers.Z3, new String[]{}); + final SolverFactory factory = JavaSMTSolverFactory.create(Solvers.Z3, new String[] {}); final ConstDecl cx = Const("x", Int()); final ConstDecl cy = Const("y", Int()); @@ -66,23 +65,30 @@ public void testModels() { // if this no longer fails, clean up the FpToFp mitigations in ExprTransformer @Test public void testBugreport() throws InvalidConfigurationException { - final Configuration config = Configuration.fromCmdLineArguments(new String[]{}); + final Configuration config = Configuration.fromCmdLineArguments(new String[] {}); final LogManager logger = BasicLogManager.create(config); final ShutdownManager shutdownManager = ShutdownManager.create(); - final SolverContext context = SolverContextFactory.createSolverContext(config, logger, shutdownManager.getNotifier(), Solvers.Z3); - - final Formula term = context.getFormulaManager().getFloatingPointFormulaManager().fromIeeeBitvector( - context.getFormulaManager().getBitvectorFormulaManager().makeBitvector(16, BigInteger.ZERO), - FormulaType.getFloatingPointType(5, 10) - ); + final SolverContext context = + SolverContextFactory.createSolverContext( + config, logger, shutdownManager.getNotifier(), Solvers.Z3); - context.getFormulaManager().visit(term, new DefaultFormulaVisitor() { - @Override - protected Void visitDefault(Formula f) { - return null; - } - }); + final Formula term = + context.getFormulaManager() + .getFloatingPointFormulaManager() + .fromIeeeBitvector( + context.getFormulaManager() + .getBitvectorFormulaManager() + .makeBitvector(16, BigInteger.ZERO), + FormulaType.getFloatingPointType(5, 10)); + context.getFormulaManager() + .visit( + term, + new DefaultFormulaVisitor() { + @Override + protected Void visitDefault(Formula f) { + return null; + } + }); } - } diff --git a/subprojects/solver/solver-smtlib-cli/build.gradle.kts b/subprojects/solver/solver-smtlib-cli/build.gradle.kts index 95cbb948f4..e112fbe48b 100644 --- a/subprojects/solver/solver-smtlib-cli/build.gradle.kts +++ b/subprojects/solver/solver-smtlib-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib-cli/src/main/java/hu/bme/mit/theta/solver/smtlib/cli/SmtLibCli.java b/subprojects/solver/solver-smtlib-cli/src/main/java/hu/bme/mit/theta/solver/smtlib/cli/SmtLibCli.java index a7721cc72f..d430220f38 100644 --- a/subprojects/solver/solver-smtlib-cli/src/main/java/hu/bme/mit/theta/solver/smtlib/cli/SmtLibCli.java +++ b/subprojects/solver/solver-smtlib-cli/src/main/java/hu/bme/mit/theta/solver/smtlib/cli/SmtLibCli.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,9 +23,8 @@ import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.logging.ConsoleLogger; import hu.bme.mit.theta.common.logging.Logger; -import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.SmtLibSolverManager; - +import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import java.awt.Desktop; import java.io.IOException; import java.io.PrintWriter; @@ -49,7 +48,9 @@ static class MainParams { @Parameter(names = "--loglevel", description = "Detailedness of logging") Logger.Level logLevel = Logger.Level.MAINSTEP; - @Parameter(names = "--stacktrace", description = "Prints the stacktrace in case of an error") + @Parameter( + names = "--stacktrace", + description = "Prints the stacktrace in case of an error") private boolean stacktrace = false; @Parameter(names = "--help", help = true, description = "Prints this help message") @@ -69,16 +70,31 @@ static class InstallCommand implements Command { static final String COMMAND = "install"; - @Parameter(description = "The solver to install (:)", validateWith = SolverNameAndVersionValidator.class, required = true) + @Parameter( + description = "The solver to install (:)", + validateWith = SolverNameAndVersionValidator.class, + required = true) String solver; - @Parameter(names = "--name", description = "Install the solver version under this custom name (:), instead of the default (:)") + @Parameter( + names = "--name", + description = + "Install the solver version under this custom name (:)," + + " instead of the default (:)") String name; - @Parameter(names = "--solver-path", description = "The path of the solver to install. The solver will not be downloaded, instead the binary on this path will be used. Caveat emptor: the version must be specified correctly, there is no automatic detection.") + @Parameter( + names = "--solver-path", + description = + "The path of the solver to install. The solver will not be downloaded," + + " instead the binary on this path will be used. Caveat emptor: the" + + " version must be specified correctly, there is no automatic" + + " detection.") String solverPath; - @Parameter(names = "--tempt-murphy", description = "Allows the installation of unsupported solver version") + @Parameter( + names = "--tempt-murphy", + description = "Allows the installation of unsupported solver version") boolean temptMurphy = false; @Override @@ -92,18 +108,27 @@ public void handle(final SmtLibSolverManager smtLibSolverManager, final Logger l final var solver = decodeVersionString(this.solver); if (solver.get1().equals(smtLibSolverManager.getGenericInstallerName())) { - logger.write(Logger.Level.RESULT, + logger.write( + Logger.Level.RESULT, "To install a generic solver, use the \"%s\" command", InstallGenericCommand.COMMAND); return; } if (name != null) { - smtLibSolverManager.install(solver.get1(), solver.get2(), name, - solverPath != null ? Path.of(solverPath) : null, temptMurphy); + smtLibSolverManager.install( + solver.get1(), + solver.get2(), + name, + solverPath != null ? Path.of(solverPath) : null, + temptMurphy); } else { - smtLibSolverManager.install(solver.get1(), solver.get2(), solver.get2(), - solverPath != null ? Path.of(solverPath) : null, temptMurphy); + smtLibSolverManager.install( + solver.get1(), + solver.get2(), + solver.get2(), + solverPath != null ? Path.of(solverPath) : null, + temptMurphy); } } } @@ -113,13 +138,23 @@ static class InstallGenericCommand implements Command { static final String COMMAND = "install-generic"; - @Parameter(names = "--solver-path", description = "The path of the generic solver to install", required = true) + @Parameter( + names = "--solver-path", + description = "The path of the generic solver to install", + required = true) String solverPath; - @Parameter(names = "--solver-args", description = "The arguments of the generic solver to invoke with") + @Parameter( + names = "--solver-args", + description = "The arguments of the generic solver to invoke with") String solverArgs; - @Parameter(names = "--name", description = "Install the solver version under this custom name (:), instead of the default (:)", required = true) + @Parameter( + names = "--name", + description = + "Install the solver version under this custom name (:)," + + " instead of the default (:)", + required = true) String name; @Override @@ -131,10 +166,7 @@ public String getCommand() { public void handle(final SmtLibSolverManager smtLibSolverManager, final Logger logger) throws SmtLibSolverInstallerException { smtLibSolverManager.installGeneric( - name, - Path.of(solverPath), - (solverArgs == null ? "" : solverArgs).split(" ") - ); + name, Path.of(solverPath), (solverArgs == null ? "" : solverArgs).split(" ")); } } @@ -143,7 +175,10 @@ static class UninstallCommand implements Command { static final String COMMAND = "uninstall"; - @Parameter(description = "The solver to uninstall (:)", validateWith = SolverNameAndVersionValidator.class, required = true) + @Parameter( + description = "The solver to uninstall (:)", + validateWith = SolverNameAndVersionValidator.class, + required = true) String solver; @Override @@ -164,10 +199,17 @@ static class RenameCommand implements Command { static final String COMMAND = "rename"; - @Parameter(description = "The solver to reinstall (:)", validateWith = SolverNameAndVersionValidator.class, required = true) + @Parameter( + description = "The solver to reinstall (:)", + validateWith = SolverNameAndVersionValidator.class, + required = true) String solver; - @Parameter(names = "--name", description = "Rename the solver version to this custom name (:).", required = true) + @Parameter( + names = "--name", + description = + "Rename the solver version to this custom name (:).", + required = true) String name; @Override @@ -188,7 +230,10 @@ static class GetInfoCommand implements Command { static final String COMMAND = "get-info"; - @Parameter(description = "The solver to print info about (:)", validateWith = SolverNameAndVersionValidator.class, required = true) + @Parameter( + description = "The solver to print info about (:)", + validateWith = SolverNameAndVersionValidator.class, + required = true) String solver; @Override @@ -210,10 +255,17 @@ static class EditArgsCommand implements Command { static final String COMMAND = "edit-args"; - @Parameter(description = "The solver, whose runtime arguments are to be edited (:)", validateWith = SolverNameAndVersionValidator.class, required = true) + @Parameter( + description = + "The solver, whose runtime arguments are to be edited" + + " (:)", + validateWith = SolverNameAndVersionValidator.class, + required = true) String solver; - @Parameter(names = "--print", description = "Print the path instead of opening it for editing") + @Parameter( + names = "--print", + description = "Print the path instead of opening it for editing") boolean print = false; @Override @@ -228,20 +280,22 @@ public void handle(SmtLibSolverManager smtLibSolverManager, Logger logger) final var argsFilePath = smtLibSolverManager.getArgsFile(solver.get1(), solver.get2()); if (print) { - logger.write(Logger.Level.RESULT, - String.format("%s\n", argsFilePath.toAbsolutePath())); - } else if (Desktop.isDesktopSupported() && Desktop.getDesktop() - .isSupported(Desktop.Action.EDIT)) { + logger.write( + Logger.Level.RESULT, String.format("%s\n", argsFilePath.toAbsolutePath())); + } else if (Desktop.isDesktopSupported() + && Desktop.getDesktop().isSupported(Desktop.Action.EDIT)) { try { Desktop.getDesktop().edit(argsFilePath.toFile()); } catch (IOException e) { throw new SmtLibSolverInstallerException(e); } } else { - logger.write(Logger.Level.MAINSTEP, - "Open the following text file in your favourite editor, and edit the content:\n"); - logger.write(Logger.Level.RESULT, - String.format("%s\n", argsFilePath.toAbsolutePath())); + logger.write( + Logger.Level.MAINSTEP, + "Open the following text file in your favourite editor, and edit the" + + " content:\n"); + logger.write( + Logger.Level.RESULT, String.format("%s\n", argsFilePath.toAbsolutePath())); } } } @@ -251,7 +305,10 @@ static class ListInstalledCommand implements Command { static final String COMMAND = "list-installed"; - @Parameter(description = "The solver, whose installed versions are to be listed ()", validateWith = SolverNameValidator.class) + @Parameter( + description = + "The solver, whose installed versions are to be listed ()", + validateWith = SolverNameValidator.class) String solver; @Override @@ -263,18 +320,32 @@ public String getCommand() { public void handle(SmtLibSolverManager smtLibSolverManager, Logger logger) throws SmtLibSolverInstallerException { if (solver != null) { - logger.write(Logger.Level.MAINSTEP, - "The currently installed versions of solver %s are: \n", solver); - smtLibSolverManager.getInstalledVersions(solver).forEach(version -> { - logger.write(Logger.Level.RESULT, "\t%s:%s\n", solver, version); - }); + logger.write( + Logger.Level.MAINSTEP, + "The currently installed versions of solver %s are: \n", + solver); + smtLibSolverManager + .getInstalledVersions(solver) + .forEach( + version -> { + logger.write(Logger.Level.RESULT, "\t%s:%s\n", solver, version); + }); } else { logger.write(Logger.Level.MAINSTEP, "The currently installed solvers are: \n"); - smtLibSolverManager.getInstalledVersions().forEach(solver -> { - solver.get2().forEach(version -> { - logger.write(Logger.Level.RESULT, "\t%s:%s\n", solver.get1(), version); - }); - }); + smtLibSolverManager + .getInstalledVersions() + .forEach( + solver -> { + solver.get2() + .forEach( + version -> { + logger.write( + Logger.Level.RESULT, + "\t%s:%s\n", + solver.get1(), + version); + }); + }); } } } @@ -284,7 +355,10 @@ static class ListSupportedCommand implements Command { static final String COMMAND = "list-supported"; - @Parameter(description = "The solver, whose supported versions are to be listed ()", validateWith = SolverNameValidator.class) + @Parameter( + description = + "The solver, whose supported versions are to be listed ()", + validateWith = SolverNameValidator.class) String solver; @Override @@ -296,18 +370,32 @@ public String getCommand() { public void handle(SmtLibSolverManager smtLibSolverManager, Logger logger) throws SmtLibSolverInstallerException { if (solver != null) { - logger.write(Logger.Level.MAINSTEP, - "The currently supported versions of solver %s are: \n", solver); - smtLibSolverManager.getSupportedVersions(solver).forEach(version -> { - logger.write(Logger.Level.RESULT, "\t%s:%s\n", solver, version); - }); + logger.write( + Logger.Level.MAINSTEP, + "The currently supported versions of solver %s are: \n", + solver); + smtLibSolverManager + .getSupportedVersions(solver) + .forEach( + version -> { + logger.write(Logger.Level.RESULT, "\t%s:%s\n", solver, version); + }); } else { logger.write(Logger.Level.MAINSTEP, "The currently supported solvers are: \n"); - smtLibSolverManager.getSupportedVersions().forEach(solver -> { - solver.get2().forEach(version -> { - logger.write(Logger.Level.RESULT, "\t%s:%s\n", solver.get1(), version); - }); - }); + smtLibSolverManager + .getSupportedVersions() + .forEach( + solver -> { + solver.get2() + .forEach( + version -> { + logger.write( + Logger.Level.RESULT, + "\t%s:%s\n", + solver.get1(), + version); + }); + }); } } } @@ -323,16 +411,16 @@ public static void main(final String[] args) { private void run() { final var mainParams = new MainParams(); - List commands = List.of( - new InstallCommand(), - new InstallGenericCommand(), - new UninstallCommand(), - new RenameCommand(), - new GetInfoCommand(), - new EditArgsCommand(), - new ListInstalledCommand(), - new ListSupportedCommand() - ); + List commands = + List.of( + new InstallCommand(), + new InstallGenericCommand(), + new UninstallCommand(), + new RenameCommand(), + new GetInfoCommand(), + new EditArgsCommand(), + new ListInstalledCommand(), + new ListSupportedCommand()); final var jcBuilder = JCommander.newBuilder().addObject(mainParams); commands.forEach(command -> jcBuilder.addCommand(command.getCommand(), command)); @@ -383,7 +471,8 @@ private void run() { } private static Tuple2 decodeVersionString(final String version) { - return Tuple2.of(SmtLibSolverManager.getSolverName(version), + return Tuple2.of( + SmtLibSolverManager.getSolverName(version), SmtLibSolverManager.getSolverVersion(version)); } @@ -396,8 +485,11 @@ private Path createIfNotExists(final Path path) throws IOException { private void printError(final Throwable ex, final boolean printStackTrace) { final String message = ex.getMessage() == null ? "" : ex.getMessage(); - logger.write(Logger.Level.RESULT, "%s occurred, message: %s%n", - ex.getClass().getSimpleName(), message); + logger.write( + Logger.Level.RESULT, + "%s occurred, message: %s%n", + ex.getClass().getSimpleName(), + message); if (printStackTrace) { final StringWriter errors = new StringWriter(); ex.printStackTrace(new PrintWriter(errors)); @@ -413,8 +505,7 @@ public static class SolverNameValidator implements IParameterValidator { public void validate(String name, String value) throws ParameterException { if (!value.matches("[a-zA-Z0-9]+")) { throw new ParameterException( - String.format("Invalid solver name in parameter %s", name) - ); + String.format("Invalid solver name in parameter %s", name)); } } } @@ -430,11 +521,10 @@ public void validate(String name, String value) throws ParameterException { String.format("Invalid version string %s in parameter %s", value, name)); } - if (!versionArr[0].matches("[a-zA-Z0-9]+") || !versionArr[1].matches( - "[a-zA-Z0-9-._]+")) { + if (!versionArr[0].matches("[a-zA-Z0-9]+") + || !versionArr[1].matches("[a-zA-Z0-9-._]+")) { throw new ParameterException( - String.format("Invalid version string %s in parameter %s", value, name) - ); + String.format("Invalid version string %s in parameter %s", value, name)); } } } diff --git a/subprojects/solver/solver-smtlib/build.gradle.kts b/subprojects/solver/solver-smtlib/build.gradle.kts index c578f4dba8..16f68f4da1 100644 --- a/subprojects/solver/solver-smtlib/build.gradle.kts +++ b/subprojects/solver/solver-smtlib/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverManager.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverManager.java index 5f408ea538..51d82ccc7b 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverManager.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.smtlib; +import static com.google.common.base.Preconditions.*; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.logging.Logger; @@ -32,7 +34,6 @@ import hu.bme.mit.theta.solver.smtlib.impl.z3.Z3SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; - import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; @@ -41,14 +42,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.*; - public final class SmtLibSolverManager extends SolverManager { public static final Path HOME = Path.of(System.getProperty("user.home"), ".theta"); - private static final Map> installerDeclarations = new HashMap<>(); - private static Tuple2> genericInstallerDeclaration; + private static final Map> installerDeclarations = + new HashMap<>(); + private static Tuple2> + genericInstallerDeclaration; static { registerInstaller("z3", Z3SmtLibSolverInstaller.class); @@ -77,36 +78,47 @@ private SmtLibSolverManager(final Path home, final Logger logger) { this.home = home; try { - this.genericInstaller = Tuple2.of( - genericInstallerDeclaration.get1(), - genericInstallerDeclaration.get2().getDeclaredConstructor(Logger.class) - .newInstance(logger) - ); - - this.installers = Stream.concat( - Stream.of(this.genericInstaller), - installerDeclarations.entrySet().stream() - .map(p -> { - try { - return Tuple2.of(p.getKey(), - p.getValue().getDeclaredConstructor(Logger.class) - .newInstance(logger)); - } catch (InstantiationException | IllegalAccessException | - InvocationTargetException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - }) - ).collect(Collectors.toUnmodifiableMap(Tuple2::get1, Tuple2::get2)); - } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | - IllegalAccessException e) { + this.genericInstaller = + Tuple2.of( + genericInstallerDeclaration.get1(), + genericInstallerDeclaration + .get2() + .getDeclaredConstructor(Logger.class) + .newInstance(logger)); + + this.installers = + Stream.concat( + Stream.of(this.genericInstaller), + installerDeclarations.entrySet().stream() + .map( + p -> { + try { + return Tuple2.of( + p.getKey(), + p.getValue() + .getDeclaredConstructor( + Logger.class) + .newInstance(logger)); + } catch (InstantiationException + | IllegalAccessException + | InvocationTargetException + | NoSuchMethodException e) { + throw new RuntimeException(e); + } + })) + .collect(Collectors.toUnmodifiableMap(Tuple2::get1, Tuple2::get2)); + } catch (InstantiationException + | InvocationTargetException + | NoSuchMethodException + | IllegalAccessException e) { throw new RuntimeException(e); } this.instantiatedSolvers = new HashSet<>(); } - public static void registerInstaller(final String name, - final Class decl) { + public static void registerInstaller( + final String name, final Class decl) { installerDeclarations.put(name, decl); } @@ -166,8 +178,12 @@ public boolean managesSolver(final String name) { return solverName != null && installers.containsKey(solverName); } - public void install(final String solver, final String version, final String name, - final Path solverPath, final boolean installUnsupported) + public void install( + final String solver, + final String version, + final String name, + final Path solverPath, + final boolean installUnsupported) throws SmtLibSolverInstallerException { checkArgument(!solver.equals(genericInstaller.get1())); @@ -189,11 +205,20 @@ public void install(final String solver, final String version, final String name } if (solverPath != null) { - installers.get(solver).install(installDir, getVersionString(solver, version, false), - getVersionString(solver, name, false), solverPath); + installers + .get(solver) + .install( + installDir, + getVersionString(solver, version, false), + getVersionString(solver, name, false), + solverPath); } else { - installers.get(solver).install(installDir, getVersionString(solver, version, false), - getVersionString(solver, name, false)); + installers + .get(solver) + .install( + installDir, + getVersionString(solver, version, false), + getVersionString(solver, name, false)); } } @@ -216,7 +241,8 @@ public void uninstall(final String solver, final String version) throw new SmtLibSolverInstallerException(String.format("Unknown solver: %s", solver)); } - installers.get(solver) + installers + .get(solver) .uninstall(home.resolve(solver), getVersionString(solver, version, true)); } @@ -226,7 +252,8 @@ public void rename(final String solver, final String version, final String name) throw new SmtLibSolverInstallerException(String.format("Unknown solver: %s", solver)); } - installers.get(solver) + installers + .get(solver) .rename(home.resolve(solver), getVersionString(solver, version, true), name); } @@ -236,7 +263,8 @@ public String getInfo(final String solver, final String version) throw new SmtLibSolverInstallerException(String.format("Unknown solver: %s", solver)); } - return installers.get(solver) + return installers + .get(solver) .getInfo(home.resolve(solver), getVersionString(solver, version, true)); } @@ -246,7 +274,8 @@ public Path getArgsFile(final String solver, final String version) throw new SmtLibSolverInstallerException(String.format("Unknown solver: %s", solver)); } - return installers.get(solver) + return installers + .get(solver) .getArgsFile(home.resolve(solver), getVersionString(solver, version, true)); } @@ -262,8 +291,11 @@ public SolverFactory getSolverFactory(final String solver, final String version) throw new SmtLibSolverInstallerException(String.format("Unknown solver: %s", solver)); } - return new ManagedFactory(installers.get(solver) - .getSolverFactory(home.resolve(solver), getVersionString(solver, version, true))); + return new ManagedFactory( + installers + .get(solver) + .getSolverFactory( + home.resolve(solver), getVersionString(solver, version, true))); } public List getSupportedSolvers() { @@ -310,20 +342,25 @@ public List getInstalledVersions(final String solver) return installers.get(solver).getInstalledVersions(home.resolve(solver)); } - public String getVersionString(final String solver, final String version, - final boolean installed) throws SmtLibSolverInstallerException { + public String getVersionString( + final String solver, final String version, final boolean installed) + throws SmtLibSolverInstallerException { if (!version.equals("latest")) { return version; } else { final var supportedVersions = getSupportedVersions(solver); - final var versions = installed ? getInstalledVersions(solver).stream() - .filter(supportedVersions::contains).toList() - : supportedVersions; + final var versions = + installed + ? getInstalledVersions(solver).stream() + .filter(supportedVersions::contains) + .toList() + : supportedVersions; if (!versions.isEmpty()) { return versions.get(0); } else { throw new SmtLibSolverInstallerException( - String.format("There are no %s versions of solver: %s", + String.format( + "There are no %s versions of solver: %s", installed ? "installed" : "supported", solver)); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverFactory.java index 00cada33bc..83d268cd36 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,9 +16,7 @@ package hu.bme.mit.theta.solver.smtlib.impl.bitwuzla; import hu.bme.mit.theta.solver.ItpSolver; -import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSolverFactory; - import java.nio.file.Path; public class BitwuzlaSmtLibSolverFactory extends GenericSmtLibSolverFactory { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverInstaller.java index 2b344da9a6..60aeaf7d06 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/bitwuzla/BitwuzlaSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; - import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -40,10 +39,10 @@ protected String getSolverName() { @Override protected void installSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException { - final var downloadUrl = URI.create(String.format( - "https://github.com/bitwuzla/bitwuzla/archive/%s.zip", - version - )); + final var downloadUrl = + URI.create( + String.format( + "https://github.com/bitwuzla/bitwuzla/archive/%s.zip", version)); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); @@ -57,11 +56,17 @@ protected void installSolver(final Path installDir, final String version) logger.write(Logger.Level.MAINSTEP, "Starting compilation\n"); - installDir.resolve("contrib").resolve("setup-cadical.sh").toFile() + installDir + .resolve("contrib") + .resolve("setup-cadical.sh") + .toFile() .setExecutable(true, true); executeCommand(installDir, "./contrib/setup-cadical.sh"); - installDir.resolve("contrib").resolve("setup-btor2tools.sh").toFile() + installDir + .resolve("contrib") + .resolve("setup-btor2tools.sh") + .toFile() .setExecutable(true, true); executeCommand(installDir, "./contrib/setup-btor2tools.sh"); @@ -71,7 +76,11 @@ protected void installSolver(final Path installDir, final String version) installDir.resolve("configure.sh").toFile().setExecutable(true, true); executeCommand(installDir, "./configure.sh"); executeCommand(installDir.resolve("build"), "make"); - installDir.resolve("build").resolve("bin").resolve("bitwuzla").toFile() + installDir + .resolve("build") + .resolve("bin") + .resolve("bitwuzla") + .toFile() .setExecutable(true, true); logger.write(Logger.Level.MAINSTEP, "Finished compilation\n"); @@ -84,17 +93,20 @@ protected void uninstallSolver(final Path installDir, final String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{ - "--smt2", - "-i" - }; + return new String[] {"--smt2", "-i"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { - final var solverFilePath = solverPath != null ? solverPath - : installDir.resolve("build").resolve("bin").resolve("bitwuzla"); + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { + final var solverFilePath = + solverPath != null + ? solverPath + : installDir.resolve("build").resolve("bin").resolve("bitwuzla"); return BitwuzlaSmtLibSolverFactory.create(solverFilePath, solverArgs); } @@ -107,12 +119,13 @@ private void executeCommand(final Path workingPath, final String command) throws SmtLibSolverInstallerException { try { logger.write(Logger.Level.SUBSTEP, "Execute command: %s\n", command); - final var process = new ProcessBuilder() - .command("bash", "-c", command) - .directory(workingPath.toFile()) - .redirectOutput(ProcessBuilder.Redirect.INHERIT) - .redirectError(ProcessBuilder.Redirect.INHERIT) - .start(); + final var process = + new ProcessBuilder() + .command("bash", "-c", command) + .directory(workingPath.toFile()) + .redirectOutput(ProcessBuilder.Redirect.INHERIT) + .redirectError(ProcessBuilder.Redirect.INHERIT) + .start(); if (process.waitFor() != 0) { throw new SmtLibSolverInstallerException( diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverFactory.java index 15cfb96600..daa461b1ef 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,7 +18,6 @@ import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSolverFactory; - import java.nio.file.Path; public class BoolectorSmtLibSolverFactory extends GenericSmtLibSolverFactory { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverInstaller.java index 31aca6b527..c4311927ef 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/boolector/BoolectorSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,7 +22,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -43,10 +42,11 @@ protected String getSolverName() { @Override protected void installSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException { - final var downloadUrl = URI.create(String.format( - "https://github.com/Boolector/boolector/archive/refs/tags/%s.tar.gz", - version - )); + final var downloadUrl = + URI.create( + String.format( + "https://github.com/Boolector/boolector/archive/refs/tags/%s.tar.gz", + version)); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); @@ -60,18 +60,28 @@ protected void installSolver(final Path installDir, final String version) logger.write(Logger.Level.MAINSTEP, "Starting compilation\n"); - installDir.resolve("contrib").resolve("setup-lingeling.sh").toFile() + installDir + .resolve("contrib") + .resolve("setup-lingeling.sh") + .toFile() .setExecutable(true, true); executeCommand(installDir, "alias nproc=\"echo 1\" && ./contrib/setup-lingeling.sh"); - installDir.resolve("contrib").resolve("setup-btor2tools.sh").toFile() + installDir + .resolve("contrib") + .resolve("setup-btor2tools.sh") + .toFile() .setExecutable(true, true); executeCommand(installDir, "alias nproc=\"echo 1\" && ./contrib/setup-btor2tools.sh"); installDir.resolve("configure.sh").toFile().setExecutable(true, true); executeCommand(installDir, "./configure.sh"); executeCommand(installDir.resolve("build"), "make"); - installDir.resolve("build").resolve("bin").resolve(getSolverBinaryName()).toFile() + installDir + .resolve("build") + .resolve("bin") + .resolve(getSolverBinaryName()) + .toFile() .setExecutable(true, true); logger.write(Logger.Level.MAINSTEP, "Finished compilation\n"); @@ -85,24 +95,23 @@ protected void uninstallSolver(final Path installDir, final String version) { @Override protected String[] getDefaultSolverArgs(String version) { if (SemVer.of(version).compareTo(SemVer.of("3.2.2")) >= 0) { - return new String[]{ - "--smt2", - "-i" - }; + return new String[] {"--smt2", "-i"}; } else { - return new String[]{ - "--smt2", - "--smt2-model", - "-i" - }; + return new String[] {"--smt2", "--smt2-model", "-i"}; } } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { - final var solverFilePath = solverPath != null ? solverPath - : installDir.resolve("build").resolve("bin").resolve(getSolverBinaryName()); + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { + final var solverFilePath = + solverPath != null + ? solverPath + : installDir.resolve("build").resolve("bin").resolve(getSolverBinaryName()); return BoolectorSmtLibSolverFactory.create(solverFilePath, solverArgs); } @@ -124,12 +133,13 @@ private void executeCommand(final Path workingPath, final String command) throws SmtLibSolverInstallerException { try { logger.write(Logger.Level.SUBSTEP, "Execute command: %s\n", command); - final var process = new ProcessBuilder() - .command("bash", "-c", command) - .directory(workingPath.toFile()) - .redirectOutput(ProcessBuilder.Redirect.INHERIT) - .redirectError(ProcessBuilder.Redirect.INHERIT) - .start(); + final var process = + new ProcessBuilder() + .command("bash", "-c", command) + .directory(workingPath.toFile()) + .redirectOutput(ProcessBuilder.Redirect.INHERIT) + .redirectError(ProcessBuilder.Redirect.INHERIT) + .start(); if (process.waitFor() != 0) { throw new SmtLibSolverInstallerException( diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverFactory.java index 73a68a8a81..3b48d3bd34 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.cvc4; import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSolverBinary; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSolverFactory; - import java.nio.file.Path; import java.util.EnumSet; diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverInstaller.java index f0d1749378..da830e5c6e 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc4/CVC4SmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,16 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.cvc4; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; @@ -32,10 +35,6 @@ import java.util.Arrays; import java.util.List; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; - public class CVC4SmtLibSolverInstaller extends SmtLibSolverInstaller.Default { public CVC4SmtLibSolverInstaller(final Logger logger) { @@ -51,12 +50,17 @@ protected String getSolverName() { protected void installSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException { - try ( - final var inputChannel = Channels.newChannel(getDownloadUrl(version).openStream()); - final var outputChannel = new FileOutputStream( - installDir.resolve(getSolverBinaryName()).toAbsolutePath().toString()).getChannel() - ) { - logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", + try (final var inputChannel = Channels.newChannel(getDownloadUrl(version).openStream()); + final var outputChannel = + new FileOutputStream( + installDir + .resolve(getSolverBinaryName()) + .toAbsolutePath() + .toString()) + .getChannel()) { + logger.write( + Logger.Level.MAINSTEP, + "Starting download (%s)...\n", getDownloadUrl(version).toString()); outputChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); installDir.resolve(getSolverBinaryName()).toFile().setExecutable(true, true); @@ -74,17 +78,16 @@ protected void uninstallSolver(final Path installDir, final String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{ - "--lang", "smt2", - "--output-lang", "smt2", - "--quiet", - "--incremental" - }; + return new String[] {"--lang", "smt2", "--output-lang", "smt2", "--quiet", "--incremental"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { final var solverFilePath = solverPath != null ? solverPath : installDir.resolve(getSolverBinaryName()); return CVC4SmtLibSolverFactory.create(solverFilePath, solverArgs); @@ -120,10 +123,11 @@ private URL getDownloadUrl(final String version) } } - return URI.create(String.format( - "https://cvc4.cs.stanford.edu/downloads/builds/%s/cvc4-%s-%s%s", - archString, version, archString, platformExtension - )).toURL(); + return URI.create( + String.format( + "https://cvc4.cs.stanford.edu/downloads/builds/%s/cvc4-%s-%s%s", + archString, version, archString, platformExtension)) + .toURL(); } private String getSolverBinaryName() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpMarker.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpMarker.java index 5269b539e1..2e4245ae3e 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpMarker.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,6 +17,4 @@ import hu.bme.mit.theta.solver.smtlib.solver.interpolation.SmtLibItpMarker; -public class CVC5SmtLibItpMarker extends SmtLibItpMarker { - -} +public class CVC5SmtLibItpMarker extends SmtLibItpMarker {} diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpSolver.java index 039ba105c4..539312fb01 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.cvc5; +import static com.google.common.base.Preconditions.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.Decls; @@ -35,33 +40,30 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; +import java.util.*; +import java.util.function.Supplier; +import java.util.stream.Collectors; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.misc.Interval; -import java.util.*; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.*; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class CVC5SmtLibItpSolver extends SmtLibItpSolver { private final Supplier itpSolverBinaryFactory; - public CVC5SmtLibItpSolver(final SmtLibSymbolTable symbolTable, - final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary, - final Supplier itpSolverBinaryFactory, - final SmtLibEnumStrategy enumStrategy) { + public CVC5SmtLibItpSolver( + final SmtLibSymbolTable symbolTable, + final SmtLibTransformationManager transformationManager, + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary, + final Supplier itpSolverBinaryFactory, + final SmtLibEnumStrategy enumStrategy) { super(symbolTable, transformationManager, termTransformer, solverBinary, enumStrategy); this.itpSolverBinaryFactory = itpSolverBinaryFactory; final var tmp = Decls.Const("shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh", Int()); -// symbolTable.put(tmp, "shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh", "(declare-fun shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh () Int)"); + // symbolTable.put(tmp, "shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh", "(declare-fun + // shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh () Int)"); } @Override @@ -78,26 +80,33 @@ public CVC5SmtLibItpMarker createMarker() { } @Override - protected void add(CVC5SmtLibItpMarker marker, Expr assertion, - Set> consts, String term) { + protected void add( + CVC5SmtLibItpMarker marker, + Expr assertion, + Set> consts, + String term) { consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); issueGeneralCommand(String.format("(assert %s)", term)); } @Override public Interpolant getInterpolant(ItpPattern pattern) { - checkState(getStatus() == SolverStatus.UNSAT, + checkState( + getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof SmtLibItpPattern); try (final var itpSolverBinary = itpSolverBinaryFactory.get()) { itpSolverBinary.issueCommand("(set-option :produce-interpolants true)"); itpSolverBinary.issueCommand("(set-logic ALL)"); - enumStrategy.declareDatatypes(typeStack.toCollection(), new StackImpl<>(), itpSolverBinary::issueCommand); + enumStrategy.declareDatatypes( + typeStack.toCollection(), new StackImpl<>(), itpSolverBinary::issueCommand); declarationStack.forEach( - constDecl -> itpSolverBinary.issueCommand(symbolTable.getDeclaration(constDecl))); + constDecl -> + itpSolverBinary.issueCommand(symbolTable.getDeclaration(constDecl))); - @SuppressWarnings("unchecked") final var cvc5ItpPattern = (SmtLibItpPattern) pattern; + @SuppressWarnings("unchecked") + final var cvc5ItpPattern = (SmtLibItpPattern) pattern; final List markers = cvc5ItpPattern.getSequence(); final List A = new ArrayList<>(); final List B = new ArrayList<>(markers); @@ -109,25 +118,32 @@ public Interpolant getInterpolant(ItpPattern pattern) { A.add(marker); if (B.size() != 0) { - final var aTerm = A.stream() - .flatMap(m -> m.getTerms().stream().map(Tuple2::get2)); - final var bTerm = B.stream() - .flatMap(m -> m.getTerms().stream().map(Tuple2::get2)); + final var aTerm = + A.stream().flatMap(m -> m.getTerms().stream().map(Tuple2::get2)); + final var bTerm = + B.stream().flatMap(m -> m.getTerms().stream().map(Tuple2::get2)); itpSolverBinary.issueCommand("(push)"); - itpSolverBinary.issueCommand("(declare-fun shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh () Int)"); - itpSolverBinary.issueCommand("(assert (= shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh 0))"); itpSolverBinary.issueCommand( - String.format("(assert (and %s))", aTerm.collect(Collectors.joining(" ")))); + "(declare-fun shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh () Int)"); + itpSolverBinary.issueCommand( + "(assert (= shevgcrjhsdfzgrjbms2dhrbcshdmrgcsh 0))"); + itpSolverBinary.issueCommand( + String.format( + "(assert (and %s))", aTerm.collect(Collectors.joining(" ")))); itpSolverBinary.issueCommand( - String.format("(get-interpolant _cvc5_interpolant%d (not (and %s)))", + String.format( + "(get-interpolant _cvc5_interpolant%d (not (and %s)))", interpolantCount++, bTerm.collect(Collectors.joining(" ")))); itpSolverBinary.issueCommand("(pop)"); final String solverResponse = itpSolverBinary.readResponse(); - itpMap.put(marker, - termTransformer.toExpr(parseItpResponse(solverResponse), - Bool(), new SmtLibModel(Collections.emptyMap()))); + itpMap.put( + marker, + termTransformer.toExpr( + parseItpResponse(solverResponse), + Bool(), + new SmtLibModel(Collections.emptyMap()))); } else { itpMap.put(marker, False()); } @@ -159,7 +175,8 @@ private String parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverFactory.java index 2e6420481c..b4891b97a9 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,23 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.cvc5; import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.smtlib.impl.generic.*; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibEnumStrategy; - import java.nio.file.Path; import java.util.EnumSet; public class CVC5SmtLibSolverFactory extends GenericSmtLibSolverFactory { - private CVC5SmtLibSolverFactory(Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { + private CVC5SmtLibSolverFactory( + Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { super(solverPath, args, enumStrategy); } - public static CVC5SmtLibSolverFactory create(Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { + public static CVC5SmtLibSolverFactory create( + Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { return new CVC5SmtLibSolverFactory(solverPath, args, enumStrategy); } @@ -38,13 +38,20 @@ public ItpSolver createItpSolver() { final var symbolTable = new GenericSmtLibSymbolTable(); final var transformationManager = new GenericSmtLibTransformationManager(symbolTable); final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); - final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args, - EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class)); + final var solverBinary = + new GenericSmtLibSolverBinary( + solverPath, args, EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class)); return new CVC5SmtLibItpSolver( - symbolTable, transformationManager, termTransformer, solverBinary, - () -> new GenericSmtLibSolverBinary(solverPath, args, - EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class)), enumStrategy - ); + symbolTable, + transformationManager, + termTransformer, + solverBinary, + () -> + new GenericSmtLibSolverBinary( + solverPath, + args, + EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class)), + enumStrategy); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverInstaller.java index 6d13d05cd7..35bc1f756e 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/cvc5/CVC5SmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.cvc5; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.MAC; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; @@ -23,7 +28,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; @@ -35,11 +39,6 @@ import java.util.Arrays; import java.util.List; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.MAC; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; - public class CVC5SmtLibSolverInstaller extends SmtLibSolverInstaller.Default { private static final SmtLibEnumStrategy ENUM_STRATEGY = SmtLibEnumStrategy.DATATYPES; @@ -50,18 +49,18 @@ public CVC5SmtLibSolverInstaller(final Logger logger) { super(logger); versions = new ArrayList<>(); - versions.add(SemVer.VersionDecoder.create(SemVer.of("1.1.1")) - .addString(LINUX, X64, "Linux-static.zip") - .addString(MAC, X64, "macOS-arm64-static.zip") - .addString(WINDOWS, X64, "Win64-static.zip") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("1.0.0")) - .addString(LINUX, X64, "Linux") - .addString(MAC, X64, "macOS") - .addString(WINDOWS, X64, "Win64.exe") - .build() - ); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("1.1.1")) + .addString(LINUX, X64, "Linux-static.zip") + .addString(MAC, X64, "macOS-arm64-static.zip") + .addString(WINDOWS, X64, "Win64-static.zip") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("1.0.0")) + .addString(LINUX, X64, "Linux") + .addString(MAC, X64, "macOS") + .addString(WINDOWS, X64, "Win64.exe") + .build()); } @Override @@ -70,30 +69,49 @@ protected String getSolverName() { } @Override - protected void installSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException { + protected void installSolver(final Path installDir, final String version) + throws SmtLibSolverInstallerException { try (final var inputStream = getDownloadUrl(version).openStream()) { - logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", getDownloadUrl(version).toString()); + logger.write( + Logger.Level.MAINSTEP, + "Starting download (%s)...\n", + getDownloadUrl(version).toString()); if (SemVer.of(version).compareTo(SemVer.of("1.1.1")) < 0) { - try ( - final var inputChannel = Channels.newChannel(inputStream); - final var outputChannel = new FileOutputStream(installDir.resolve(getSolverBinaryName(version)).toAbsolutePath().toString()).getChannel() - ) { + try (final var inputChannel = Channels.newChannel(inputStream); + final var outputChannel = + new FileOutputStream( + installDir + .resolve(getSolverBinaryName(version)) + .toAbsolutePath() + .toString()) + .getChannel()) { outputChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); - installDir.resolve(getSolverBinaryName(version)).toFile().setExecutable(true, true); + installDir + .resolve(getSolverBinaryName(version)) + .toFile() + .setExecutable(true, true); } } else { Compress.extract(inputStream, installDir, Compress.CompressionType.ZIP); - installDir.resolve("bin").resolve(getSolverBinaryName(version)).toFile().setExecutable(true, true); + installDir + .resolve("bin") + .resolve(getSolverBinaryName(version)) + .toFile() + .setExecutable(true, true); } } catch (IOException e) { throw new SmtLibSolverInstallerException(e); } - try ( - final var inputChannel = Channels.newChannel(getLicenseDownloadUrl().openStream()); - final var outputChannel = new FileOutputStream(installDir.resolve("COPYING").toAbsolutePath().toString()).getChannel() - ) { - logger.write(Logger.Level.MAINSTEP, "Starting license download (%s)...\n", getLicenseDownloadUrl().toString()); + try (final var inputChannel = Channels.newChannel(getLicenseDownloadUrl().openStream()); + final var outputChannel = + new FileOutputStream( + installDir.resolve("COPYING").toAbsolutePath().toString()) + .getChannel()) { + logger.write( + Logger.Level.MAINSTEP, + "Starting license download (%s)...\n", + getLicenseDownloadUrl().toString()); outputChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); } catch (IOException e) { throw new SmtLibSolverInstallerException(e); @@ -109,22 +127,29 @@ protected void uninstallSolver(final Path installDir, final String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{ - "--lang", "smt2", - "--output-lang", "smt2", - "--quiet", - "--incremental", - "--fp-exp" + return new String[] { + "--lang", "smt2", "--output-lang", "smt2", "--quiet", "--incremental", "--fp-exp" }; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { final Path solverFilePath; if (SemVer.of(version).compareTo(SemVer.of("1.1.1")) < 0) { - solverFilePath = solverPath != null ? solverPath : installDir.resolve(getSolverBinaryName(version)); + solverFilePath = + solverPath != null + ? solverPath + : installDir.resolve(getSolverBinaryName(version)); } else { - solverFilePath = solverPath != null ? solverPath : installDir.resolve("bin").resolve(getSolverBinaryName(version)); + solverFilePath = + solverPath != null + ? solverPath + : installDir.resolve("bin").resolve(getSolverBinaryName(version)); } return CVC5SmtLibSolverFactory.create(solverFilePath, solverArgs, ENUM_STRATEGY); } @@ -132,18 +157,21 @@ public SolverFactory getSolverFactory(final Path installDir, final String versio @Override public List getSupportedVersions() { return Arrays.asList( - "1.1.2", "1.1.1", "1.1.0", "1.0.9", "1.0.8", "1.0.7", "1.0.6", "1.0.5", "1.0.4", "1.0.3", "1.0.2", "1.0.1", "1.0.0" - ); + "1.1.2", "1.1.1", "1.1.0", "1.0.9", "1.0.8", "1.0.7", "1.0.6", "1.0.5", "1.0.4", + "1.0.3", "1.0.2", "1.0.1", "1.0.0"); } - private URL getDownloadUrl(final String version) throws SmtLibSolverInstallerException, MalformedURLException { - return URI.create(String.format( - "https://github.com/cvc5/cvc5/releases/download/cvc5-%s/cvc5-%s", - version, getArchString(version) - )).toURL(); + private URL getDownloadUrl(final String version) + throws SmtLibSolverInstallerException, MalformedURLException { + return URI.create( + String.format( + "https://github.com/cvc5/cvc5/releases/download/cvc5-%s/cvc5-%s", + version, getArchString(version))) + .toURL(); } - private URL getLicenseDownloadUrl() throws SmtLibSolverInstallerException, MalformedURLException { + private URL getLicenseDownloadUrl() + throws SmtLibSolverInstallerException, MalformedURLException { return URI.create("https://raw.githubusercontent.com/cvc5/cvc5/main/COPYING").toURL(); } @@ -158,7 +186,10 @@ private String getArchString(final String version) throws SmtLibSolverInstallerE } } if (archStr == null) { - throw new SmtLibSolverInstallerException(String.format("CVC5 on operating system %s and architecture %s is not supported", OsHelper.getOs(), OsHelper.getArch())); + throw new SmtLibSolverInstallerException( + String.format( + "CVC5 on operating system %s and architecture %s is not supported", + OsHelper.getOs(), OsHelper.getArch())); } return archStr; @@ -170,6 +201,5 @@ private String getSolverBinaryName(final String version) throws SmtLibSolverInst } else { return OsHelper.getOs() == WINDOWS ? "cvc5.exe" : "cvc5"; } - } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverFactory.java index 46ccc72a69..f1b463dce7 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,7 +25,6 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTransformationManager; - import java.nio.file.Path; public class EldaricaSmtLibSolverFactory extends GenericSmtLibSolverFactory { @@ -40,12 +39,14 @@ public static EldaricaSmtLibSolverFactory create(Path solverPath, String[] args) @Override public Solver createSolver() { - throw new UnsupportedOperationException("Eldarica factory cannot create conventional solvers"); + throw new UnsupportedOperationException( + "Eldarica factory cannot create conventional solvers"); } @Override public UCSolver createUCSolver() { - throw new UnsupportedOperationException("Eldarica factory cannot create conventional solvers"); + throw new UnsupportedOperationException( + "Eldarica factory cannot create conventional solvers"); } @Override @@ -55,11 +56,13 @@ public HornSolver createHornSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable); final var solverBinary = new GenericSmtLibOneshotSolverBinary(solverPath, args); - return new GenericHornSolver(symbolTable, transformationManager, termTransformer, solverBinary); + return new GenericHornSolver( + symbolTable, transformationManager, termTransformer, solverBinary); } @Override public ItpSolver createItpSolver() { - throw new UnsupportedOperationException("Eldarica factory cannot create conventional solvers"); + throw new UnsupportedOperationException( + "Eldarica factory cannot create conventional solvers"); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverInstaller.java index adbfa821c7..f590b34bc2 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/eldarica/EldaricaSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.eldarica; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; @@ -22,7 +25,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -30,9 +32,6 @@ import java.util.Arrays; import java.util.List; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; - public class EldaricaSmtLibSolverInstaller extends SmtLibSolverInstaller.Default { private final List versions; @@ -41,10 +40,10 @@ public EldaricaSmtLibSolverInstaller(final Logger logger) { super(logger); versions = new ArrayList<>(); - versions.add(SemVer.VersionDecoder.create(SemVer.of("2.1")) - .addString(LINUX, X64, "zip") - .build() - ); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("2.1")) + .addString(LINUX, X64, "zip") + .build()); } @Override @@ -66,20 +65,21 @@ protected void installSolver(final Path installDir, final String version) } if (archStr == null) { throw new SmtLibSolverInstallerException( - String.format("%s on operating system %s and architecture %s is not supported", + String.format( + "%s on operating system %s and architecture %s is not supported", getSolverName(), OsHelper.getOs(), OsHelper.getArch())); } - final var downloadUrl = URI.create(String.format( - "https://github.com/uuverifiers/eldarica/releases/download/v%s/eldarica-bin-%s.%s", - version, version, archStr - )); + final var downloadUrl = + URI.create( + String.format( + "https://github.com/uuverifiers/eldarica/releases/download/v%s/eldarica-bin-%s.%s", + version, version, archStr)); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); try (final var inputStream = downloadUrl.toURL().openStream()) { Compress.extract(inputStream, installDir, Compress.CompressionType.ZIP); - installDir.resolve(getSolverBinaryName()).toFile() - .setExecutable(true, true); + installDir.resolve(getSolverBinaryName()).toFile().setExecutable(true, true); } catch (IOException e) { throw new SmtLibSolverInstallerException(e); } @@ -94,14 +94,18 @@ protected void uninstallSolver(Path installDir, String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{"-ssol", "-scex"}; + return new String[] {"-ssol", "-scex"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { - final var solverFilePath = solverPath != null ? solverPath - : installDir.resolve(getSolverBinaryName()); + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { + final var solverFilePath = + solverPath != null ? solverPath : installDir.resolve(getSolverBinaryName()); return EldaricaSmtLibSolverFactory.create(solverFilePath, solverArgs); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericHornSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericHornSolver.java index e11d2b4fbe..a4b43ec7aa 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericHornSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericHornSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.HornSolver; @@ -30,7 +33,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; - import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -39,22 +41,27 @@ import java.util.Map; import java.util.regex.Pattern; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - - -/** - * This solver expects the Horn solver-style proofs for counterexamples - */ +/** This solver expects the Horn solver-style proofs for counterexamples */ public class GenericHornSolver extends SmtLibSolver implements HornSolver { - private static final Pattern CEX_PATTERN = Pattern.compile("([0-9]+):\s*(.*)(?=->)->(\s*([0-9]+)(,?\s+[0-9]+)*)?"); + private static final Pattern CEX_PATTERN = + Pattern.compile("([0-9]+):\s*(.*)(?=->)->(\s*([0-9]+)(,?\s+[0-9]+)*)?"); private static final Pattern CEX_ROOT = Pattern.compile("([0-9]+):\s*(.*)"); private ProofNode proof = null; - public GenericHornSolver(SmtLibSymbolTable symbolTable, SmtLibTransformationManager transformationManager, SmtLibTermTransformer termTransformer, SmtLibSolverBinary solverBinary) { - super(symbolTable, transformationManager, termTransformer, solverBinary, false, SmtLibEnumStrategy.getDefaultStrategy(), "HORN"); + public GenericHornSolver( + SmtLibSymbolTable symbolTable, + SmtLibTransformationManager transformationManager, + SmtLibTermTransformer termTransformer, + SmtLibSolverBinary solverBinary) { + super( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + false, + SmtLibEnumStrategy.getDefaultStrategy(), + "HORN"); } @Override @@ -66,7 +73,10 @@ public void track(Expr assertion) { public SolverStatus check() { solverBinary.issueCommand("(check-sat)"); final var response = solverBinary.readResponse().lines().toList(); - status = response.get(0).equals("sat") ? SolverStatus.SAT : response.get(0).equals("unsat") ? SolverStatus.UNSAT : null; + status = + response.get(0).equals("sat") + ? SolverStatus.SAT + : response.get(0).equals("unsat") ? SolverStatus.UNSAT : null; if (status == SolverStatus.SAT) { // we have a model final var sb = new StringBuilder(); @@ -77,8 +87,12 @@ public SolverStatus check() { sb.append(")"); final var generalResponse = parseResponse(sb.toString()); if (generalResponse.isSpecific() && generalResponse.asSpecific().isGetModelResponse()) { - model = new SmtLibValuation(symbolTable, transformationManager, termTransformer, - generalResponse.asSpecific().asGetModelResponse().getModel()); + model = + new SmtLibValuation( + symbolTable, + transformationManager, + termTransformer, + generalResponse.asSpecific().asGetModelResponse().getModel()); } } else if (status == SolverStatus.UNSAT) { // we have a cex (beginning with an empty line) @@ -94,7 +108,11 @@ public SolverStatus check() { idx = Integer.parseInt(matcher.group(1)); term = matcher.group(2); if (matcher.group(3) != null) { - dependencies = Arrays.stream(matcher.group(3).split(",?\s+")).filter(it -> !it.isEmpty()).map(it -> Integer.parseInt(it.trim())).toList(); + dependencies = + Arrays.stream(matcher.group(3).split(",?\s+")) + .filter(it -> !it.isEmpty()) + .map(it -> Integer.parseInt(it.trim())) + .toList(); } else { dependencies = List.of(); } @@ -107,7 +125,9 @@ public SolverStatus check() { } } if (idx != -1) { - final var expr = termTransformer.toExpr(term, Bool(), new SmtLibModel(Collections.emptyMap())); + final var expr = + termTransformer.toExpr( + term, Bool(), new SmtLibModel(Collections.emptyMap())); final var builder = new ProofNode.Builder(expr); if (root == null && expr.equals(False())) { root = builder; @@ -116,11 +136,10 @@ public SolverStatus check() { dependencyMap.put(builder, dependencies); } } - dependencyMap.forEach((builder, integers) -> - integers.forEach(integer -> builder.addChild(builderMap.get(integer))) - ); + dependencyMap.forEach( + (builder, integers) -> + integers.forEach(integer -> builder.addChild(builderMap.get(integer)))); proof = root.build(); - } return status; } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibDeclTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibDeclTransformer.java index c535776309..57183fc338 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibDeclTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibDeclTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; @@ -24,11 +26,8 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibDeclTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; - public class GenericSmtLibDeclTransformer implements SmtLibDeclTransformer { private final SmtLibTransformationManager transformer; @@ -36,8 +35,8 @@ public class GenericSmtLibDeclTransformer implements SmtLibDeclTransformer { private int symbolCount; - public GenericSmtLibDeclTransformer(final SmtLibTransformationManager transformer, - final SmtLibSymbolTable symbolTable) { + public GenericSmtLibDeclTransformer( + final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { this.transformer = transformer; this.symbolTable = symbolTable; @@ -78,14 +77,14 @@ private void transformConst(final ConstDecl decl) { final Type returnType = extractedTypes.get2(); final String returnSort = transformer.toSort(returnType); - final String[] paramSorts = paramTypes.stream().map(transformer::toSort) - .toArray(String[]::new); + final String[] paramSorts = + paramTypes.stream().map(transformer::toSort).toArray(String[]::new); final String symbolName = symbolNameFor(decl); - final String symbolDeclaration = String.format( - "(declare-fun %s (%s) %s)", - symbolName, String.join(" ", paramSorts), returnSort - ); + final String symbolDeclaration = + String.format( + "(declare-fun %s (%s) %s)", + symbolName, String.join(" ", paramSorts), returnSort); symbolTable.put(decl, symbolName, symbolDeclaration); } @@ -101,8 +100,8 @@ private Tuple2, Type> extractTypes(final Type type) { final Tuple2, Type> subResult = extractTypes(resultType); final List paramTypes = subResult.get1(); final Type newResultType = subResult.get2(); - final List newParamTypes = ImmutableList.builder().add(paramType) - .addAll(paramTypes).build(); + final List newParamTypes = + ImmutableList.builder().add(paramType).addAll(paramTypes).build(); final Tuple2, Type> result = Tuple2.of(newParamTypes, newResultType); return result; @@ -114,5 +113,4 @@ private Tuple2, Type> extractTypes(final Type type) { private String symbolNameFor(final Decl decl) { return String.format("%s_%d", decl.getName(), symbolCount++); } - } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibExprTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibExprTransformer.java index 753dc0a462..cc8cc81545 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibExprTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; + import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.DispatchTable; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.dsl.Env; @@ -150,15 +151,11 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibExprTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; - import java.math.BigInteger; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; - public class GenericSmtLibExprTransformer implements SmtLibExprTransformer { private static final int CACHE_SIZE = 1000; @@ -170,7 +167,8 @@ public class GenericSmtLibExprTransformer implements SmtLibExprTransformer { private final DispatchTable table; private final Env env; - public GenericSmtLibExprTransformer(final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { + public GenericSmtLibExprTransformer( + final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { this.transformer = transformer; this.symbolTable = symbolTable; this.env = new Env(); @@ -179,230 +177,133 @@ public GenericSmtLibExprTransformer(final SmtLibTransformationManager transforme this.table = buildDispatchTable(DispatchTable.builder()).build(); } - protected DispatchTable.Builder buildDispatchTable(DispatchTable.Builder builder) { + protected DispatchTable.Builder buildDispatchTable( + DispatchTable.Builder builder) { builder // General .addCase(RefExpr.class, this::transformRef) - .addCase(IteExpr.class, this::transformIte) // Boolean .addCase(FalseExpr.class, this::transformFalse) - .addCase(TrueExpr.class, this::transformTrue) - .addCase(NotExpr.class, this::transformNot) - .addCase(ImplyExpr.class, this::transformImply) - .addCase(IffExpr.class, this::transformIff) - .addCase(XorExpr.class, this::transformXor) - .addCase(AndExpr.class, this::transformAnd) - .addCase(OrExpr.class, this::transformOr) - .addCase(ExistsExpr.class, this::transformExists) - .addCase(ForallExpr.class, this::transformForall) // Rationals .addCase(RatLitExpr.class, this::transformRatLit) - .addCase(RatAddExpr.class, this::transformRatAdd) - .addCase(RatSubExpr.class, this::transformRatSub) - .addCase(RatPosExpr.class, this::transformRatPos) - .addCase(RatNegExpr.class, this::transformRatNeg) - .addCase(RatMulExpr.class, this::transformRatMul) - .addCase(RatDivExpr.class, this::transformRatDiv) - .addCase(RatEqExpr.class, this::transformRatEq) - .addCase(RatNeqExpr.class, this::transformRatNeq) - .addCase(RatGeqExpr.class, this::transformRatGeq) - .addCase(RatGtExpr.class, this::transformRatGt) - .addCase(RatLeqExpr.class, this::transformRatLeq) - .addCase(RatLtExpr.class, this::transformRatLt) - .addCase(RatToIntExpr.class, this::transformRatToInt) // Integers .addCase(IntLitExpr.class, this::transformIntLit) - .addCase(IntAddExpr.class, this::transformIntAdd) - .addCase(IntSubExpr.class, this::transformIntSub) - .addCase(IntPosExpr.class, this::transformIntPos) - .addCase(IntNegExpr.class, this::transformIntNeg) - .addCase(IntMulExpr.class, this::transformIntMul) - .addCase(IntDivExpr.class, this::transformIntDiv) - .addCase(IntModExpr.class, this::transformIntMod) - .addCase(IntRemExpr.class, this::transformIntRem) - .addCase(IntEqExpr.class, this::transformIntEq) - .addCase(IntNeqExpr.class, this::transformIntNeq) - .addCase(IntGeqExpr.class, this::transformIntGeq) - .addCase(IntGtExpr.class, this::transformIntGt) - .addCase(IntLeqExpr.class, this::transformIntLeq) - .addCase(IntLtExpr.class, this::transformIntLt) - .addCase(IntToRatExpr.class, this::transformIntToRat) // Enums .addCase(EnumLitExpr.class, this::transformEnumLit) - .addCase(EnumNeqExpr.class, this::transformEnumNeq) - .addCase(EnumEqExpr.class, this::transformEnumEq) // Bitvectors .addCase(BvLitExpr.class, this::transformBvLit) - .addCase(BvConcatExpr.class, this::transformBvConcat) - .addCase(BvExtractExpr.class, this::transformBvExtract) - .addCase(BvZExtExpr.class, this::transformBvZExt) - .addCase(BvSExtExpr.class, this::transformBvSExt) - .addCase(BvAddExpr.class, this::transformBvAdd) - .addCase(BvSubExpr.class, this::transformBvSub) - .addCase(BvPosExpr.class, this::transformBvPos) - .addCase(BvSignChangeExpr.class, this::transformBvSignChange) - .addCase(BvNegExpr.class, this::transformBvNeg) - .addCase(BvMulExpr.class, this::transformBvMul) - .addCase(BvUDivExpr.class, this::transformBvUDiv) - .addCase(BvSDivExpr.class, this::transformBvSDiv) - .addCase(BvSModExpr.class, this::transformBvSMod) - .addCase(BvURemExpr.class, this::transformBvURem) - .addCase(BvSRemExpr.class, this::transformBvSRem) - .addCase(BvAndExpr.class, this::transformBvAnd) - .addCase(BvOrExpr.class, this::transformBvOr) - .addCase(BvXorExpr.class, this::transformBvXor) - .addCase(BvNotExpr.class, this::transformBvNot) - .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) - .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) - .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) - .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) - .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) - .addCase(BvEqExpr.class, this::transformBvEq) - .addCase(BvNeqExpr.class, this::transformBvNeq) - .addCase(BvUGeqExpr.class, this::transformBvUGeq) - .addCase(BvUGtExpr.class, this::transformBvUGt) - .addCase(BvULeqExpr.class, this::transformBvULeq) - .addCase(BvULtExpr.class, this::transformBvULt) - .addCase(BvSGeqExpr.class, this::transformBvSGeq) - .addCase(BvSGtExpr.class, this::transformBvSGt) - .addCase(BvSLeqExpr.class, this::transformBvSLeq) - .addCase(BvSLtExpr.class, this::transformBvSLt) // Floating points .addCase(FpLitExpr.class, this::transformFpLit) - .addCase(FpAddExpr.class, this::transformFpAdd) - .addCase(FpSubExpr.class, this::transformFpSub) - .addCase(FpPosExpr.class, this::transformFpPos) - .addCase(FpNegExpr.class, this::transformFpNeg) - .addCase(FpMulExpr.class, this::transformFpMul) - .addCase(FpDivExpr.class, this::transformFpDiv) - .addCase(FpEqExpr.class, this::transformFpEq) - .addCase(FpAssignExpr.class, this::transformFpAssign) - .addCase(FpGeqExpr.class, this::transformFpGeq) - .addCase(FpLeqExpr.class, this::transformFpLeq) - .addCase(FpGtExpr.class, this::transformFpGt) - .addCase(FpLtExpr.class, this::transformFpLt) - .addCase(FpNeqExpr.class, this::transformFpNeq) - .addCase(FpAbsExpr.class, this::transformFpAbs) - .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) - .addCase(FpMaxExpr.class, this::transformFpMax) - .addCase(FpMinExpr.class, this::transformFpMin) - .addCase(FpSqrtExpr.class, this::transformFpSqrt) - .addCase(FpRemExpr.class, this::transformFpRem) - .addCase(FpIsNanExpr.class, this::transformFpIsNaN) - .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) - .addCase(FpFromBvExpr.class, this::transformFpFromBv) - .addCase(FpToBvExpr.class, this::transformFpToBv) - .addCase(FpToFpExpr.class, this::transformFpToFp) // Functions @@ -412,21 +313,15 @@ protected DispatchTable.Builder buildDispatchTable(DispatchTable.Builder // Arrays .addCase(ArrayReadExpr.class, this::transformArrayRead) - .addCase(ArrayWriteExpr.class, this::transformArrayWrite) - .addCase(ArrayEqExpr.class, this::transformArrayEq) - .addCase(ArrayNeqExpr.class, this::transformArrayNeq) - .addCase(ArrayLitExpr.class, this::transformArrayLit) - .addCase(ArrayInitExpr.class, this::transformArrayInit) // References - .addCase(Dereference.class, this::transformDereference) + .addCase(Dereference.class, this::transformDereference); - ; return builder; } @@ -498,12 +393,12 @@ protected String transformAnd(final AndExpr expr) { } else if (expr.getArity() == 0) { return "true"; } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(and %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(and %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(and %s %s)", op1, op2)); } } @@ -513,12 +408,12 @@ protected String transformOr(final OrExpr expr) { } else if (expr.getArity() == 0) { return "false"; } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(or %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(or %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(or %s %s)", op1, op2)); } } @@ -526,8 +421,8 @@ protected String transformExists(final ExistsExpr expr) { env.push(); final String[] paramTerms = transformParamDecls(expr.getParamDecls()); final String opTerm = toTerm(expr.getOp()); - final String result = String.format("(exists (%s) %s)", String.join(" ", paramTerms), - opTerm); + final String result = + String.format("(exists (%s) %s)", String.join(" ", paramTerms), opTerm); env.pop(); return result; } @@ -536,8 +431,8 @@ protected String transformForall(final ForallExpr expr) { env.push(); final String[] paramTerms = transformParamDecls(expr.getParamDecls()); final String opTerm = toTerm(expr.getOp()); - final String result = String.format("(forall (%s) %s)", String.join(" ", paramTerms), - opTerm); + final String result = + String.format("(forall (%s) %s)", String.join(" ", paramTerms), opTerm); env.pop(); return result; } @@ -577,12 +472,12 @@ protected String transformRatAdd(final RatAddExpr expr) { } else if (expr.getArity() == 0) { return "0.0"; } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(+ %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(+ %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(+ %s %s)", op1, op2)); } } @@ -604,12 +499,12 @@ protected String transformRatMul(final RatMulExpr expr) { } else if (expr.getArity() == 0) { return "1.0"; } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(* %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(* %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(* %s %s)", op1, op2)); } } @@ -622,8 +517,8 @@ protected String transformRatEq(final RatEqExpr expr) { } protected String transformRatNeq(final RatNeqExpr expr) { - return String.format("(not (= %s %s))", toTerm(expr.getLeftOp()), - toTerm(expr.getRightOp())); + return String.format( + "(not (= %s %s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } protected String transformRatGeq(final RatGeqExpr expr) { @@ -664,12 +559,12 @@ protected String transformIntAdd(final IntAddExpr expr) { } else if (expr.getArity() == 0) { return "0"; } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(+ %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(+ %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(+ %s %s)", op1, op2)); } } @@ -691,12 +586,12 @@ protected String transformIntMul(final IntMulExpr expr) { } else if (expr.getArity() == 0) { return "1"; } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(* %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(* %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(* %s %s)", op1, op2)); } } @@ -717,8 +612,8 @@ protected String transformIntEq(final IntEqExpr expr) { } protected String transformIntNeq(final IntNeqExpr expr) { - return String.format("(not (= %s %s))", toTerm(expr.getLeftOp()), - toTerm(expr.getRightOp())); + return String.format( + "(not (= %s %s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } protected String transformIntGeq(final IntGeqExpr expr) { @@ -750,8 +645,8 @@ protected String transformEnumEq(final EnumEqExpr expr) { } protected String transformEnumNeq(final EnumNeqExpr expr) { - return String.format("(not (= %s %s))", toTerm(expr.getLeftOp()), - toTerm(expr.getRightOp())); + return String.format( + "(not (= %s %s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } protected String transformEnumLit(final EnumLitExpr expr) { @@ -775,9 +670,7 @@ protected String transformBvLit(final BvLitExpr expr) { } protected String transformBvConcat(final BvConcatExpr expr) { - final String[] opTerms = expr.getOps().stream() - .map(this::toTerm) - .toArray(String[]::new); + final String[] opTerms = expr.getOps().stream().map(this::toTerm).toArray(String[]::new); return String.format("(concat %s)", String.join(" ", opTerms)); } @@ -804,14 +697,15 @@ protected String transformBvAdd(final BvAddExpr expr) { return toTerm(expr.getOps().get(0)); } else if (expr.getArity() == 0) { return toTerm( - BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.ZERO, expr.getType().getSize())); + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.ZERO, expr.getType().getSize())); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(bvadd %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(bvadd %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(bvadd %s %s)", op1, op2)); } } @@ -838,12 +732,12 @@ protected String transformBvMul(final BvMulExpr expr) { return toTerm( BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.ONE, expr.getType().getSize())); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(bvmul %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(bvmul %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(bvmul %s %s)", op1, op2)); } } @@ -871,16 +765,17 @@ protected String transformBvAnd(final BvAndExpr expr) { if (expr.getArity() == 1) { return toTerm(expr.getOps().get(0)); } else if (expr.getArity() == 0) { - return toTerm(BvUtils.bigIntegerToNeutralBvLitExpr( - BigInteger.TWO.pow(expr.getType().getSize()).subtract(BigInteger.ONE), - expr.getType().getSize())); + return toTerm( + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.TWO.pow(expr.getType().getSize()).subtract(BigInteger.ONE), + expr.getType().getSize())); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(bvand %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(bvand %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(bvand %s %s)", op1, op2)); } } @@ -889,14 +784,15 @@ protected String transformBvOr(final BvOrExpr expr) { return toTerm(expr.getOps().get(0)); } else if (expr.getArity() == 0) { return toTerm( - BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.ZERO, expr.getType().getSize())); + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.ZERO, expr.getType().getSize())); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(bvor %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(bvor %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(bvor %s %s)", op1, op2)); } } @@ -905,14 +801,15 @@ protected String transformBvXor(final BvXorExpr expr) { return toTerm(expr.getOps().get(0)); } else if (expr.getArity() == 0) { return toTerm( - BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.ZERO, expr.getType().getSize())); + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.ZERO, expr.getType().getSize())); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), (acc, op) -> String.format("(bvxor %s %s)", acc, toTerm(op)), - (op1, op2) -> String.format("(bvxor %s %s)", op1, op2) - ); + (op1, op2) -> String.format("(bvxor %s %s)", op1, op2)); } } @@ -935,21 +832,27 @@ protected String transformBvLogicShiftRight(final BvLogicShiftRightExpr expr) { protected String transformBvRotateLeft(final BvRotateLeftExpr expr) { final var toRotate = toTerm(expr.getLeftOp()); final var rotateWith = toTerm(expr.getRightOp()); - final var size = toTerm( - BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.valueOf(expr.getType().getSize()), - expr.getType().getSize())); - return String.format("(bvor (bvshl %s %s) (bvlshr %s (bvsub %s %s)))", toRotate, rotateWith, - toRotate, size, rotateWith); + final var size = + toTerm( + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.valueOf(expr.getType().getSize()), + expr.getType().getSize())); + return String.format( + "(bvor (bvshl %s %s) (bvlshr %s (bvsub %s %s)))", + toRotate, rotateWith, toRotate, size, rotateWith); } protected String transformBvRotateRight(final BvRotateRightExpr expr) { final var toRotate = toTerm(expr.getLeftOp()); final var rotateWith = toTerm(expr.getRightOp()); - final var size = toTerm( - BvUtils.bigIntegerToNeutralBvLitExpr(BigInteger.valueOf(expr.getType().getSize()), - expr.getType().getSize())); - return String.format("(bvor (bvlshr %s %s) (bvshl %s (bvsub %s %s)))", toRotate, rotateWith, - toRotate, size, rotateWith); + final var size = + toTerm( + BvUtils.bigIntegerToNeutralBvLitExpr( + BigInteger.valueOf(expr.getType().getSize()), + expr.getType().getSize())); + return String.format( + "(bvor (bvlshr %s %s) (bvshl %s (bvsub %s %s)))", + toRotate, rotateWith, toRotate, size, rotateWith); } protected String transformBvEq(final BvEqExpr expr) { @@ -957,8 +860,8 @@ protected String transformBvEq(final BvEqExpr expr) { } protected String transformBvNeq(final BvNeqExpr expr) { - return String.format("(not (= %s %s))", toTerm(expr.getLeftOp()), - toTerm(expr.getRightOp())); + return String.format( + "(not (= %s %s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } protected String transformBvUGeq(final BvUGeqExpr expr) { @@ -998,34 +901,46 @@ protected String transformBvSLt(final BvSLtExpr expr) { */ protected String transformFpLit(final FpLitExpr expr) { - return String.format("(fp #b%s #b%s #b%s)", + return String.format( + "(fp #b%s #b%s #b%s)", expr.getHidden() ? "1" : "0", transformBvLit(expr.getExponent()).substring(2), - transformBvLit(expr.getSignificand()).substring(2) - ); + transformBvLit(expr.getSignificand()).substring(2)); } protected String transformFpAdd(final FpAddExpr expr) { if (expr.getArity() == 1) { return toTerm(expr.getOps().get(0)); } else if (expr.getArity() == 0) { - return String.format("(_ +zero %d %d)", expr.getType().getExponent(), - expr.getType().getSignificand()); + return String.format( + "(_ +zero %d %d)", + expr.getType().getExponent(), expr.getType().getSignificand()); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), - (acc, op) -> String.format("(fp.add %s %s %s)", - transformFpRoundingMode(expr.getRoundingMode()), acc, toTerm(op)), - (op1, op2) -> String.format("(fp.add %s %s %s)", - transformFpRoundingMode(expr.getRoundingMode()), op1, op2) - ); + (acc, op) -> + String.format( + "(fp.add %s %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), + acc, + toTerm(op)), + (op1, op2) -> + String.format( + "(fp.add %s %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), + op1, + op2)); } } protected String transformFpSub(final FpSubExpr expr) { - return String.format("(fp.sub %s %s %s)", transformFpRoundingMode(expr.getRoundingMode()), - toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); + return String.format( + "(fp.sub %s %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), + toTerm(expr.getLeftOp()), + toTerm(expr.getRightOp())); } protected String transformFpPos(final FpPosExpr expr) { @@ -1040,24 +955,36 @@ protected String transformFpMul(final FpMulExpr expr) { if (expr.getArity() == 1) { return toTerm(expr.getOps().get(0)); } else if (expr.getArity() == 0) { - return String.format("(fp #b0 #b0%s #b%s)", + return String.format( + "(fp #b0 #b0%s #b%s)", "1".repeat(expr.getType().getExponent() - 1), "0".repeat(expr.getType().getSignificand())); } else { - return expr.getOps().stream().skip(1) + return expr.getOps().stream() + .skip(1) .reduce( toTerm(expr.getOps().get(0)), - (acc, op) -> String.format("(fp.mul %s %s %s)", - transformFpRoundingMode(expr.getRoundingMode()), acc, toTerm(op)), - (op1, op2) -> String.format("(fp.mul %s %s %s)", - transformFpRoundingMode(expr.getRoundingMode()), op1, op2) - ); + (acc, op) -> + String.format( + "(fp.mul %s %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), + acc, + toTerm(op)), + (op1, op2) -> + String.format( + "(fp.mul %s %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), + op1, + op2)); } } protected String transformFpDiv(final FpDivExpr expr) { - return String.format("(fp.div %s %s %s)", transformFpRoundingMode(expr.getRoundingMode()), - toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); + return String.format( + "(fp.div %s %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), + toTerm(expr.getLeftOp()), + toTerm(expr.getRightOp())); } protected String transformFpEq(final FpEqExpr expr) { @@ -1069,8 +996,8 @@ protected String transformFpAssign(final FpAssignExpr expr) { } protected String transformFpNeq(final FpNeqExpr expr) { - return String.format("(not (fp.eq %s %s))", toTerm(expr.getLeftOp()), - toTerm(expr.getRightOp())); + return String.format( + "(not (fp.eq %s %s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } protected String transformFpGeq(final FpGeqExpr expr) { @@ -1094,7 +1021,8 @@ protected String transformFpAbs(final FpAbsExpr expr) { } protected String transformFpRoundToIntegral(final FpRoundToIntegralExpr expr) { - return String.format("(fp.roundToIntegral %s %s)", + return String.format( + "(fp.roundToIntegral %s %s)", transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); } @@ -1107,8 +1035,9 @@ protected String transformFpMax(final FpMaxExpr expr) { } protected String transformFpSqrt(final FpSqrtExpr expr) { - return String.format("(fp.sqrt %s %s)", transformFpRoundingMode(expr.getRoundingMode()), - toTerm(expr.getOp())); + return String.format( + "(fp.sqrt %s %s)", + transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); } protected String transformFpRem(final FpRemExpr expr) { @@ -1125,29 +1054,44 @@ protected String transformFpIsInfinite(final FpIsInfiniteExpr expr) { protected String transformFpFromBv(final FpFromBvExpr expr) { if (expr.isSigned()) { - return String.format("((_ to_fp %d %d) %s %s)", expr.getType().getExponent(), - expr.getType().getSignificand(), transformFpRoundingMode(expr.getRoundingMode()), + return String.format( + "((_ to_fp %d %d) %s %s)", + expr.getType().getExponent(), + expr.getType().getSignificand(), + transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); } else { - return String.format("((_ to_fp_unsigned %d %d) %s %s)", expr.getType().getExponent(), - expr.getType().getSignificand(), transformFpRoundingMode(expr.getRoundingMode()), + return String.format( + "((_ to_fp_unsigned %d %d) %s %s)", + expr.getType().getExponent(), + expr.getType().getSignificand(), + transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); } } protected String transformFpToBv(final FpToBvExpr expr) { if (expr.getSgn()) { - return String.format("((_ fp.to_sbv %d) %s %s) ", expr.getType().getSize(), - transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); + return String.format( + "((_ fp.to_sbv %d) %s %s) ", + expr.getType().getSize(), + transformFpRoundingMode(expr.getRoundingMode()), + toTerm(expr.getOp())); } else { - return String.format("((_ fp.to_ubv %d) %s %s) ", expr.getType().getSize(), - transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); + return String.format( + "((_ fp.to_ubv %d) %s %s) ", + expr.getType().getSize(), + transformFpRoundingMode(expr.getRoundingMode()), + toTerm(expr.getOp())); } } protected String transformFpToFp(final FpToFpExpr expr) { - return String.format("((_ to_fp %d %d) %s %s)", expr.getType().getExponent(), - expr.getType().getSignificand(), transformFpRoundingMode(expr.getRoundingMode()), + return String.format( + "((_ to_fp %d %d) %s %s)", + expr.getType().getExponent(), + expr.getType().getSignificand(), + transformFpRoundingMode(expr.getRoundingMode()), toTerm(expr.getOp())); } @@ -1180,9 +1124,7 @@ protected String transformFuncApp(final FuncAppExpr expr) { final RefExpr ref = (RefExpr) func; final Decl decl = ref.getDecl(); final String funcDecl = transformer.toSymbol(decl); - final String[] argTerms = args.stream() - .map(this::toTerm) - .toArray(String[]::new); + final String[] argTerms = args.stream().map(this::toTerm).toArray(String[]::new); return String.format("(%s %s)", funcDecl, String.join(" ", argTerms)); } else if (func instanceof FuncLitExpr) { @@ -1191,7 +1133,9 @@ protected String transformFuncApp(final FuncAppExpr expr) { while (replaced instanceof FuncLitExpr) { final ParamDecl param = ((FuncLitExpr) replaced).getParam(); final Expr funcExpr = ((FuncLitExpr) replaced).getResult(); - replaced = ExprUtils.changeDecls(funcExpr, Map.of(param, ((RefExpr) args.get(i++)).getDecl())); + replaced = + ExprUtils.changeDecls( + funcExpr, Map.of(param, ((RefExpr) args.get(i++)).getDecl())); } return toTerm(replaced); } else { @@ -1209,8 +1153,9 @@ protected String transformArrayRead(final ArrayReadExpr expr) { } protected String transformArrayWrite(final ArrayWriteExpr expr) { - return String.format("(store %s %s %s)", toTerm(expr.getArray()), toTerm(expr.getIndex()), - toTerm(expr.getElem())); + return String.format( + "(store %s %s %s)", + toTerm(expr.getArray()), toTerm(expr.getIndex()), toTerm(expr.getElem())); } protected String transformArrayEq(final ArrayEqExpr expr) { @@ -1218,32 +1163,44 @@ protected String transformArrayEq(final ArrayEqExpr expr) { } protected String transformArrayNeq(final ArrayNeqExpr expr) { - return String.format("(not (= %s %s))", toTerm(expr.getLeftOp()), - toTerm(expr.getRightOp())); + return String.format( + "(not (= %s %s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } protected String transformArrayLit(final ArrayLitExpr expr) { - String running = String.format("((as const %s) %s)", transformer.toSort(expr.getType()), - toTerm(expr.getElseElem())); + String running = + String.format( + "((as const %s) %s)", + transformer.toSort(expr.getType()), toTerm(expr.getElseElem())); for (Tuple2, ? extends Expr> elem : expr.getElements()) { - running = String.format("(store %s %s %s)", running, toTerm(elem.get1()), - toTerm(elem.get2())); + running = + String.format( + "(store %s %s %s)", running, toTerm(elem.get1()), toTerm(elem.get2())); } return running; } protected String transformArrayInit(final ArrayInitExpr expr) { - String running = String.format("((as const %s) %s)", transformer.toSort(expr.getType()), - toTerm(expr.getElseElem())); + String running = + String.format( + "((as const %s) %s)", + transformer.toSort(expr.getType()), toTerm(expr.getElseElem())); for (Tuple2, ? extends Expr> elem : expr.getElements()) { - running = String.format("(store %s %s %s)", running, toTerm(elem.get1()), - toTerm(elem.get2())); + running = + String.format( + "(store %s %s %s)", running, toTerm(elem.get1()), toTerm(elem.get2())); } return running; } private String transformDereference(final Dereference expr) { - checkState(expr.getUniquenessIdx().isPresent(), "Incomplete dereferences (missing uniquenessIdx) are not handled properly."); - return "(deref %s %s %s)".formatted(toTerm(expr.getArray()), toTerm(expr.getOffset()), toTerm(expr.getUniquenessIdx().get())); + checkState( + expr.getUniquenessIdx().isPresent(), + "Incomplete dereferences (missing uniquenessIdx) are not handled properly."); + return "(deref %s %s %s)" + .formatted( + toTerm(expr.getArray()), + toTerm(expr.getOffset()), + toTerm(expr.getUniquenessIdx().get())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibHornSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibHornSolver.java index 42650a4709..96a23ab363 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibHornSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibHornSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,16 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.Lists; import com.microsoft.z3.Z3Exception; import hu.bme.mit.theta.core.type.Expr; @@ -37,27 +47,27 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; - import java.util.*; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - /** * This class is a HornSolver that expects the proofs to be in the style of Z3 (using hyper-res * predicates) */ public class GenericSmtLibHornSolver extends SmtLibSolver implements HornSolver { - public GenericSmtLibHornSolver(SmtLibSymbolTable symbolTable, SmtLibTransformationManager transformationManager, SmtLibTermTransformer termTransformer, SmtLibSolverBinary solverBinary) { - super(symbolTable, transformationManager, termTransformer, solverBinary, false, SmtLibEnumStrategy.getDefaultStrategy(), "HORN"); + public GenericSmtLibHornSolver( + SmtLibSymbolTable symbolTable, + SmtLibTransformationManager transformationManager, + SmtLibTermTransformer termTransformer, + SmtLibSolverBinary solverBinary) { + super( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + false, + SmtLibEnumStrategy.getDefaultStrategy(), + "HORN"); } public static Type transformSort(final SortContext ctx) { @@ -87,14 +97,21 @@ public ProofNode getProof() { throw new SmtLibSolverException(res.getReason()); } else if (res.isSpecific()) { final GetProofResponse getModelResponse = res.asSpecific().asGetProofResponse(); - getModelResponse.getFunDeclarations().forEach((name, def) -> { - var type = transformSort(def.get2()); - for (SortContext s : Lists.reverse(def.get1())) { - type = FuncType.of(transformSort(s), type); - } - symbolTable.put(Const(name, type), name, def.get3()); - }); - final var proof = termTransformer.toExpr(getModelResponse.getProof(), Bool(), new SmtLibModel(Collections.emptyMap())); + getModelResponse + .getFunDeclarations() + .forEach( + (name, def) -> { + var type = transformSort(def.get2()); + for (SortContext s : Lists.reverse(def.get1())) { + type = FuncType.of(transformSort(s), type); + } + symbolTable.put(Const(name, type), name, def.get3()); + }); + final var proof = + termTransformer.toExpr( + getModelResponse.getProof(), + Bool(), + new SmtLibModel(Collections.emptyMap())); return proofFromExpr(proof); } else { throw new AssertionError(); @@ -127,7 +144,8 @@ private ProofNode proofFromExpr(Expr proof) { if (proofNodeExpr instanceof FuncAppExpr funcAppExpr) { final var nameAndArgs = extractFuncAndArgs(funcAppExpr); - if (nameAndArgs.get1() instanceof RefExpr refName && refName.getDecl().getName().startsWith("hyper-res")) { + if (nameAndArgs.get1() instanceof RefExpr refName + && refName.getDecl().getName().startsWith("hyper-res")) { if (!nameAndArgs.get2().isEmpty()) { for (int i = 1; i < nameAndArgs.get2().size() - 1; ++i) { final var child = nameAndArgs.get2().get(i); @@ -135,7 +153,8 @@ private ProofNode proofFromExpr(Expr proof) { if (!lookup.containsKey(child)) { lookup.put(child, id++); } - visited.put(lookup.get(child), new Builder(extractProofExpr(child))); + visited.put( + lookup.get(child), new Builder(extractProofExpr(child))); proofStack.push(child); } proofNode.addChild(visited.get(lookup.get(child))); @@ -155,6 +174,4 @@ private Expr extractProofExpr(Expr expr) { checkState(lastArg instanceof FuncAppExpr, "Proof should be function application."); return (Expr) lastArg; } - - } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibOneshotSolverBinary.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibOneshotSolverBinary.java index 808d5b309b..b953b7c343 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibOneshotSolverBinary.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibOneshotSolverBinary.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.generic; import com.zaxxer.nuprocess.NuAbstractProcessHandler; import com.zaxxer.nuprocess.NuProcessBuilder; import hu.bme.mit.theta.solver.smtlib.solver.binary.SmtLibSolverBinary; - import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -32,8 +30,8 @@ import java.util.concurrent.TimeUnit; /** - * Instead of an interactive solver, these binaries can only work with an input file. - * Therefore, we keep track of commands, and only execute them when readResponse() is called. + * Instead of an interactive solver, these binaries can only work with an input file. Therefore, we + * keep track of commands, and only execute them when readResponse() is called. */ public class GenericSmtLibOneshotSolverBinary implements SmtLibSolverBinary { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverBinary.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverBinary.java index 3acef6cb5e..cc0d41608e 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverBinary.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverBinary.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,23 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkState; +import static java.lang.Math.min; + import com.zaxxer.nuprocess.NuAbstractProcessHandler; import com.zaxxer.nuprocess.NuProcess; import com.zaxxer.nuprocess.NuProcessBuilder; import hu.bme.mit.theta.solver.smtlib.solver.binary.SmtLibSolverBinary; import hu.bme.mit.theta.solver.smtlib.solver.binary.SmtLibSolverBinaryException; - import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.*; -import static com.google.common.base.Preconditions.checkState; -import static java.lang.Math.min; - public final class GenericSmtLibSolverBinary implements SmtLibSolverBinary { private final NuProcess solverProcess; @@ -40,8 +38,8 @@ public GenericSmtLibSolverBinary(final Path solverPath, final String[] args) { this(solverPath, args, EnumSet.noneOf(Solver.class)); } - public GenericSmtLibSolverBinary(final Path solverPath, final String[] args, - final EnumSet solverOverride) { + public GenericSmtLibSolverBinary( + final Path solverPath, final String[] args, final EnumSet solverOverride) { final var processCmd = new ArrayList(); processCmd.add(solverPath.toAbsolutePath().toString()); processCmd.addAll(Arrays.asList(args)); @@ -84,7 +82,8 @@ public void close() { } public enum Solver { - CVC4, PRINCESS + CVC4, + PRINCESS } private static final class ProcessHandler extends NuAbstractProcessHandler { @@ -119,10 +118,11 @@ public synchronized boolean onStdinReady(final ByteBuffer buffer) { if (!inputQueue.isEmpty()) { final var output = inputQueue.peek(); final var eol = "\n".getBytes(StandardCharsets.US_ASCII); - final var cutoff = min(buffer.remaining() - eol.length, - output.length() - headDoneIndex); - buffer.put(output.substring(headDoneIndex, headDoneIndex + cutoff) - .getBytes(StandardCharsets.US_ASCII)); + final var cutoff = + min(buffer.remaining() - eol.length, output.length() - headDoneIndex); + buffer.put( + output.substring(headDoneIndex, headDoneIndex + cutoff) + .getBytes(StandardCharsets.US_ASCII)); if (headDoneIndex + cutoff < output.length()) { headDoneIndex = headDoneIndex + cutoff; } else { @@ -153,7 +153,7 @@ private synchronized void onInput(final ByteBuffer buffer) { final var buf = new byte[buffer.remaining()]; buffer.get(buf); final var input = new String(buf, StandardCharsets.US_ASCII); - //System.out.println(input); + // System.out.println(input); for (var c : input.toCharArray()) { if (readProcessor == null) { @@ -189,7 +189,12 @@ private synchronized void onInput(final ByteBuffer buffer) { private static final class ReadProcessor { private enum ReadStatus { - INIT, LINE, PARENTHESES, STRING, COMMENT, READY + INIT, + LINE, + PARENTHESES, + STRING, + COMMENT, + READY } private ReadProcessor.ReadStatus status = ReadProcessor.ReadStatus.INIT; diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverFactory.java index f307e7c356..bec10ed650 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.smtlib.impl.generic; import hu.bme.mit.theta.solver.HornSolver; @@ -23,7 +22,6 @@ import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibEnumStrategy; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolver; - import java.nio.file.Path; import java.util.EnumSet; @@ -39,19 +37,27 @@ protected GenericSmtLibSolverFactory(Path solverPath, String[] args) { this(solverPath, args, EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class)); } - protected GenericSmtLibSolverFactory(Path solverPath, String[] args, - EnumSet solverOverride) { + protected GenericSmtLibSolverFactory( + Path solverPath, + String[] args, + EnumSet solverOverride) { this(solverPath, args, solverOverride, SmtLibEnumStrategy.SORTS); } - protected GenericSmtLibSolverFactory(Path solverPath, String[] args, - SmtLibEnumStrategy enumStrategy) { - this(solverPath, args, EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class), enumStrategy); + protected GenericSmtLibSolverFactory( + Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { + this( + solverPath, + args, + EnumSet.noneOf(GenericSmtLibSolverBinary.Solver.class), + enumStrategy); } - protected GenericSmtLibSolverFactory(Path solverPath, String[] args, - EnumSet solverOverride, - SmtLibEnumStrategy enumStrategy) { + protected GenericSmtLibSolverFactory( + Path solverPath, + String[] args, + EnumSet solverOverride, + SmtLibEnumStrategy enumStrategy) { this.solverPath = solverPath; this.args = args; this.solverOverride = solverOverride; @@ -62,7 +68,8 @@ public static GenericSmtLibSolverFactory create(Path solverPath, String[] args) return new GenericSmtLibSolverFactory(solverPath, args); } - public static GenericSmtLibSolverFactory create(Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { + public static GenericSmtLibSolverFactory create( + Path solverPath, String[] args, SmtLibEnumStrategy enumStrategy) { return new GenericSmtLibSolverFactory(solverPath, args, enumStrategy); } @@ -73,8 +80,13 @@ public Solver createSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args, solverOverride); - return new SmtLibSolver(symbolTable, transformationManager, termTransformer, solverBinary, - false, enumStrategy); + return new SmtLibSolver( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + false, + enumStrategy); } @Override @@ -84,8 +96,8 @@ public UCSolver createUCSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args, solverOverride); - return new SmtLibSolver(symbolTable, transformationManager, termTransformer, solverBinary, - true); + return new SmtLibSolver( + symbolTable, transformationManager, termTransformer, solverBinary, true); } @Override @@ -101,6 +113,7 @@ public HornSolver createHornSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable); final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args, solverOverride); - return new GenericSmtLibHornSolver(symbolTable, transformationManager, termTransformer, solverBinary); + return new GenericSmtLibHornSolver( + symbolTable, transformationManager, termTransformer, solverBinary); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverInstaller.java index 07203bc81d..93ea676029 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,12 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; - import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -27,8 +28,6 @@ import java.util.Collections; import java.util.List; -import static com.google.common.base.Preconditions.checkState; - public final class GenericSmtLibSolverInstaller extends SmtLibSolverInstaller.Default { private Path solverPath; @@ -43,8 +42,9 @@ protected String getSolverName() { return "generic"; } - public void install(final Path home, final String version, final Path solverPath, - final String[] solverArgs) throws SmtLibSolverInstallerException { + public void install( + final Path home, final String version, final Path solverPath, final String[] solverArgs) + throws SmtLibSolverInstallerException { this.solverPath = solverPath; this.solverArgs = solverArgs; super.install(home, version, version, solverPath); @@ -56,16 +56,15 @@ protected void installSolver(Path installDir, String version) checkState(solverPath != null); try { final var solverFilePath = solverFile(installDir); - Files.writeString(solverFilePath, solverPath.toAbsolutePath().toString(), - StandardCharsets.UTF_8); + Files.writeString( + solverFilePath, solverPath.toAbsolutePath().toString(), StandardCharsets.UTF_8); final var solverInfoPath = infoFile(installDir); final var info = Files.readString(solverInfoPath, StandardCharsets.UTF_8); Files.writeString( solverInfoPath, info + String.format("binary=%s\n", solverPath.toAbsolutePath().toString()), - StandardCharsets.UTF_8 - ); + StandardCharsets.UTF_8); solverPath = null; } catch (IOException e) { @@ -85,8 +84,11 @@ protected void uninstallSolver(Path installDir, String version) } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) { + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) { return GenericSmtLibSolverFactory.create(solverPath, solverArgs); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSymbolTable.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSymbolTable.java index d4a9665ef9..5ade04de55 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSymbolTable.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibSymbolTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.enumtype.EnumLitExpr; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; - import java.util.HashMap; import java.util.Map; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - public class GenericSmtLibSymbolTable implements SmtLibSymbolTable { private static final String problematicCharactersRegex = "[:#]"; @@ -60,8 +59,11 @@ public boolean definesConst(final ConstDecl constDecl) { @Override public boolean definesSymbol(final String symbol) { - return constToSymbol.inverse().containsKey( - symbol.replaceAll(problematicCharactersRegex, problematicCharactersReplacement)); + return constToSymbol + .inverse() + .containsKey( + symbol.replaceAll( + problematicCharactersRegex, problematicCharactersReplacement)); } @Override @@ -98,10 +100,13 @@ public void put(final ConstDecl constDecl, final String symbol, final String checkNotNull(symbol); checkNotNull(declaration); checkState(!constToSymbol.containsKey(constDecl), "Constant not found."); - constToSymbol.put(constDecl, + constToSymbol.put( + constDecl, symbol.replaceAll(problematicCharactersRegex, problematicCharactersReplacement)); - constToDeclaration.put(constDecl, - declaration.replaceAll(problematicCharactersRegex, problematicCharactersReplacement)); + constToDeclaration.put( + constDecl, + declaration.replaceAll( + problematicCharactersRegex, problematicCharactersReplacement)); } @Override diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTermTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTermTransformer.java index 22402fba62..c500700589 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTermTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTermTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,37 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.generic; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.UnsafeApp; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.BinaryContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.DecimalContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Exists_termContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Forall_termContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Generic_termContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.HexadecimalContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.IdentifierContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.IndexContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Let_termContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.NumeralContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Qual_identifierContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.SortContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Spec_constantContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.SymbolContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.TermContext; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import hu.bme.mit.theta.common.QuadFunction; @@ -116,9 +147,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.parser.ThrowExceptionErrorListener; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; - import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; @@ -132,37 +160,8 @@ import java.util.function.Supplier; import java.util.function.UnaryOperator; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.UnsafeApp; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.core.utils.TypeUtils.castBv; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.BinaryContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.DecimalContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Exists_termContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Forall_termContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Generic_termContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.HexadecimalContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.IdentifierContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.IndexContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Let_termContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.NumeralContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Qual_identifierContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.SortContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Spec_constantContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.SymbolContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.TermContext; -import static java.util.stream.Collectors.toList; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; public class GenericSmtLibTermTransformer implements SmtLibTermTransformer { @@ -174,101 +173,107 @@ public GenericSmtLibTermTransformer(final SmtLibSymbolTable symbolTable) { this(symbolTable, SmtLibEnumStrategy.getDefaultStrategy()); } - public GenericSmtLibTermTransformer(final SmtLibSymbolTable symbolTable, final SmtLibEnumStrategy enumStrategy) { + public GenericSmtLibTermTransformer( + final SmtLibSymbolTable symbolTable, final SmtLibEnumStrategy enumStrategy) { this.symbolTable = symbolTable; this.enumStrategy = enumStrategy; - this.funAppTransformer = new HashMap<>() {{ - // Generic - put("ite", exprIteOperator()); - - // Abstract - put("=", exprRelationalOperator(EqExpr::create2)); - put("<=", exprRelationalOperator(LeqExpr::create2)); - put("<", exprRelationalOperator(LtExpr::create2)); - put(">=", exprRelationalOperator(GeqExpr::create2)); - put(">", exprRelationalOperator(GtExpr::create2)); - put("+", exprMultiaryOperator(AddExpr::create2)); - put("-", exprMinusOperator()); - put("*", exprMultiaryOperator(MulExpr::create2)); - put("div", exprBinaryOperator(IntDivExpr::create)); - put("/", exprBinaryOperator(RatDivExpr::create)); - put("mod", exprBinaryOperator(ModExpr::create2)); - put("rem", exprBinaryOperator(RemExpr::create2)); - - // Booleal - put("not", exprUnaryOperator(NotExpr::create)); - put("or", exprMultiaryOperator(OrExpr::create)); - put("and", exprMultiaryOperator(AndExpr::create)); - put("xor", exprBinaryOperator(XorExpr::create)); - put("iff", exprBinaryOperator(IffExpr::create)); - put("=>", exprBinaryOperator(ImplyExpr::create)); - - // Integer - put("to_real", exprUnaryOperator(IntToRatExpr::create)); - - // Rational - put("to_int", exprUnaryOperator(RatToIntExpr::create)); - - // Bitvector - put("concat", exprMultiaryOperator(BvConcatExpr::create)); - put("extract", exprBvExtractOperator()); - put("zero_extend", exprBvExtendOperator(BvZExtExpr::create)); - put("sign_extend", exprBvExtendOperator(BvSExtExpr::create)); - put("bvadd", exprMultiaryOperator(BvAddExpr::create)); - put("bvsub", exprBinaryOperator(BvSubExpr::create)); - put("bvneg", exprUnaryOperator(BvNegExpr::create)); - put("bvmul", exprMultiaryOperator(BvAddExpr::create)); - put("bvudiv", exprBinaryOperator(BvUDivExpr::create)); - put("bvsdiv", exprBinaryOperator(BvSDivExpr::create)); - put("bvsmod", exprBinaryOperator(BvSModExpr::create)); - put("bvsrem", exprBinaryOperator(BvURemExpr::create)); - put("bvurem", exprBinaryOperator(BvSRemExpr::create)); - put("bvand", exprMultiaryOperator(BvAndExpr::create)); - put("bvor", exprMultiaryOperator(BvOrExpr::create)); - put("bvxor", exprMultiaryOperator(BvXorExpr::create)); - put("bvnot", exprUnaryOperator(BvNotExpr::create)); - put("bvshl", exprBinaryOperator(BvShiftLeftExpr::create)); - put("bvashr", exprBinaryOperator(BvArithShiftRightExpr::create)); - put("bvlshr", exprBinaryOperator(BvLogicShiftRightExpr::create)); - put("bvult", exprBinaryOperator(BvULtExpr::create)); - put("bvslt", exprBinaryOperator(BvSLtExpr::create)); - put("bvule", exprBinaryOperator(BvULeqExpr::create)); - put("bvsle", exprBinaryOperator(BvSLeqExpr::create)); - put("bvugt", exprBinaryOperator(BvUGtExpr::create)); - put("bvsgt", exprBinaryOperator(BvSGtExpr::create)); - put("bvuge", exprBinaryOperator(BvUGeqExpr::create)); - put("bvsge", exprBinaryOperator(BvSGeqExpr::create)); - - // Floating point - - put("fp", exprFpLit()); - put("fp.add", exprFpMultiaryOperator(FpAddExpr::create)); - put("fp.sub", exprFpBinaryOperator(FpSubExpr::create)); - put("fp.neg", exprUnaryOperator(FpNegExpr::create)); - put("fp.mul", exprFpMultiaryOperator(FpMulExpr::create)); - put("fp.div", exprFpBinaryOperator(FpDivExpr::create)); - put("fp.eq", exprBinaryOperator(FpEqExpr::create)); - put("fp.geq", exprBinaryOperator(FpGeqExpr::create)); - put("fp.gt", exprBinaryOperator(FpGtExpr::create)); - put("fp.leq", exprBinaryOperator(FpLeqExpr::create)); - put("fp.lt", exprBinaryOperator(FpLtExpr::create)); - put("fp.abs", exprUnaryOperator(FpAbsExpr::create)); - put("fp.roundToIntegral", exprFpUnaryOperator(FpRoundToIntegralExpr::create)); - put("fp.min", exprBinaryOperator(FpMinExpr::create)); - put("fp.max", exprBinaryOperator(FpMaxExpr::create)); - put("fp.sqrt", exprFpUnaryOperator(FpSqrtExpr::create)); - put("fp.rem", exprBinaryOperator(FpRemExpr::create)); - put("fp.isNaN", exprUnaryOperator(FpIsNanExpr::create)); - - // Array - put("select", exprArrayReadOperator()); - put("store", exprArrayWriteOperator()); - - // Proof - put("hyper-res", expectedFunc("hyper-res")); - put("asserted", expectedFunc("asserted")); - put("mp", expectedFunc("mp")); - }}; + this.funAppTransformer = + new HashMap<>() { + { + // Generic + put("ite", exprIteOperator()); + + // Abstract + put("=", exprRelationalOperator(EqExpr::create2)); + put("<=", exprRelationalOperator(LeqExpr::create2)); + put("<", exprRelationalOperator(LtExpr::create2)); + put(">=", exprRelationalOperator(GeqExpr::create2)); + put(">", exprRelationalOperator(GtExpr::create2)); + put("+", exprMultiaryOperator(AddExpr::create2)); + put("-", exprMinusOperator()); + put("*", exprMultiaryOperator(MulExpr::create2)); + put("div", exprBinaryOperator(IntDivExpr::create)); + put("/", exprBinaryOperator(RatDivExpr::create)); + put("mod", exprBinaryOperator(ModExpr::create2)); + put("rem", exprBinaryOperator(RemExpr::create2)); + + // Booleal + put("not", exprUnaryOperator(NotExpr::create)); + put("or", exprMultiaryOperator(OrExpr::create)); + put("and", exprMultiaryOperator(AndExpr::create)); + put("xor", exprBinaryOperator(XorExpr::create)); + put("iff", exprBinaryOperator(IffExpr::create)); + put("=>", exprBinaryOperator(ImplyExpr::create)); + + // Integer + put("to_real", exprUnaryOperator(IntToRatExpr::create)); + + // Rational + put("to_int", exprUnaryOperator(RatToIntExpr::create)); + + // Bitvector + put("concat", exprMultiaryOperator(BvConcatExpr::create)); + put("extract", exprBvExtractOperator()); + put("zero_extend", exprBvExtendOperator(BvZExtExpr::create)); + put("sign_extend", exprBvExtendOperator(BvSExtExpr::create)); + put("bvadd", exprMultiaryOperator(BvAddExpr::create)); + put("bvsub", exprBinaryOperator(BvSubExpr::create)); + put("bvneg", exprUnaryOperator(BvNegExpr::create)); + put("bvmul", exprMultiaryOperator(BvAddExpr::create)); + put("bvudiv", exprBinaryOperator(BvUDivExpr::create)); + put("bvsdiv", exprBinaryOperator(BvSDivExpr::create)); + put("bvsmod", exprBinaryOperator(BvSModExpr::create)); + put("bvsrem", exprBinaryOperator(BvURemExpr::create)); + put("bvurem", exprBinaryOperator(BvSRemExpr::create)); + put("bvand", exprMultiaryOperator(BvAndExpr::create)); + put("bvor", exprMultiaryOperator(BvOrExpr::create)); + put("bvxor", exprMultiaryOperator(BvXorExpr::create)); + put("bvnot", exprUnaryOperator(BvNotExpr::create)); + put("bvshl", exprBinaryOperator(BvShiftLeftExpr::create)); + put("bvashr", exprBinaryOperator(BvArithShiftRightExpr::create)); + put("bvlshr", exprBinaryOperator(BvLogicShiftRightExpr::create)); + put("bvult", exprBinaryOperator(BvULtExpr::create)); + put("bvslt", exprBinaryOperator(BvSLtExpr::create)); + put("bvule", exprBinaryOperator(BvULeqExpr::create)); + put("bvsle", exprBinaryOperator(BvSLeqExpr::create)); + put("bvugt", exprBinaryOperator(BvUGtExpr::create)); + put("bvsgt", exprBinaryOperator(BvSGtExpr::create)); + put("bvuge", exprBinaryOperator(BvUGeqExpr::create)); + put("bvsge", exprBinaryOperator(BvSGeqExpr::create)); + + // Floating point + + put("fp", exprFpLit()); + put("fp.add", exprFpMultiaryOperator(FpAddExpr::create)); + put("fp.sub", exprFpBinaryOperator(FpSubExpr::create)); + put("fp.neg", exprUnaryOperator(FpNegExpr::create)); + put("fp.mul", exprFpMultiaryOperator(FpMulExpr::create)); + put("fp.div", exprFpBinaryOperator(FpDivExpr::create)); + put("fp.eq", exprBinaryOperator(FpEqExpr::create)); + put("fp.geq", exprBinaryOperator(FpGeqExpr::create)); + put("fp.gt", exprBinaryOperator(FpGtExpr::create)); + put("fp.leq", exprBinaryOperator(FpLeqExpr::create)); + put("fp.lt", exprBinaryOperator(FpLtExpr::create)); + put("fp.abs", exprUnaryOperator(FpAbsExpr::create)); + put( + "fp.roundToIntegral", + exprFpUnaryOperator(FpRoundToIntegralExpr::create)); + put("fp.min", exprBinaryOperator(FpMinExpr::create)); + put("fp.max", exprBinaryOperator(FpMaxExpr::create)); + put("fp.sqrt", exprFpUnaryOperator(FpSqrtExpr::create)); + put("fp.rem", exprBinaryOperator(FpRemExpr::create)); + put("fp.isNaN", exprUnaryOperator(FpIsNanExpr::create)); + + // Array + put("select", exprArrayReadOperator()); + put("store", exprArrayWriteOperator()); + + // Proof + put("hyper-res", expectedFunc("hyper-res")); + put("asserted", expectedFunc("asserted")); + put("mp", expectedFunc("mp")); + } + }; } /* Public interface */ @@ -298,8 +303,8 @@ private Expr toFuncLitExpr(final String funcLitImpl, final SmtLibModel model) } @Override - public Expr toExpr(final String term, final T type, - final SmtLibModel model) { + public Expr toExpr( + final String term, final T type, final SmtLibModel model) { final var expr = toExpr(term, model); return cast(expr, type); } @@ -316,8 +321,8 @@ private Expr toExpr(final String term, final SmtLibModel model) { } @Override - public LitExpr toLitExpr(final String litImpl, final T type, - final SmtLibModel model) { + public LitExpr toLitExpr( + final String litImpl, final T type, final SmtLibModel model) { if (type instanceof EnumType enumType) return (LitExpr) cast(toEnumLitExpr(litImpl, enumType, model), type); final var litExpr = toLitExpr(litImpl, model); @@ -340,9 +345,10 @@ private Expr toLitExpr(final String litImpl, final SmtLibModel model) { parser.addErrorListener(new ThrowExceptionErrorListener()); final var funcDef = parser.function_def(); - final List> paramDecls = funcDef.sorted_var().stream() - .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) - .collect(toList()); + final List> paramDecls = + funcDef.sorted_var().stream() + .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) + .collect(toList()); final var vars = new StackImpl>(); pushParams(paramDecls, vars); @@ -352,7 +358,8 @@ private Expr toLitExpr(final String litImpl, final SmtLibModel model) { return expr; } - private LitExpr toEnumLitExpr(final String litImpl, final EnumType type, final SmtLibModel model) { + private LitExpr toEnumLitExpr( + final String litImpl, final EnumType type, final SmtLibModel model) { final var lexer = new SMTLIBv2Lexer(CharStreams.fromString(litImpl)); final var parser = new SMTLIBv2Parser(new CommonTokenStream(lexer)); lexer.removeErrorListeners(); @@ -373,7 +380,8 @@ public LitExpr> toArrayLitExpr( if (arrayLitExpr == null) { return null; } else if (arrayLitExpr instanceof IteExpr) { - final var entryExprsBuilder = new ImmutableList.Builder, ? extends Expr>>(); + final var entryExprsBuilder = + new ImmutableList.Builder, ? extends Expr>>(); var iteExpr = (IteExpr) arrayLitExpr; while (true) { entryExprsBuilder.add( @@ -390,8 +398,8 @@ public LitExpr> toArrayLitExpr( } @Override - public LitExpr toBvLitExpr(final String bvLitImpl, final BvType type, - final SmtLibModel model) { + public LitExpr toBvLitExpr( + final String bvLitImpl, final BvType type, final SmtLibModel model) { final var bvLitExpr = toLitExpr(bvLitImpl, model); if (bvLitExpr == null) { @@ -407,14 +415,17 @@ public LitExpr toBvLitExpr(final String bvLitImpl, final BvType type, /* Visitor implementation */ - protected Expr transformFuncDef(final SMTLIBv2Parser.Function_defContext ctx, - final SmtLibModel model, final Stack> vars) { + protected Expr transformFuncDef( + final SMTLIBv2Parser.Function_defContext ctx, + final SmtLibModel model, + final Stack> vars) { assert model != null; assert vars != null; - final List> paramDecls = ctx.sorted_var().stream() - .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) - .collect(toList()); + final List> paramDecls = + ctx.sorted_var().stream() + .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) + .collect(toList()); pushParams(paramDecls, vars); var op = transformTerm(ctx.term(), model, vars); @@ -425,8 +436,8 @@ protected Expr transformFuncDef(final SMTLIBv2Parser.Function_defContext ctx, return op; } - protected Expr transformTerm(final TermContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformTerm( + final TermContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -451,8 +462,10 @@ protected Expr transformTerm(final TermContext ctx, final SmtLibModel model, } } - protected Expr transformSpecConstant(final Spec_constantContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformSpecConstant( + final Spec_constantContext ctx, + final SmtLibModel model, + final Stack> vars) { assert model != null; assert vars != null; @@ -471,16 +484,20 @@ protected Expr transformSpecConstant(final Spec_constantContext ctx, final Sm } } - protected Expr transformQualIdentifier(final Qual_identifierContext ctx, - final SmtLibModel model, final Stack> vars) { + protected Expr transformQualIdentifier( + final Qual_identifierContext ctx, + final SmtLibModel model, + final Stack> vars) { assert model != null; assert vars != null; return transformIdentifier(ctx.identifier(), model, vars); } - protected Expr transformGenericTerm(final Generic_termContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformGenericTerm( + final Generic_termContext ctx, + final SmtLibModel model, + final Stack> vars) { assert model != null; assert vars != null; @@ -503,40 +520,47 @@ protected Expr transformGenericTerm(final Generic_termContext ctx, final SmtL } else if (funAppTransformer.containsKey(funName)) { // known function application return funAppTransformer.get(funName).apply(funParams, funAppParams, model, vars); } else { // custom function application -// checkArgument(funParams.size() == 0, -// "Custom unary function application cannot have parameter"); -// checkArgument(funAppParams.size() == 1, "Only unary functions are supported"); + // checkArgument(funParams.size() == 0, + // "Custom unary function application cannot have parameter"); + // checkArgument(funAppParams.size() == 1, "Only unary functions are + // supported"); return createFuncAppExpr(funName, funAppParams, model, vars); } } @SuppressWarnings("unchecked") - private Expr createArrayLitExpr(final Expr elze, - final ArrayType type) { + private Expr createArrayLitExpr( + final Expr elze, final ArrayType type) { return Array(Collections.emptyList(), (Expr) elze, type); } - private

Expr createFuncAppExpr(final String funName, - final List funAppParams, final SmtLibModel model, - final Stack> vars) { + private

Expr createFuncAppExpr( + final String funName, + final List funAppParams, + final SmtLibModel model, + final Stack> vars) { final Expr funcExpr; if (symbolTable.definesSymbol(funName)) { funcExpr = checkNotNull(symbolTable.getConst(funName).getRef()); } else { final var funDefImpl = model.getTerm(funName); if (funDefImpl == null) { - throw new SmtLibSolverException("Model (%s) does not have function \"%s\".".formatted(model, funName)); + throw new SmtLibSolverException( + "Model (%s) does not have function \"%s\".".formatted(model, funName)); } funcExpr = toFuncLitExpr(funDefImpl, model); } - final List> params = funAppParams.stream().map(it -> (Expr) transformTerm(it, model, vars)).collect(Collectors.toUnmodifiableList()); + final List> params = + funAppParams.stream() + .map(it -> (Expr) transformTerm(it, model, vars)) + .collect(Collectors.toUnmodifiableList()); return UnsafeApp(funcExpr, params); } - protected Expr transformLetTerm(final Let_termContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformLetTerm( + final Let_termContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -562,14 +586,15 @@ protected Expr transformLetTerm(final Let_termContext ctx, final SmtLibModel return substitutionBuilder.build().apply(term); } - protected Expr transformForallTerm(final Forall_termContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformForallTerm( + final Forall_termContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; - final List> paramDecls = ctx.sorted_var().stream() - .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) - .collect(toList()); + final List> paramDecls = + ctx.sorted_var().stream() + .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) + .collect(toList()); pushParams(paramDecls, vars); final var op = transformTerm(ctx.term(), model, vars); @@ -579,14 +604,15 @@ protected Expr transformForallTerm(final Forall_termContext ctx, final SmtLib return Forall(paramDecls, cast(op, Bool())); } - protected Expr transformExistsTerm(final Exists_termContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformExistsTerm( + final Exists_termContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; - final List> paramDecls = ctx.sorted_var().stream() - .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) - .collect(toList()); + final List> paramDecls = + ctx.sorted_var().stream() + .map(sv -> Param(sv.symbol().getText(), transformSort(sv.sort()))) + .collect(toList()); pushParams(paramDecls, vars); final var op = transformTerm(ctx.term(), model, vars); @@ -596,8 +622,8 @@ protected Expr transformExistsTerm(final Exists_termContext ctx, final SmtLib return Exists(paramDecls, cast(op, Bool())); } - protected Expr transformIdentifier(final IdentifierContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformIdentifier( + final IdentifierContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -630,8 +656,8 @@ protected Expr transformIdentifier(final IdentifierContext ctx, final SmtLibM } } - protected Expr transformSymbol(final SymbolContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformSymbol( + final SymbolContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -642,7 +668,10 @@ protected Expr transformSymbol(final SymbolContext ctx, final SmtLibModel mod case "false": return BoolExprs.False(); default: - final var filter = vars.toCollection().stream().filter(it -> it.getName().equals(value)).toList(); + final var filter = + vars.toCollection().stream() + .filter(it -> it.getName().equals(value)) + .toList(); if (!filter.isEmpty()) { final var decl = filter.get(filter.size() - 1); return decl.getRef(); @@ -651,21 +680,22 @@ protected Expr transformSymbol(final SymbolContext ctx, final SmtLibModel mod } else if (symbolTable.definesEnumLiteral(value)) { return symbolTable.getEnumLiteral(value); } else { - throw new SmtLibSolverException("Transformation of symbol not supported: " + value); + throw new SmtLibSolverException( + "Transformation of symbol not supported: " + value); } } } - protected Expr transformNumeral(final NumeralContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformNumeral( + final NumeralContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; return Int(ctx.getText()); } - protected Expr transformDecimal(final DecimalContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformDecimal( + final DecimalContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -677,8 +707,8 @@ protected Expr transformDecimal(final DecimalContext ctx, final SmtLibModel m } } - protected Expr transformHexadecimal(final HexadecimalContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformHexadecimal( + final HexadecimalContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -687,8 +717,8 @@ protected Expr transformHexadecimal(final HexadecimalContext ctx, final SmtLi return BvUtils.bigIntegerToNeutralBvLitExpr(num, numStr.length() * 4); } - protected Expr transformBinary(final BinaryContext ctx, final SmtLibModel model, - final Stack> vars) { + protected Expr transformBinary( + final BinaryContext ctx, final SmtLibModel model, final Stack> vars) { assert model != null; assert vars != null; @@ -721,14 +751,14 @@ protected Type transformSort(final SortContext ctx) { /* Variable scope handling */ - protected void pushParams(final List> paramDecls, - Stack> vars) { + protected void pushParams( + final List> paramDecls, Stack> vars) { vars.push(); vars.add(paramDecls); } - protected void popParams(final List> paramDecls, - Stack> vars) { + protected void popParams( + final List> paramDecls, Stack> vars) { vars.pop(); } @@ -890,8 +920,10 @@ private OperatorCreatorFunction exprMultiaryOperator( return (params, ops, model, vars) -> { checkArgument(params.size() == 0, "No parameters expected"); - return function.apply(ops.stream().map(op -> transformTerm(op, model, vars)) - .collect(Collectors.toUnmodifiableList())); + return function.apply( + ops.stream() + .map(op -> transformTerm(op, model, vars)) + .collect(Collectors.toUnmodifiableList())); }; } @@ -941,9 +973,10 @@ private OperatorCreatorFunction exprFpMultiaryOperator( return function.apply( fpOperatorRoundingMode(ops.get(0)), - ops.stream().skip(1).map(op -> transformTerm(op, model, vars)) - .collect(Collectors.toUnmodifiableList()) - ); + ops.stream() + .skip(1) + .map(op -> transformTerm(op, model, vars)) + .collect(Collectors.toUnmodifiableList())); }; } @@ -964,13 +997,12 @@ private FpRoundingMode fpOperatorRoundingMode(final TermContext term) { } } - private interface OperatorCreatorFunction extends QuadFunction< - List, // Parameters - List, // Operands - SmtLibModel, // The model - Stack>, // The variable (param) store - Expr // Return type - > { - - } + private interface OperatorCreatorFunction + extends QuadFunction< + List, // Parameters + List, // Operands + SmtLibModel, // The model + Stack>, // The variable (param) store + Expr // Return type + > {} } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTransformationManager.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTransformationManager.java index 24fefdfcae..603ab73817 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTransformationManager.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTransformationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -57,14 +57,12 @@ protected SmtLibTypeTransformer instantiateTypeTransformer( } protected SmtLibDeclTransformer instantiateDeclTransformer( - final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable - ) { + final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { return new GenericSmtLibDeclTransformer(transformer, symbolTable); } protected SmtLibExprTransformer instantiateExprTransformer( - final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable - ) { + final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { return new GenericSmtLibExprTransformer(transformer, symbolTable); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTypeTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTypeTransformer.java index c0442f7ab7..e6f29aa0aa 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTypeTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/generic/GenericSmtLibTypeTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,7 +28,6 @@ import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTypeTransformer; - import java.util.concurrent.ExecutionException; public class GenericSmtLibTypeTransformer implements SmtLibTypeTransformer { @@ -49,9 +48,9 @@ public GenericSmtLibTypeTransformer(final SmtLibTransformationManager transforme table = buildDispatchTable(DispatchTable.builder()).build(); } - protected DispatchTable.Builder buildDispatchTable(DispatchTable.Builder builder) { - builder - .addCase(BoolType.class, this::boolType) + protected DispatchTable.Builder buildDispatchTable( + DispatchTable.Builder builder) { + builder.addCase(BoolType.class, this::boolType) .addCase(IntType.class, this::intType) .addCase(RatType.class, this::ratType) .addCase(BvType.class, this::bvType) @@ -91,8 +90,8 @@ protected String fpType(final FpType type) { } protected String arrayType(final ArrayType type) { - return String.format("(Array %s %s)", toSort(type.getIndexType()), - toSort(type.getElemType())); + return String.format( + "(Array %s %s)", toSort(type.getIndexType()), toSort(type.getElemType())); } protected String enumType(final EnumType type) { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverFactory.java index 6abdd24d4a..1999135faa 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,7 +25,6 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTransformationManager; - import java.nio.file.Path; public class GolemSmtLibSolverFactory extends GenericSmtLibSolverFactory { @@ -55,7 +54,8 @@ public HornSolver createHornSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable); final var solverBinary = new GenericSmtLibOneshotSolverBinary(solverPath, args); - return new GenericHornSolver(symbolTable, transformationManager, termTransformer, solverBinary); + return new GenericHornSolver( + symbolTable, transformationManager, termTransformer, solverBinary); } @Override diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverInstaller.java index 028cecf44a..0cbfa5446c 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/golem/GolemSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.golem; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; @@ -23,16 +26,12 @@ import hu.bme.mit.theta.solver.smtlib.utils.Compress; import hu.bme.mit.theta.solver.smtlib.utils.Compress.CompressionType; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.net.URI; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; - public class GolemSmtLibSolverInstaller extends SmtLibSolverInstaller.Default { private final List versions; @@ -41,10 +40,10 @@ public GolemSmtLibSolverInstaller(final Logger logger) { super(logger); versions = new ArrayList<>(); - versions.add(SemVer.VersionDecoder.create(SemVer.of("0.5.0")) - .addString(LINUX, X64, "x64-linux.tar.bz2") - .build() - ); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("0.5.0")) + .addString(LINUX, X64, "x64-linux.tar.bz2") + .build()); } @Override @@ -66,20 +65,21 @@ protected void installSolver(final Path installDir, final String version) } if (archStr == null) { throw new SmtLibSolverInstallerException( - String.format("%s on operating system %s and architecture %s is not supported", + String.format( + "%s on operating system %s and architecture %s is not supported", getSolverName(), OsHelper.getOs(), OsHelper.getArch())); } - final var downloadUrl = URI.create(String.format( - "https://github.com/usi-verification-and-security/golem/releases/download/v%s/golem-%s-%s", - version, version, archStr - )); + final var downloadUrl = + URI.create( + String.format( + "https://github.com/usi-verification-and-security/golem/releases/download/v%s/golem-%s-%s", + version, version, archStr)); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); try (final var inputStream = downloadUrl.toURL().openStream()) { Compress.extractTarbomb(inputStream, installDir, CompressionType.TARBZ2); - installDir.resolve(getSolverBinaryName()).toFile() - .setExecutable(true, true); + installDir.resolve(getSolverBinaryName()).toFile().setExecutable(true, true); } catch (Exception e) { throw new SmtLibSolverInstallerException(e); } @@ -94,14 +94,18 @@ protected void uninstallSolver(Path installDir, String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{"--print-witness"}; + return new String[] {"--print-witness"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { - final var solverFilePath = solverPath != null ? solverPath - : installDir.resolve(getSolverBinaryName()); + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { + final var solverFilePath = + solverPath != null ? solverPath : installDir.resolve(getSolverBinaryName()); return GolemSmtLibSolverFactory.create(solverFilePath, solverArgs); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibExprTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibExprTransformer.java index 5a7dbd33b4..eca7cdbaa3 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibExprTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,13 +22,15 @@ public class MathSATSmtLibExprTransformer extends GenericSmtLibExprTransformer { - public MathSATSmtLibExprTransformer(final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { + public MathSATSmtLibExprTransformer( + final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { super(transformer, symbolTable); } @Override protected String transformIntRem(final IntRemExpr expr) { - return String.format("(ite (< %2$s 0) (- (mod %1$s %2$s)) (mod %1$s %2$s))", + return String.format( + "(ite (< %2$s 0) (- (mod %1$s %2$s)) (mod %1$s %2$s))", toTerm(expr.getLeftOp()), toTerm(expr.getRightOp())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpMarker.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpMarker.java index d6c1ea540d..53fb66dd8e 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpMarker.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpSolver.java index 2d19bcd505..e8c20b3675 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.mathsat; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolExprs; @@ -24,23 +28,18 @@ import hu.bme.mit.theta.solver.ItpMarkerTree; import hu.bme.mit.theta.solver.ItpPattern; import hu.bme.mit.theta.solver.SolverStatus; +import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Lexer; +import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibItpSolver; +import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolverException; +import hu.bme.mit.theta.solver.smtlib.solver.binary.SmtLibSolverBinary; import hu.bme.mit.theta.solver.smtlib.solver.interpolation.SmtLibInterpolant; import hu.bme.mit.theta.solver.smtlib.solver.interpolation.SmtLibItpPattern; import hu.bme.mit.theta.solver.smtlib.solver.model.SmtLibModel; -import hu.bme.mit.theta.solver.smtlib.solver.binary.SmtLibSolverBinary; -import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolverException; +import hu.bme.mit.theta.solver.smtlib.solver.parser.ThrowExceptionErrorListener; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; -import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Lexer; -import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser; -import hu.bme.mit.theta.solver.smtlib.solver.parser.ThrowExceptionErrorListener; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.misc.Interval; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -48,18 +47,18 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; public class MathSATSmtLibItpSolver extends SmtLibItpSolver { public MathSATSmtLibItpSolver( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary - ) { + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary) { super(symbolTable, transformationManager, termTransformer, solverBinary); } @@ -77,19 +76,25 @@ public MathSATSmtLibItpMarker createMarker() { } @Override - protected void add(final MathSATSmtLibItpMarker marker, final Expr assertion, - final Set> consts, final String term) { + protected void add( + final MathSATSmtLibItpMarker marker, + final Expr assertion, + final Set> consts, + final String term) { consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); issueGeneralCommand( - String.format("(assert (! %s :interpolation-group %s))", term, marker.getMarkerName())); + String.format( + "(assert (! %s :interpolation-group %s))", term, marker.getMarkerName())); } @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(getStatus() == SolverStatus.UNSAT, + checkState( + getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof SmtLibItpPattern); - @SuppressWarnings("unchecked") final var mathsatItpPattern = (SmtLibItpPattern) pattern; + @SuppressWarnings("unchecked") + final var mathsatItpPattern = (SmtLibItpPattern) pattern; final Map> itpMap = new HashMap<>(); buildItpMapFromTree(mathsatItpPattern.getRoot(), itpMap); @@ -112,12 +117,17 @@ private List buildItpMapFromTree( } markers.add(pattern.getMarker()); - solverBinary.issueCommand(String.format("(get-interpolant (%s))", - markers.stream().map(MathSATSmtLibItpMarker::getMarkerName) - .collect(Collectors.joining(" ")))); + solverBinary.issueCommand( + String.format( + "(get-interpolant (%s))", + markers.stream() + .map(MathSATSmtLibItpMarker::getMarkerName) + .collect(Collectors.joining(" ")))); final var res = parseItpResponse(solverBinary.readResponse()); - itpMap.put(pattern.getMarker(), - termTransformer.toExpr(res, BoolExprs.Bool(), new SmtLibModel(Collections.emptyMap()))); + itpMap.put( + pattern.getMarker(), + termTransformer.toExpr( + res, BoolExprs.Bool(), new SmtLibModel(Collections.emptyMap()))); return markers; } @@ -142,7 +152,8 @@ private String parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverFactory.java index 827bddc5d3..715bef75ea 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,7 +23,6 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolver; - import java.nio.file.Path; public class MathSATSmtLibSolverFactory extends GenericSmtLibSolverFactory { @@ -35,8 +34,8 @@ private MathSATSmtLibSolverFactory(Path solverPath, String[] args, boolean itpSu this.itpSupported = itpSupported; } - public static MathSATSmtLibSolverFactory create(Path solverPath, String[] args, - boolean itpSupported) { + public static MathSATSmtLibSolverFactory create( + Path solverPath, String[] args, boolean itpSupported) { return new MathSATSmtLibSolverFactory(solverPath, args, itpSupported); } @@ -47,8 +46,8 @@ public Solver createSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args); - return new SmtLibSolver(symbolTable, transformationManager, termTransformer, solverBinary, - false); + return new SmtLibSolver( + symbolTable, transformationManager, termTransformer, solverBinary, false); } @Override @@ -58,8 +57,8 @@ public UCSolver createUCSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args); - return new SmtLibSolver(symbolTable, transformationManager, termTransformer, solverBinary, - true); + return new SmtLibSolver( + symbolTable, transformationManager, termTransformer, solverBinary, true); } @Override @@ -70,8 +69,8 @@ public ItpSolver createItpSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args); - return new MathSATSmtLibItpSolver(symbolTable, transformationManager, termTransformer, - solverBinary); + return new MathSATSmtLibItpSolver( + symbolTable, transformationManager, termTransformer, solverBinary); } else { throw new UnsupportedOperationException("MathSAT interpolation supported above 5.4.0"); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverInstaller.java index f0ee30e8a8..5621929662 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,12 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.mathsat; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X86; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.MAC; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; @@ -22,7 +28,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -30,12 +35,6 @@ import java.util.Arrays; import java.util.List; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X86; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.MAC; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; - public class MathSATSmtLibSolverInstaller extends SmtLibSolverInstaller.Default { private final List versions; @@ -44,61 +43,61 @@ public MathSATSmtLibSolverInstaller(final Logger logger) { super(logger); versions = new ArrayList<>(); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.6.7")) - .addString(LINUX, X64, "linux-x86_64") - .addString(MAC, X64, "osx") - .addString(WINDOWS, X64, "win64-msvc") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.5.0")) - .addString(LINUX, X64, "linux-x86_64") - .addString(MAC, X64, "darwin-libcxx-x86_64") - .addString(WINDOWS, X64, "win64-msvc") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.3.6")) - .addString(LINUX, X64, "linux-x86_64") - .addString(LINUX, X86, "linux-x86") - .addString(MAC, X64, "darwin-libcxx-x86_64") - .addString(WINDOWS, X64, "win64-msvc") - .addString(WINDOWS, X86, "win32-msvc") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.2.12")) - .addString(LINUX, X64, "linux-x86_64") - .addString(LINUX, X86, "linux-x86") - .addString(MAC, X64, "darwin-libcxx-x86_64") - .addString(WINDOWS, X64, "win64-msvc18") - .addString(WINDOWS, X86, "win32-msvc18") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.2.9")) - .addString(LINUX, X64, "linux-x86_64") - .addString(LINUX, X86, "linux-x86") - .addString(MAC, X64, "darwin-libcxx-x86_64") - .addString(WINDOWS, X64, "win64-msvc") - .addString(WINDOWS, X86, "win32-msvc") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.2.6")) - .addString(LINUX, X64, "linux-x86_64") - .addString(LINUX, X86, "linux-x86") - .addString(MAC, X64, "darwin-x86_64") - .addString(WINDOWS, X64, "win64-msvc") - .addString(WINDOWS, X86, "win32-msvc") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.1.10")) - .addString(LINUX, X64, "linux-x86_64") - .addString(LINUX, X86, "linux-x86") - .addString(MAC, X64, "darwin-x86_64") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("5.1.1")) - .addString(LINUX, X64, "linux-x86_64") - .addString(LINUX, X86, "linux-x86") - .build() - ); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.6.7")) + .addString(LINUX, X64, "linux-x86_64") + .addString(MAC, X64, "osx") + .addString(WINDOWS, X64, "win64-msvc") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.5.0")) + .addString(LINUX, X64, "linux-x86_64") + .addString(MAC, X64, "darwin-libcxx-x86_64") + .addString(WINDOWS, X64, "win64-msvc") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.3.6")) + .addString(LINUX, X64, "linux-x86_64") + .addString(LINUX, X86, "linux-x86") + .addString(MAC, X64, "darwin-libcxx-x86_64") + .addString(WINDOWS, X64, "win64-msvc") + .addString(WINDOWS, X86, "win32-msvc") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.2.12")) + .addString(LINUX, X64, "linux-x86_64") + .addString(LINUX, X86, "linux-x86") + .addString(MAC, X64, "darwin-libcxx-x86_64") + .addString(WINDOWS, X64, "win64-msvc18") + .addString(WINDOWS, X86, "win32-msvc18") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.2.9")) + .addString(LINUX, X64, "linux-x86_64") + .addString(LINUX, X86, "linux-x86") + .addString(MAC, X64, "darwin-libcxx-x86_64") + .addString(WINDOWS, X64, "win64-msvc") + .addString(WINDOWS, X86, "win32-msvc") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.2.6")) + .addString(LINUX, X64, "linux-x86_64") + .addString(LINUX, X86, "linux-x86") + .addString(MAC, X64, "darwin-x86_64") + .addString(WINDOWS, X64, "win64-msvc") + .addString(WINDOWS, X86, "win32-msvc") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.1.10")) + .addString(LINUX, X64, "linux-x86_64") + .addString(LINUX, X86, "linux-x86") + .addString(MAC, X64, "darwin-x86_64") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("5.1.1")) + .addString(LINUX, X64, "linux-x86_64") + .addString(LINUX, X86, "linux-x86") + .build()); } @Override @@ -120,14 +119,18 @@ protected void installSolver(Path installDir, String version) } if (archStr == null) { throw new SmtLibSolverInstallerException( - String.format("MathSAT on operating system %s and architecture %s is not supported", + String.format( + "MathSAT on operating system %s and architecture %s is not supported", OsHelper.getOs(), OsHelper.getArch())); } - final var downloadUrl = URI.create(String.format( - "https://mathsat.fbk.eu/download.php?file=mathsat-%s-%s.%s", - version, archStr, OsHelper.getOs().equals(WINDOWS) ? "zip" : "tar.gz" - )); + final var downloadUrl = + URI.create( + String.format( + "https://mathsat.fbk.eu/download.php?file=mathsat-%s-%s.%s", + version, + archStr, + OsHelper.getOs().equals(WINDOWS) ? "zip" : "tar.gz")); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); @@ -137,7 +140,10 @@ protected void installSolver(Path installDir, String version) } else { Compress.extract(inputStream, installDir, Compress.CompressionType.TARGZ); } - installDir.resolve("bin").resolve(getSolverBinaryName()).toFile() + installDir + .resolve("bin") + .resolve(getSolverBinaryName()) + .toFile() .setExecutable(true, true); } catch (IOException e) { throw new SmtLibSolverInstallerException(e); @@ -153,33 +159,36 @@ protected void uninstallSolver(Path installDir, String version) { @Override protected String[] getDefaultSolverArgs(String version) throws SmtLibSolverInstallerException { - return new String[]{"-theory.bv.eager=false", "-theory.fp.mode=2"}; + return new String[] {"-theory.bv.eager=false", "-theory.fp.mode=2"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { - final var solverFilePath = solverPath != null ? solverPath - : installDir.resolve("bin").resolve(getSolverBinaryName()); + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { + final var solverFilePath = + solverPath != null + ? solverPath + : installDir.resolve("bin").resolve(getSolverBinaryName()); return MathSATSmtLibSolverFactory.create( - solverFilePath, solverArgs, - !SemVer.valid(version) || SemVer.of(version).compareTo(SemVer.of("5.4.0")) >= 0 - ); + solverFilePath, + solverArgs, + !SemVer.valid(version) || SemVer.of(version).compareTo(SemVer.of("5.4.0")) >= 0); } @Override public List getSupportedVersions() { return Arrays.asList( - "5.6.10", "5.6.9", "5.6.8", "5.6.7", "5.6.6", "5.6.5", "5.6.4", "5.6.3", "5.6.2", "5.6.1", "5.6.0", - "5.5.4", "5.5.3", "5.5.2", "5.5.1", "5.5.0", - "5.4.1", "5.4.0", - "5.3.14", "5.3.13", "5.3.12", "5.3.11", "5.3.10", "5.3.9", "5.3.8", "5.3.7", "5.3.6", - "5.3.5", "5.3.4", "5.3.3", "5.3.2", "5.3.1", - "5.2.12", "5.2.11", "5.2.10", "5.2.9", "5.2.8", "5.2.7", "5.2.6", "5.2.5", "5.2.4", - "5.2.3", "5.2.2", "5.2.1", + "5.6.10", "5.6.9", "5.6.8", "5.6.7", "5.6.6", "5.6.5", "5.6.4", "5.6.3", "5.6.2", + "5.6.1", "5.6.0", "5.5.4", "5.5.3", "5.5.2", "5.5.1", "5.5.0", "5.4.1", "5.4.0", + "5.3.14", "5.3.13", "5.3.12", "5.3.11", "5.3.10", "5.3.9", "5.3.8", "5.3.7", + "5.3.6", "5.3.5", "5.3.4", "5.3.3", "5.3.2", "5.3.1", "5.2.12", "5.2.11", "5.2.10", + "5.2.9", "5.2.8", "5.2.7", "5.2.6", "5.2.5", "5.2.4", "5.2.3", "5.2.2", "5.2.1", "5.1.12", "5.1.11", "5.1.10", "5.1.9", "5.1.8", "5.1.7", "5.1.6", "5.1.5", "5.1.4", - "5.1.3" - ); + "5.1.3"); } private String getSolverBinaryName() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibTransformationManager.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibTransformationManager.java index 12dd71c7bb..9a0f113bcd 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibTransformationManager.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/mathsat/MathSATSmtLibTransformationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,8 +28,7 @@ public MathSATSmtLibTransformationManager(final SmtLibSymbolTable symbolTable) { @Override protected SmtLibExprTransformer instantiateExprTransformer( - final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable - ) { + final SmtLibTransformationManager transformer, final SmtLibSymbolTable symbolTable) { return new MathSATSmtLibExprTransformer(transformer, symbolTable); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpMarker.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpMarker.java index 7fbe211c11..0d652f0d03 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpMarker.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,6 +17,4 @@ import hu.bme.mit.theta.solver.smtlib.solver.interpolation.SmtLibItpMarker; -public class PrincessSmtLibItpMarker extends SmtLibItpMarker { - -} +public class PrincessSmtLibItpMarker extends SmtLibItpMarker {} diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpSolver.java index 4a797c200e..742b6d6017 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.princess; +import static com.google.common.base.Preconditions.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolExprs; @@ -33,17 +36,13 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; +import java.util.*; +import java.util.stream.Collectors; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.misc.Interval; -import java.util.*; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.*; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - public final class PrincessSmtLibItpSolver extends SmtLibItpSolver { private final Map, String> assertionNames = new IdentityHashMap<>(); @@ -53,9 +52,9 @@ public final class PrincessSmtLibItpSolver extends SmtLibItpSolver assertion, - final Set> consts, final String term) { + protected void add( + final PrincessSmtLibItpMarker marker, + final Expr assertion, + final Set> consts, + final String term) { consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); final var name = String.format(assertionNamePattern, assertionCount++); @@ -84,10 +86,12 @@ protected void add(final PrincessSmtLibItpMarker marker, final Expr as @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(getStatus() == SolverStatus.UNSAT, + checkState( + getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof SmtLibItpPattern); - @SuppressWarnings("unchecked") final var princessItpPattern = (SmtLibItpPattern) pattern; + @SuppressWarnings("unchecked") + final var princessItpPattern = (SmtLibItpPattern) pattern; final var term = patternToTerm(princessItpPattern.getRoot()); @@ -95,8 +99,9 @@ public Interpolant getInterpolant(final ItpPattern pattern) { solverBinary.issueCommand(String.format("(get-interpolants %s)", term)); for (final var itp : parseItpResponse(solverBinary.readResponse())) { - itpList.add(termTransformer.toExpr(itp, BoolExprs.Bool(), - new SmtLibModel(Collections.emptyMap()))); + itpList.add( + termTransformer.toExpr( + itp, BoolExprs.Bool(), new SmtLibModel(Collections.emptyMap()))); } itpList.add(False()); @@ -114,8 +119,12 @@ private String patternToTerm(final ItpMarkerTree marker if (terms.size() == 1) { term = assertionNames.get(terms.iterator().next().get1()); } else { - term = String.format("(and %s)", terms.stream().map(t -> assertionNames.get(t.get1())) - .collect(Collectors.joining(" "))); + term = + String.format( + "(and %s)", + terms.stream() + .map(t -> assertionNames.get(t.get1())) + .collect(Collectors.joining(" "))); } final var children = markerTree.getChildren(); @@ -130,8 +139,10 @@ private String patternToTerm(final ItpMarkerTree marker return term; } - private void buildItpMapFormList(final ItpMarkerTree pattern, - final List> itpList, final Map> itpMap) { + private void buildItpMapFormList( + final ItpMarkerTree pattern, + final List> itpList, + final Map> itpMap) { for (final ItpMarkerTree child : pattern.getChildren()) { buildItpMapFormList(child, itpList, itpMap); } @@ -176,7 +187,8 @@ private List parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverFactory.java index f98f22b72d..2d47a214f9 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,17 +18,22 @@ import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.smtlib.impl.generic.*; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibEnumStrategy; - import java.nio.file.Path; import java.util.EnumSet; public class PrincessSmtLibSolverFactory extends GenericSmtLibSolverFactory { - private PrincessSmtLibSolverFactory(Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { - super(solverPath, args, EnumSet.of(GenericSmtLibSolverBinary.Solver.PRINCESS), enumStrategy); + private PrincessSmtLibSolverFactory( + Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { + super( + solverPath, + args, + EnumSet.of(GenericSmtLibSolverBinary.Solver.PRINCESS), + enumStrategy); } - public static PrincessSmtLibSolverFactory create(Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { + public static PrincessSmtLibSolverFactory create( + Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { return new PrincessSmtLibSolverFactory(solverPath, args, enumStrategy); } @@ -37,10 +42,11 @@ public ItpSolver createItpSolver() { final var symbolTable = new GenericSmtLibSymbolTable(); final var transformationManager = new GenericSmtLibTransformationManager(symbolTable); final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); - final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args, - EnumSet.of(GenericSmtLibSolverBinary.Solver.PRINCESS)); + final var solverBinary = + new GenericSmtLibSolverBinary( + solverPath, args, EnumSet.of(GenericSmtLibSolverBinary.Solver.PRINCESS)); - return new PrincessSmtLibItpSolver(symbolTable, transformationManager, termTransformer, - solverBinary, enumStrategy); + return new PrincessSmtLibItpSolver( + symbolTable, transformationManager, termTransformer, solverBinary, enumStrategy); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverInstaller.java index 5c759d715a..e7a8262b42 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/princess/PrincessSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,7 +22,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; - import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -44,15 +43,16 @@ protected String getSolverName() { protected void installSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException { - final var downloadUrl = Integer.parseInt(version.substring(0, 4)) > 2021 ? - URI.create(String.format( - "https://github.com/uuverifiers/princess/releases/download/snapshot-%s/princess-bin-%s.zip", - version, version - )) : - URI.create(String.format( - "http://www.philipp.ruemmer.org/princess/princess-bin-%s.zip", - version - )); + final var downloadUrl = + Integer.parseInt(version.substring(0, 4)) > 2021 + ? URI.create( + String.format( + "https://github.com/uuverifiers/princess/releases/download/snapshot-%s/princess-bin-%s.zip", + version, version)) + : URI.create( + String.format( + "http://www.philipp.ruemmer.org/princess/princess-bin-%s.zip", + version)); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); @@ -73,31 +73,43 @@ protected void uninstallSolver(final Path installDir, final String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{ - "+stdin", - "+incremental", - "+quiet" - }; + return new String[] {"+stdin", "+incremental", "+quiet"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { final var solverFilePath = solverPath != null ? solverPath : installDir.resolve(getSolverBinaryName()); // Even though all versions support interpolation with datatypes, the result interpolation // contains arithmetic, so it's better to just use the sort approach - return PrincessSmtLibSolverFactory.create(solverFilePath, solverArgs, SmtLibEnumStrategy.SORTS); + return PrincessSmtLibSolverFactory.create( + solverFilePath, solverArgs, SmtLibEnumStrategy.SORTS); } @Override public List getSupportedVersions() { return Arrays.asList( "2024-01-12", - "2023-06-19", "2023-04-07", "2022-11-03", "2022-07-01", "2021-11-15", - "2021-05-10", "2021-03-10", "2020-03-12", "2019-10-02", "2019-07-24", - "2018-10-26", "2018-05-25", "2018-01-27", "2017-12-06", "2017-07-17" - ); + "2023-06-19", + "2023-04-07", + "2022-11-03", + "2022-07-01", + "2021-11-15", + "2021-05-10", + "2021-03-10", + "2020-03-12", + "2019-10-02", + "2019-07-24", + "2018-10-26", + "2018-05-25", + "2018-01-27", + "2017-12-06", + "2017-07-17"); } private String getSolverBinaryName() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpMarker.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpMarker.java index 22b4a718c4..e0f606c93e 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpMarker.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,6 +17,4 @@ import hu.bme.mit.theta.solver.smtlib.solver.interpolation.SmtLibItpMarker; -public class SMTInterpolSmtLibItpMarker extends SmtLibItpMarker { - -} +public class SMTInterpolSmtLibItpMarker extends SmtLibItpMarker {} diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpSolver.java index cafb3e2ff5..68f171e836 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.smtinterpol; +import static com.google.common.base.Preconditions.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolExprs; @@ -33,17 +36,13 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; +import java.util.*; +import java.util.stream.Collectors; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.misc.Interval; -import java.util.*; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.*; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - public final class SMTInterpolSmtLibItpSolver extends SmtLibItpSolver { private final Map, String> assertionNames = new IdentityHashMap<>(); @@ -53,9 +52,9 @@ public final class SMTInterpolSmtLibItpSolver extends SmtLibItpSolver assertion, - final Set> consts, final String term) { + protected void add( + final SMTInterpolSmtLibItpMarker marker, + final Expr assertion, + final Set> consts, + final String term) { consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); final var name = String.format(assertionNamePattern, assertionCount++); assertionNames.put(assertion, name); - issueGeneralCommand(String.format("(assert (! %s :named %s))", enumStrategy.wrapAssertionExpression(term, consts.stream().collect(Collectors.toMap(c -> c, symbolTable::getSymbol))), name)); + issueGeneralCommand( + String.format( + "(assert (! %s :named %s))", + enumStrategy.wrapAssertionExpression( + term, + consts.stream() + .collect(Collectors.toMap(c -> c, symbolTable::getSymbol))), + name)); } @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(getStatus() == SolverStatus.UNSAT, + checkState( + getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof SmtLibItpPattern); - @SuppressWarnings("unchecked") final var smtInterpolItpPattern = (SmtLibItpPattern) pattern; + @SuppressWarnings("unchecked") + final var smtInterpolItpPattern = (SmtLibItpPattern) pattern; final var term = patternToTerm(smtInterpolItpPattern.getRoot()); @@ -95,8 +106,9 @@ public Interpolant getInterpolant(final ItpPattern pattern) { solverBinary.issueCommand(String.format("(get-interpolants %s)", term)); for (final var itp : parseItpResponse(solverBinary.readResponse())) { - itpList.add(termTransformer.toExpr(itp, BoolExprs.Bool(), - new SmtLibModel(Collections.emptyMap()))); + itpList.add( + termTransformer.toExpr( + itp, BoolExprs.Bool(), new SmtLibModel(Collections.emptyMap()))); } itpList.add(False()); @@ -114,8 +126,12 @@ private String patternToTerm(final ItpMarkerTree mar if (terms.size() == 1) { term = assertionNames.get(terms.iterator().next().get1()); } else { - term = String.format("(and %s)", terms.stream().map(t -> assertionNames.get(t.get1())) - .collect(Collectors.joining(" "))); + term = + String.format( + "(and %s)", + terms.stream() + .map(t -> assertionNames.get(t.get1())) + .collect(Collectors.joining(" "))); } final var children = markerTree.getChildren(); @@ -130,8 +146,10 @@ private String patternToTerm(final ItpMarkerTree mar return term; } - private void buildItpMapFormList(final ItpMarkerTree pattern, - final List> itpList, final Map> itpMap) { + private void buildItpMapFormList( + final ItpMarkerTree pattern, + final List> itpList, + final Map> itpMap) { for (final ItpMarkerTree child : pattern.getChildren()) { buildItpMapFormList(child, itpList, itpMap); } @@ -176,7 +194,8 @@ private List parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverFactory.java index 1ca42d77f3..0e3e841e21 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,7 +25,6 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTransformationManager; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibEnumStrategy; import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolver; - import java.nio.file.Path; public class SMTInterpolSmtLibSolverFactory implements SolverFactory { @@ -35,13 +34,15 @@ public class SMTInterpolSmtLibSolverFactory implements SolverFactory { private final Path solverPath; private final String[] args; - private SMTInterpolSmtLibSolverFactory(Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { + private SMTInterpolSmtLibSolverFactory( + Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { this.solverPath = solverPath; this.args = args; this.enumStrategy = enumStrategy; } - public static SMTInterpolSmtLibSolverFactory create(Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { + public static SMTInterpolSmtLibSolverFactory create( + Path solverPath, String[] args, final SmtLibEnumStrategy enumStrategy) { return new SMTInterpolSmtLibSolverFactory(solverPath, args, enumStrategy); } @@ -52,8 +53,13 @@ public Solver createSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(getJavaBinary(), getSolverArgs()); - return new SmtLibSolver(symbolTable, transformationManager, termTransformer, solverBinary, - false, enumStrategy); + return new SmtLibSolver( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + false, + enumStrategy); } @Override @@ -63,8 +69,13 @@ public UCSolver createUCSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(getJavaBinary(), getSolverArgs()); - return new SmtLibSolver(symbolTable, transformationManager, termTransformer, solverBinary, - true, enumStrategy); + return new SmtLibSolver( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + true, + enumStrategy); } @Override @@ -74,8 +85,8 @@ public ItpSolver createItpSolver() { final var termTransformer = new GenericSmtLibTermTransformer(symbolTable, enumStrategy); final var solverBinary = new GenericSmtLibSolverBinary(getJavaBinary(), getSolverArgs()); - return new SMTInterpolSmtLibItpSolver(symbolTable, transformationManager, termTransformer, - solverBinary, enumStrategy); + return new SMTInterpolSmtLibItpSolver( + symbolTable, transformationManager, termTransformer, solverBinary, enumStrategy); } private Path getJavaBinary() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverInstaller.java index a97ba7a0c0..0d225f337c 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/smtinterpol/SMTInterpolSmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.SmtLibEnumStrategy; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstaller; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; - import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; @@ -46,13 +45,17 @@ protected String getSolverName() { protected void installSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException { - try ( - final var inputChannel = Channels.newChannel(getDownloadUrl(version).openStream()); - final var outputChannel = new FileOutputStream( - installDir.resolve(getSolverBinaryName(version)).toAbsolutePath() - .toString()).getChannel() - ) { - logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", + try (final var inputChannel = Channels.newChannel(getDownloadUrl(version).openStream()); + final var outputChannel = + new FileOutputStream( + installDir + .resolve(getSolverBinaryName(version)) + .toAbsolutePath() + .toString()) + .getChannel()) { + logger.write( + Logger.Level.MAINSTEP, + "Starting download (%s)...\n", getDownloadUrl(version).toString()); outputChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); } catch (IOException e) { @@ -69,41 +72,50 @@ protected void uninstallSolver(final Path installDir, final String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{"-smt2", "-q"}; + return new String[] {"-smt2", "-q"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { final var solverFilePath = solverPath != null ? solverPath : installDir.resolve(getSolverBinaryName(version)); - return SMTInterpolSmtLibSolverFactory.create(solverFilePath, solverArgs, getEnumStrategyForVersion(version)); + return SMTInterpolSmtLibSolverFactory.create( + solverFilePath, solverArgs, getEnumStrategyForVersion(version)); } @Override public List getSupportedVersions() { - //TODO download won't work on 2.5-1301 yet, so in order for 'latest' to work, order has to stay like this for now - return Arrays.asList("2.5-1256", "2.5-1301", "2.5-1230", "2.5-916", "2.5-663", "2.5-479", "2.5-7"); + // TODO download won't work on 2.5-1301 yet, so in order for 'latest' to work, order has to + // stay like this for now + return Arrays.asList( + "2.5-1256", "2.5-1301", "2.5-1230", "2.5-916", "2.5-663", "2.5-479", "2.5-7"); } private URL getDownloadUrl(final String version) throws SmtLibSolverInstallerException, MalformedURLException { - final String fileName = switch (version) { - - case "2.5-1301" -> "2.5-1301-g2c871e40"; - case "2.5-1256" -> "2.5-1256-g55d6ba76"; - case "2.5-1230" -> "2.5-1230-g3eafb46a"; - case "2.5-916" -> "2.5-916-ga5843d8b"; - case "2.5-663" -> "2.5-663-gf15aa217"; - case "2.5-479" -> "2.5-479-ga49e50b1"; - case "2.5-7" -> "2.5-7-g64ec65d"; - default -> throw new SmtLibSolverInstallerException("Unsupported solver version."); - }; - - return URI.create(String.format( - "https://ultimate.informatik.uni-freiburg.de/smtinterpol/smtinterpol-%s.jar", - fileName - )).toURL(); + final String fileName = + switch (version) { + case "2.5-1301" -> "2.5-1301-g2c871e40"; + case "2.5-1256" -> "2.5-1256-g55d6ba76"; + case "2.5-1230" -> "2.5-1230-g3eafb46a"; + case "2.5-916" -> "2.5-916-ga5843d8b"; + case "2.5-663" -> "2.5-663-gf15aa217"; + case "2.5-479" -> "2.5-479-ga49e50b1"; + case "2.5-7" -> "2.5-7-g64ec65d"; + default -> + throw new SmtLibSolverInstallerException("Unsupported solver version."); + }; + + return URI.create( + String.format( + "https://ultimate.informatik.uni-freiburg.de/smtinterpol/smtinterpol-%s.jar", + fileName)) + .toURL(); } private String getSolverBinaryName(final String version) { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3NewSmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3NewSmtLibItpSolver.java index 6d1e7aaf10..76f8d34198 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3NewSmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3NewSmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.z3; +import static com.google.common.base.Preconditions.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.Expr; @@ -32,27 +36,24 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; +import java.util.*; +import java.util.stream.Collectors; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.misc.Interval; -import java.util.*; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.*; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - public class Z3NewSmtLibItpSolver extends SmtLibItpSolver { private final Map, String> assertionNames = new HashMap<>(); private static final String assertionNamePattern = "_z3_assertion_%d"; private static long assertionCount = 0; - public Z3NewSmtLibItpSolver(final SmtLibSymbolTable symbolTable, - final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary) { + public Z3NewSmtLibItpSolver( + final SmtLibSymbolTable symbolTable, + final SmtLibTransformationManager transformationManager, + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary) { super(symbolTable, transformationManager, termTransformer, solverBinary); } @@ -70,8 +71,11 @@ public Z3SmtLibItpMarker createMarker() { } @Override - protected void add(Z3SmtLibItpMarker marker, Expr assertion, Set> consts, - String term) { + protected void add( + Z3SmtLibItpMarker marker, + Expr assertion, + Set> consts, + String term) { consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); final var name = String.format(assertionNamePattern, assertionCount++); @@ -81,10 +85,12 @@ protected void add(Z3SmtLibItpMarker marker, Expr assertion, Set) pattern; + @SuppressWarnings("unchecked") + final var z3ItpPattern = (SmtLibItpPattern) pattern; final List markers = z3ItpPattern.getSequence(); final List A = new ArrayList<>(); @@ -96,17 +102,26 @@ public Interpolant getInterpolant(ItpPattern pattern) { A.add(marker); if (B.size() != 0) { - final var aTerm = A.stream().flatMap(m -> m.getTerms().stream().map(Tuple2::get1)) - .map(assertionNames::get); - final var bTerm = B.stream().flatMap(m -> m.getTerms().stream().map(Tuple2::get1)) - .map(assertionNames::get); - - solverBinary.issueCommand(String.format("(get-interpolant (and %s) (and %s))", - aTerm.collect(Collectors.joining(" ")), - bTerm.collect(Collectors.joining(" ")))); - - itpMap.put(marker, - termTransformer.toExpr(parseItpResponse(solverBinary.readResponse()), Bool(), + final var aTerm = + A.stream() + .flatMap(m -> m.getTerms().stream().map(Tuple2::get1)) + .map(assertionNames::get); + final var bTerm = + B.stream() + .flatMap(m -> m.getTerms().stream().map(Tuple2::get1)) + .map(assertionNames::get); + + solverBinary.issueCommand( + String.format( + "(get-interpolant (and %s) (and %s))", + aTerm.collect(Collectors.joining(" ")), + bTerm.collect(Collectors.joining(" ")))); + + itpMap.put( + marker, + termTransformer.toExpr( + parseItpResponse(solverBinary.readResponse()), + Bool(), new SmtLibModel(Collections.emptyMap()))); } else { itpMap.put(marker, False()); @@ -136,7 +151,8 @@ private String parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } @@ -144,7 +160,7 @@ private static String extractString(final ParserRuleContext ctx) { protected void init() { issueGeneralCommand("(set-option :print-success true)"); issueGeneralCommand("(set-option :produce-models true)"); - //issueGeneralCommand("(set-option :produce-interpolants true)"); + // issueGeneralCommand("(set-option :produce-interpolants true)"); issueGeneralCommand("(set-logic ALL)"); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3OldSmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3OldSmtLibItpSolver.java index 7f1bf8d80d..1e32613e17 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3OldSmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3OldSmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.z3; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.Expr; @@ -37,11 +41,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.misc.Interval; - import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -50,10 +49,10 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; public final class Z3OldSmtLibItpSolver extends SmtLibItpSolver { @@ -62,8 +61,8 @@ public final class Z3OldSmtLibItpSolver extends SmtLibItpSolver assertion) { if (topMostContainsAssertions) { @@ -91,8 +89,11 @@ public void add(ItpMarker marker, Expr assertion) { } @Override - protected void add(final Z3SmtLibItpMarker marker, final Expr assertion, - final Set> consts, final String term) { + protected void add( + final Z3SmtLibItpMarker marker, + final Expr assertion, + final Set> consts, + final String term) { consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); } @@ -112,9 +113,14 @@ public SolverStatus check() { issueGeneralCommand( String.format("(assert (! true :named %s))", marker.getMarkerName())); } else { - final var term = String.format("(and %s)", String.join(" ", - marker.getTerms().stream().map(Tuple2::get2) - .collect(Collectors.toUnmodifiableList()))); + final var term = + String.format( + "(and %s)", + String.join( + " ", + marker.getTerms().stream() + .map(Tuple2::get2) + .collect(Collectors.toUnmodifiableList()))); issueGeneralCommand( String.format("(assert (! %s :named %s))", term, marker.getMarkerName())); @@ -144,10 +150,12 @@ public void pop(int n) { @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(getStatus() == SolverStatus.UNSAT, + checkState( + getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof SmtLibItpPattern); - @SuppressWarnings("unchecked") final var z3ItpPattern = (SmtLibItpPattern) pattern; + @SuppressWarnings("unchecked") + final var z3ItpPattern = (SmtLibItpPattern) pattern; final var term = patternToTerm(z3ItpPattern.getRoot()); final var markerCount = getMarkerCount(z3ItpPattern.getRoot()); @@ -157,8 +165,9 @@ public Interpolant getInterpolant(final ItpPattern pattern) { solverBinary.issueCommand(String.format("(get-interpolant %s)", term)); for (var i = 0; i < markerCount; i++) { final var res = parseItpResponse(solverBinary.readResponse()); - itpList.add(termTransformer.toExpr(res, BoolExprs.Bool(), - new SmtLibModel(Collections.emptyMap()))); + itpList.add( + termTransformer.toExpr( + res, BoolExprs.Bool(), new SmtLibModel(Collections.emptyMap()))); } // itpList.add(False()); @@ -182,9 +191,10 @@ private String patternToTerm(final ItpMarkerTree markerTree) return String.format("(interp (and %s))", String.join(" ", opTerms)); } - private void buildItpMapFormList(final ItpMarkerTree pattern, - final List> itpList, - final Map> itpMap) { + private void buildItpMapFormList( + final ItpMarkerTree pattern, + final List> itpList, + final Map> itpMap) { for (final ItpMarkerTree child : pattern.getChildren()) { buildItpMapFormList(child, itpList, itpMap); } @@ -226,7 +236,8 @@ private String parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibItpMarker.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibItpMarker.java index 00b2acc9a6..aedbcf8cba 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibItpMarker.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverFactory.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverFactory.java index 926e89b0e9..9ff86aca60 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverFactory.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,13 +21,14 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTransformationManager; - import java.nio.file.Path; public class Z3SmtLibSolverFactory extends GenericSmtLibSolverFactory { public enum Z3ItpSupport { - NONE, OLD, NEW + NONE, + OLD, + NEW } private final Z3ItpSupport itpSupport; @@ -37,8 +38,8 @@ private Z3SmtLibSolverFactory(Path solverPath, String[] args, Z3ItpSupport itpSu this.itpSupport = itpSupport; } - public static Z3SmtLibSolverFactory create(Path solverPath, String[] args, - Z3ItpSupport itpSupport) { + public static Z3SmtLibSolverFactory create( + Path solverPath, String[] args, Z3ItpSupport itpSupport) { return new Z3SmtLibSolverFactory(solverPath, args, itpSupport); } @@ -51,11 +52,11 @@ public ItpSolver createItpSolver() { final var solverBinary = new GenericSmtLibSolverBinary(solverPath, args); if (itpSupport.equals(Z3ItpSupport.OLD)) { - return new Z3OldSmtLibItpSolver(symbolTable, transformationManager, termTransformer, - solverBinary); + return new Z3OldSmtLibItpSolver( + symbolTable, transformationManager, termTransformer, solverBinary); } else if (itpSupport.equals(Z3ItpSupport.NEW)) { - return new Z3NewSmtLibItpSolver(symbolTable, transformationManager, termTransformer, - solverBinary); + return new Z3NewSmtLibItpSolver( + symbolTable, transformationManager, termTransformer, solverBinary); } else { throw new AssertionError(); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverInstaller.java index e8abed63aa..a3fda4b167 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/impl/z3/Z3SmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,12 @@ */ package hu.bme.mit.theta.solver.smtlib.impl.z3; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; +import static hu.bme.mit.theta.common.OsHelper.Architecture.X86; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.MAC; +import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; @@ -22,7 +28,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.utils.Compress; import hu.bme.mit.theta.solver.smtlib.utils.SemVer; - import java.io.IOException; import java.net.URI; import java.nio.file.Path; @@ -30,12 +35,6 @@ import java.util.Arrays; import java.util.List; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X64; -import static hu.bme.mit.theta.common.OsHelper.Architecture.X86; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.LINUX; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.MAC; -import static hu.bme.mit.theta.common.OsHelper.OperatingSystem.WINDOWS; - public class Z3SmtLibSolverInstaller extends SmtLibSolverInstaller.Default { private final List versions; @@ -44,82 +43,82 @@ public Z3SmtLibSolverInstaller(final Logger logger) { super(logger); versions = new ArrayList<>(); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.12.0")) - .addString(LINUX, X64, "x64-glibc-2.35") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.16") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.12")) - .addString(LINUX, X64, "x64-glibc-2.31") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.16") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.11")) - .addString(LINUX, X64, "x64-glibc-2.31") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.15.7") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.10")) - .addString(LINUX, X64, "x64-ubuntu-18.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.15.7") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.5")) - .addString(LINUX, X64, "x64-ubuntu-16.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.14.6") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.5")) - .addString(LINUX, X64, "x64-ubuntu-16.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.14.2") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.4")) - .addString(LINUX, X64, "x64-ubuntu-16.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.14.1") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.8.3")) - .addString(LINUX, X64, "x64-ubuntu-16.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.13.6") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.6.0")) - .addString(LINUX, X64, "x64-ubuntu-16.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.11.6") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.4.0")) - .addString(LINUX, X64, "x64-ubuntu-14.04") - .addString(LINUX, X86, "x86-ubuntu-14.04") - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .addString(MAC, X64, "x64-osx-10.11.6") - .build() - ); - versions.add(SemVer.VersionDecoder.create(SemVer.of("4.3.2")) - .addString(WINDOWS, X64, "x64-win") - .addString(WINDOWS, X86, "x86-win") - .build() - ); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.12.0")) + .addString(LINUX, X64, "x64-glibc-2.35") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.16") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.12")) + .addString(LINUX, X64, "x64-glibc-2.31") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.16") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.11")) + .addString(LINUX, X64, "x64-glibc-2.31") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.15.7") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.10")) + .addString(LINUX, X64, "x64-ubuntu-18.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.15.7") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.5")) + .addString(LINUX, X64, "x64-ubuntu-16.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.14.6") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.5")) + .addString(LINUX, X64, "x64-ubuntu-16.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.14.2") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.4")) + .addString(LINUX, X64, "x64-ubuntu-16.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.14.1") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.8.3")) + .addString(LINUX, X64, "x64-ubuntu-16.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.13.6") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.6.0")) + .addString(LINUX, X64, "x64-ubuntu-16.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.11.6") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.4.0")) + .addString(LINUX, X64, "x64-ubuntu-14.04") + .addString(LINUX, X86, "x86-ubuntu-14.04") + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .addString(MAC, X64, "x64-osx-10.11.6") + .build()); + versions.add( + SemVer.VersionDecoder.create(SemVer.of("4.3.2")) + .addString(WINDOWS, X64, "x64-win") + .addString(WINDOWS, X86, "x86-win") + .build()); } @Override @@ -141,19 +140,24 @@ protected void installSolver(final Path installDir, final String version) } if (archStr == null) { throw new SmtLibSolverInstallerException( - String.format("z3 on operating system %s and architecture %s is not supported", + String.format( + "z3 on operating system %s and architecture %s is not supported", OsHelper.getOs(), OsHelper.getArch())); } - final var downloadUrl = URI.create(String.format( - "https://github.com/Z3Prover/z3/releases/download/z3-%s/z3-%s-%s.zip", - version, version, archStr - )); + final var downloadUrl = + URI.create( + String.format( + "https://github.com/Z3Prover/z3/releases/download/z3-%s/z3-%s-%s.zip", + version, version, archStr)); logger.write(Logger.Level.MAINSTEP, "Starting download (%s)...\n", downloadUrl.toString()); try (final var inputStream = downloadUrl.toURL().openStream()) { Compress.extract(inputStream, installDir, Compress.CompressionType.ZIP); - installDir.resolve("bin").resolve(getSolverBinaryName()).toFile() + installDir + .resolve("bin") + .resolve(getSolverBinaryName()) + .toFile() .setExecutable(true, true); } catch (IOException e) { throw new SmtLibSolverInstallerException(e); @@ -169,36 +173,40 @@ protected void uninstallSolver(Path installDir, String version) { @Override protected String[] getDefaultSolverArgs(String version) { - return new String[]{"-smt2", "-in"}; + return new String[] {"-smt2", "-in"}; } @Override - public SolverFactory getSolverFactory(final Path installDir, final String version, - final Path solverPath, final String[] solverArgs) throws SmtLibSolverInstallerException { - final var solverFilePath = solverPath != null ? solverPath - : installDir.resolve("bin").resolve(getSolverBinaryName()); + public SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] solverArgs) + throws SmtLibSolverInstallerException { + final var solverFilePath = + solverPath != null + ? solverPath + : installDir.resolve("bin").resolve(getSolverBinaryName()); if (SemVer.of(version).compareTo(SemVer.of("4.5.0")) <= 0) { - return Z3SmtLibSolverFactory.create(solverFilePath, solverArgs, - Z3SmtLibSolverFactory.Z3ItpSupport.OLD); + return Z3SmtLibSolverFactory.create( + solverFilePath, solverArgs, Z3SmtLibSolverFactory.Z3ItpSupport.OLD); } else if (SemVer.of(version).compareTo(SemVer.of("4.8.8")) >= 0) { - return Z3SmtLibSolverFactory.create(solverFilePath, solverArgs, - Z3SmtLibSolverFactory.Z3ItpSupport.NEW); + return Z3SmtLibSolverFactory.create( + solverFilePath, solverArgs, Z3SmtLibSolverFactory.Z3ItpSupport.NEW); } else { - return Z3SmtLibSolverFactory.create(solverFilePath, solverArgs, - Z3SmtLibSolverFactory.Z3ItpSupport.NONE); + return Z3SmtLibSolverFactory.create( + solverFilePath, solverArgs, Z3SmtLibSolverFactory.Z3ItpSupport.NONE); } } @Override public List getSupportedVersions() { return Arrays.asList( - "4.13.0", "4.12.6", "4.12.5", "4.12.4", "4.12.3", - "4.12.2", "4.12.1", "4.12.0", "4.11.2", "4.11.0", "4.10.2", "4.10.1", "4.10.0", "4.9.1", "4.9.0", - "4.8.17", "4.8.16", "4.8.15", "4.8.14", "4.8.13", "4.8.12", "4.8.11", "4.8.10", "4.8.9", - "4.8.8", "4.8.7", - "4.8.6", "4.8.5", "4.8.4", "4.8.3", "4.8.2", "4.8.1", "4.7.1", "4.6.0", "4.5.0", - "4.4.1", "4.4.0", "4.3.2" - ); + "4.13.0", "4.12.6", "4.12.5", "4.12.4", "4.12.3", "4.12.2", "4.12.1", "4.12.0", + "4.11.2", "4.11.0", "4.10.2", "4.10.1", "4.10.0", "4.9.1", "4.9.0", "4.8.17", + "4.8.16", "4.8.15", "4.8.14", "4.8.13", "4.8.12", "4.8.11", "4.8.10", "4.8.9", + "4.8.8", "4.8.7", "4.8.6", "4.8.5", "4.8.4", "4.8.3", "4.8.2", "4.8.1", "4.7.1", + "4.6.0", "4.5.0", "4.4.1", "4.4.0", "4.3.2"); } private String getSolverBinaryName() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibEnumStrategy.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibEnumStrategy.java index bae1132271..30ed496ba8 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibEnumStrategy.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibEnumStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,13 +18,11 @@ import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.enumtype.EnumLitExpr; import hu.bme.mit.theta.core.type.enumtype.EnumType; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Function_defContext; import hu.bme.mit.theta.solver.smtlib.solver.model.SmtLibModel; - import java.util.*; import java.util.function.Consumer; @@ -34,43 +32,64 @@ * interpolation with datatypes. For this, a workaround is implemented in the SORTS strategy. */ public enum SmtLibEnumStrategy { - DATATYPES { @Override - public void declareDatatypes(final Collection allTypes, final Stack typeStack, final Consumer issueGeneralCommand) { + public void declareDatatypes( + final Collection allTypes, + final Stack typeStack, + final Consumer issueGeneralCommand) { List types = new ArrayList<>(allTypes); types.removeAll(typeStack.toCollection()); Set typeSet = new HashSet<>(types); - for (Type t : - typeSet) { + for (Type t : typeSet) { if (t instanceof EnumType enumType) { typeStack.add(enumType); - Collection literals = enumType.getLongValues().stream().map(name -> String.format("(%s)", name)).toList(); - issueGeneralCommand.accept(String.format("(declare-datatypes ((%s 0)) ((%s)))", enumType.getName(), String.join(" ", literals))); + Collection literals = + enumType.getLongValues().stream() + .map(name -> String.format("(%s)", name)) + .toList(); + issueGeneralCommand.accept( + String.format( + "(declare-datatypes ((%s 0)) ((%s)))", + enumType.getName(), String.join(" ", literals))); } } } @Override - public LitExpr transformEnumTerm(Function_defContext funcDef, EnumType type, SmtLibModel model) { - final String longName = funcDef.term().qual_identifier().identifier().symbol().getText(); + public LitExpr transformEnumTerm( + Function_defContext funcDef, EnumType type, SmtLibModel model) { + final String longName = + funcDef.term().qual_identifier().identifier().symbol().getText(); return type.litFromLongName(longName); } }, SORTS { @Override - public void declareDatatypes(Collection allTypes, Stack typeStack, Consumer issueGeneralCommand) { + public void declareDatatypes( + Collection allTypes, + Stack typeStack, + Consumer issueGeneralCommand) { List types = new ArrayList<>(allTypes); types.removeAll(typeStack.toCollection()); Set typeSet = new HashSet<>(types); - for (Type t : - typeSet) { + for (Type t : typeSet) { if (t instanceof EnumType enumType) { typeStack.add(enumType); - issueGeneralCommand.accept(String.format("(declare-sort %s 0)", enumType.getName())); - enumType.getLongValues().forEach(literal -> issueGeneralCommand.accept(String.format("(declare-const %s %s)", literal, enumType.getName()))); - issueGeneralCommand.accept(String.format("(assert (distinct %s))", String.join(" ", enumType.getLongValues()))); + issueGeneralCommand.accept( + String.format("(declare-sort %s 0)", enumType.getName())); + enumType.getLongValues() + .forEach( + literal -> + issueGeneralCommand.accept( + String.format( + "(declare-const %s %s)", + literal, enumType.getName()))); + issueGeneralCommand.accept( + String.format( + "(assert (distinct %s))", + String.join(" ", enumType.getLongValues()))); } } } @@ -84,7 +103,12 @@ public String wrapAssertionExpression(String assertion, Map, String var nameOnSolver = constDeclEntry.getValue(); if (constDecl.getType() instanceof EnumType enumType) { sb.append(" (or"); - enumType.getLongValues().forEach(val -> sb.append(String.format(" (= %s %s)", nameOnSolver, val))); + enumType.getLongValues() + .forEach( + val -> + sb.append( + String.format( + " (= %s %s)", nameOnSolver, val))); sb.append(")"); needsWrap = true; } @@ -94,33 +118,38 @@ public String wrapAssertionExpression(String assertion, Map, String } @Override - public LitExpr transformEnumTerm(Function_defContext funcDef, EnumType type, SmtLibModel model) { + public LitExpr transformEnumTerm( + Function_defContext funcDef, EnumType type, SmtLibModel model) { final String id = funcDef.term().qual_identifier().identifier().symbol().getText(); for (var lit : type.getLongValues()) { - if (model.getTerm(lit).contains(id)) - return type.litFromLongName(lit); + if (model.getTerm(lit).contains(id)) return type.litFromLongName(lit); } throw new RuntimeException(); } }; - - public abstract void declareDatatypes(final Collection allTypes, final Stack typeStack, final Consumer issueGeneralCommand); + public abstract void declareDatatypes( + final Collection allTypes, + final Stack typeStack, + final Consumer issueGeneralCommand); /** * Wraps an expression with additional ones if needed. * * @param assertion the expression part that was going to be asserted. (e.g. "(= x 1)") - * @param consts all variables part of the expression + * @param consts all variables part of the expression */ - public String wrapAssertionExpression(final String assertion, final Map, String> consts) { + public String wrapAssertionExpression( + final String assertion, final Map, String> consts) { return assertion; } - public abstract LitExpr transformEnumTerm(final SMTLIBv2Parser.Function_defContext funcDef, final EnumType type, final SmtLibModel model); + public abstract LitExpr transformEnumTerm( + final SMTLIBv2Parser.Function_defContext funcDef, + final EnumType type, + final SmtLibModel model); public static SmtLibEnumStrategy getDefaultStrategy() { return SmtLibEnumStrategy.SORTS; } - } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibItpSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibItpSolver.java index 02faec669d..5cc6d9f4ef 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibItpSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.smtlib.solver; +import static com.google.common.base.Preconditions.*; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; @@ -36,14 +38,11 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; - import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.*; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; public abstract class SmtLibItpSolver implements ItpSolver { @@ -62,21 +61,25 @@ public abstract class SmtLibItpSolver implements ItpS private Valuation model; private SolverStatus status; - public SmtLibItpSolver( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary - ) { - this(symbolTable, transformationManager, termTransformer, solverBinary, SmtLibEnumStrategy.getDefaultStrategy()); + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary) { + this( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + SmtLibEnumStrategy.getDefaultStrategy()); } public SmtLibItpSolver( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary, - final SmtLibEnumStrategy enumStrategy - ) { + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary, + final SmtLibEnumStrategy enumStrategy) { this.symbolTable = symbolTable; this.transformationManager = transformationManager; this.termTransformer = termTransformer; @@ -92,7 +95,6 @@ public SmtLibItpSolver( init(); } - @Override public abstract T createMarker(); @@ -112,21 +114,39 @@ public void add(final ItpMarker marker, final Expr assertion) { final var consts = ExprUtils.getConstants(assertion); consts.removeAll(declarationStack.toCollection()); declarationStack.add(consts); - enumStrategy.declareDatatypes((Collection) consts.stream().map(ConstDecl::getType).toList(), typeStack, this::issueGeneralCommand); + enumStrategy.declareDatatypes( + (Collection) consts.stream().map(ConstDecl::getType).toList(), + typeStack, + this::issueGeneralCommand); final var itpMarker = (T) marker; final var term = transformationManager.toTerm(assertion); - itpMarker.add(assertion, enumStrategy.wrapAssertionExpression(term, ExprUtils.getConstants(assertion).stream().collect(Collectors.toMap(c -> c, symbolTable::getSymbol)))); + itpMarker.add( + assertion, + enumStrategy.wrapAssertionExpression( + term, + ExprUtils.getConstants(assertion).stream() + .collect(Collectors.toMap(c -> c, symbolTable::getSymbol)))); assertions.add(assertion); - add(itpMarker, assertion, consts, enumStrategy.wrapAssertionExpression(term, ExprUtils.getConstants(assertion).stream().collect(Collectors.toMap(c -> c, symbolTable::getSymbol)))); + add( + itpMarker, + assertion, + consts, + enumStrategy.wrapAssertionExpression( + term, + ExprUtils.getConstants(assertion).stream() + .collect(Collectors.toMap(c -> c, symbolTable::getSymbol)))); clearState(); } - protected abstract void add(final T marker, final Expr assertion, - final Set> consts, final String term); + protected abstract void add( + final T marker, + final Expr assertion, + final Set> consts, + final String term); @Override public SolverStatus check() { @@ -209,7 +229,10 @@ private Valuation extractModel() { throw new SmtLibSolverException(res.getReason()); } else if (res.isSpecific()) { final GetModelResponse getModelResponse = res.asSpecific().asGetModelResponse(); - return new SmtLibValuation(symbolTable, transformationManager, termTransformer, + return new SmtLibValuation( + symbolTable, + transformationManager, + termTransformer, getModelResponse.getModel()); } else { throw new AssertionError(); diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolver.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolver.java index 1fd60aa256..d4fba45d1f 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolver.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.smtlib.solver; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; @@ -40,17 +42,14 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; - import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkState; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; public class SmtLibSolver implements UCSolver, Solver { @@ -76,30 +75,44 @@ public class SmtLibSolver implements UCSolver, Solver { public SmtLibSolver( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary, - boolean unsatCoreEnabled - ) { - this(symbolTable, transformationManager, termTransformer, solverBinary, unsatCoreEnabled, SmtLibEnumStrategy.getDefaultStrategy(), "ALL"); + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary, + boolean unsatCoreEnabled) { + this( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + unsatCoreEnabled, + SmtLibEnumStrategy.getDefaultStrategy(), + "ALL"); } public SmtLibSolver( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary, + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary, boolean unsatCoreEnabled, - final SmtLibEnumStrategy enumStrategy - ) { - this(symbolTable, transformationManager, termTransformer, solverBinary, unsatCoreEnabled, enumStrategy, "ALL"); + final SmtLibEnumStrategy enumStrategy) { + this( + symbolTable, + transformationManager, + termTransformer, + solverBinary, + unsatCoreEnabled, + enumStrategy, + "ALL"); } public SmtLibSolver( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibSolverBinary solverBinary, + final SmtLibTermTransformer termTransformer, + final SmtLibSolverBinary solverBinary, boolean unsatCoreEnabled, final SmtLibEnumStrategy enumStrategy, - final String logic - ) { + final String logic) { this.solverBinary = solverBinary; this.symbolTable = symbolTable; this.transformationManager = transformationManager; @@ -125,14 +138,29 @@ public void add(Expr assertion) { } public void add(final Expr assertion, final String term) { - final var consts = ExprUtils.getConstants(assertion).stream().filter(symbolTable::definesConst).collect(Collectors.toSet()); + final var consts = + ExprUtils.getConstants(assertion).stream() + .filter(symbolTable::definesConst) + .collect(Collectors.toSet()); consts.removeAll(declarationStack.toCollection()); declarationStack.add(consts); assertions.add(assertion); - enumStrategy.declareDatatypes(consts.stream().map(ConstDecl::getType).toList(), typeStack, this::issueGeneralCommand); + enumStrategy.declareDatatypes( + consts.stream().map(ConstDecl::getType).toList(), + typeStack, + this::issueGeneralCommand); consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); - issueGeneralCommand(String.format("(assert %s)", enumStrategy.wrapAssertionExpression(term, ExprUtils.getConstants(assertion).stream().filter(symbolTable::definesConst).collect(Collectors.toMap(c -> c, symbolTable::getSymbol))))); + issueGeneralCommand( + String.format( + "(assert %s)", + enumStrategy.wrapAssertionExpression( + term, + ExprUtils.getConstants(assertion).stream() + .filter(symbolTable::definesConst) + .collect( + Collectors.toMap( + c -> c, symbolTable::getSymbol))))); clearState(); } @@ -149,8 +177,18 @@ public void track(Expr assertion) { assertions.add(assertion); consts.stream().map(symbolTable::getDeclaration).forEach(this::issueGeneralCommand); - enumStrategy.declareDatatypes((Collection) consts.stream().map(ConstDecl::getType).toList(), typeStack, this::issueGeneralCommand); - issueGeneralCommand(String.format("(assert (! %s :named %s))", enumStrategy.wrapAssertionExpression(term, ExprUtils.getConstants(assertion).stream().collect(Collectors.toMap(c -> c, symbolTable::getSymbol))), label)); + enumStrategy.declareDatatypes( + (Collection) consts.stream().map(ConstDecl::getType).toList(), + typeStack, + this::issueGeneralCommand); + issueGeneralCommand( + String.format( + "(assert (! %s :named %s))", + enumStrategy.wrapAssertionExpression( + term, + ExprUtils.getConstants(assertion).stream() + .collect(Collectors.toMap(c -> c, symbolTable::getSymbol))), + label)); clearState(); } @@ -230,7 +268,10 @@ private Valuation extractModel() { throw new SmtLibSolverException(res.getReason()); } else if (res.isSpecific()) { final GetModelResponse getModelResponse = res.asSpecific().asGetModelResponse(); - return new SmtLibValuation(symbolTable, transformationManager, termTransformer, + return new SmtLibValuation( + symbolTable, + transformationManager, + termTransformer, getModelResponse.getModel()); } else { throw new AssertionError(); @@ -260,8 +301,8 @@ private Collection> extractUnsatCore() { if (res.isError()) { throw new SmtLibSolverException(res.getReason()); } else if (res.isSpecific()) { - final GetUnsatCoreResponse getUnsatCoreResponse = res.asSpecific() - .asGetUnsatCoreResponse(); + final GetUnsatCoreResponse getUnsatCoreResponse = + res.asSpecific().asGetUnsatCoreResponse(); unsatCoreLabels = getUnsatCoreResponse.getLabels(); } else { throw new AssertionError(); diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolverException.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolverException.java index 3d90c79cae..e4f9ad67c7 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolverException.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/SmtLibSolverException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinary.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinary.java index 9a25731ce9..1a8b8536b5 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinary.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinary.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinaryException.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinaryException.java index dc29f9e20c..b16cd89914 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinaryException.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/binary/SmtLibSolverBinaryException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstaller.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstaller.java index 222508e06b..08174072d7 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstaller.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,11 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.installer; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.logging.Logger; import hu.bme.mit.theta.solver.SolverFactory; - import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -27,9 +29,6 @@ import java.util.Collections; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - public interface SmtLibSolverInstaller { void install(Path home, String version, String name) throws SmtLibSolverInstallerException; @@ -71,8 +70,9 @@ public final void install(final Path home, final String version, final String na } @Override - public final void install(final Path home, final String version, final String name, - final Path solverPath) throws SmtLibSolverInstallerException { + public final void install( + final Path home, final String version, final String name, final Path solverPath) + throws SmtLibSolverInstallerException { checkNotNull(home); checkArgument(Files.exists(home)); checkVersion(version); @@ -82,8 +82,9 @@ public final void install(final Path home, final String version, final String na doInstall(home, version, name, solverPath); } - private void doInstall(final Path home, final String version, final String name, - final Path solverPath) throws SmtLibSolverInstallerException { + private void doInstall( + final Path home, final String version, final String name, final Path solverPath) + throws SmtLibSolverInstallerException { final var installDir = getInstallDir(home, name); if (Files.exists(installDir)) { throw new SmtLibSolverInstallerException( @@ -97,24 +98,30 @@ private void doInstall(final Path home, final String version, final String name, if (solverPath != null) { final var solverFilePath = solverFile(installDir); - Files.writeString(solverFilePath, solverPath.toAbsolutePath().toString(), + Files.writeString( + solverFilePath, + solverPath.toAbsolutePath().toString(), StandardCharsets.UTF_8); } final var solverArgsPath = argsFile(installDir); - Files.writeString(solverArgsPath, String.join("\n", getDefaultSolverArgs(version)), + Files.writeString( + solverArgsPath, + String.join("\n", getDefaultSolverArgs(version)), StandardCharsets.UTF_8); final var solverInfoPath = infoFile(installDir); Files.writeString( solverInfoPath, - String.format("solver=%s\n", getSolverName()) + - String.format("version=%s\n", version) + - String.format("name=%s\n", name) + - (solverPath != null ? String.format("binary=%s\n", - solverPath.toAbsolutePath().toString()) : ""), - StandardCharsets.UTF_8 - ); + String.format("solver=%s\n", getSolverName()) + + String.format("version=%s\n", version) + + String.format("name=%s\n", name) + + (solverPath != null + ? String.format( + "binary=%s\n", + solverPath.toAbsolutePath().toString()) + : ""), + StandardCharsets.UTF_8); if (solverPath == null) { installSolver(installDir, version); @@ -125,8 +132,8 @@ private void doInstall(final Path home, final String version, final String name, uninstall(home, version); throw e; } catch (IOException e) { - throw new SmtLibSolverInstallerException(String.format("Error: %s", e.getMessage()), - e); + throw new SmtLibSolverInstallerException( + String.format("Error: %s", e.getMessage()), e); } } @@ -151,8 +158,8 @@ public final void uninstall(Path home, String version) logger.write(Logger.Level.MAINSTEP, "Uninstallation finished\n"); } catch (IOException e) { - throw new SmtLibSolverInstallerException(String.format("Error: %s", e.getMessage()), - e); + throw new SmtLibSolverInstallerException( + String.format("Error: %s", e.getMessage()), e); } } @@ -191,28 +198,31 @@ public final SolverFactory getSolverFactory(final Path home, final String versio final var installDir = home.resolve(version); if (!Files.exists(installDir)) { - throw new SmtLibSolverInstallerException("The version <" + version - + "> is not installed in <" + home + ">"); + throw new SmtLibSolverInstallerException( + "The version <" + version + "> is not installed in <" + home + ">"); } try { final Path solverPath; final var solverFilePath = solverFile(installDir); if (Files.exists(solverFilePath)) { - solverPath = Path.of( - Files.readAllLines(solverFilePath, StandardCharsets.UTF_8).get(0)); + solverPath = + Path.of( + Files.readAllLines(solverFilePath, StandardCharsets.UTF_8) + .get(0)); } else { solverPath = null; } final var solverArgsPath = argsFile(installDir); - final var solverArgs = Files.readAllLines(solverArgsPath, StandardCharsets.UTF_8) - .toArray(String[]::new); + final var solverArgs = + Files.readAllLines(solverArgsPath, StandardCharsets.UTF_8) + .toArray(String[]::new); return getSolverFactory(installDir, version, solverPath, solverArgs); } catch (IOException e) { - throw new SmtLibSolverInstallerException(String.format("Error: %s", e.getMessage()), - e); + throw new SmtLibSolverInstallerException( + String.format("Error: %s", e.getMessage()), e); } } @@ -232,13 +242,14 @@ public final String getInfo(Path home, String version) final var solverInfoPath = infoFile(installDir); final var solverInfoStr = Files.readString(solverInfoPath, StandardCharsets.UTF_8); final var solverArgsPath = argsFile(installDir); - final var solverArgs = Files.readAllLines(solverArgsPath, StandardCharsets.UTF_8) - .toArray(String[]::new); + final var solverArgs = + Files.readAllLines(solverArgsPath, StandardCharsets.UTF_8) + .toArray(String[]::new); return solverInfoStr + String.format("args=%s\n", String.join(" ", solverArgs)); } catch (IOException e) { - throw new SmtLibSolverInstallerException(String.format("Error: %s", e.getMessage()), - e); + throw new SmtLibSolverInstallerException( + String.format("Error: %s", e.getMessage()), e); } } @@ -262,8 +273,9 @@ public final List getInstalledVersions(Path home) { checkNotNull(home); if (Files.exists(home)) { - final var installedDirs = home.toFile() - .list((current, name) -> new File(current, name).isDirectory()); + final var installedDirs = + home.toFile() + .list((current, name) -> new File(current, name).isDirectory()); assert installedDirs != null; return Arrays.asList(installedDirs); @@ -280,8 +292,11 @@ protected abstract void installSolver(final Path installDir, final String versio protected abstract void uninstallSolver(final Path installDir, final String version) throws SmtLibSolverInstallerException; - protected abstract SolverFactory getSolverFactory(final Path installDir, - final String version, final Path solverPath, final String[] args) + protected abstract SolverFactory getSolverFactory( + final Path installDir, + final String version, + final Path solverPath, + final String[] args) throws SmtLibSolverInstallerException; protected abstract String[] getDefaultSolverArgs(final String version) diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstallerException.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstallerException.java index 6a2511efa9..6de071cd58 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstallerException.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/installer/SmtLibSolverInstallerException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibInterpolant.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibInterpolant.java index 93523955d2..5d269ce111 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibInterpolant.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibInterpolant.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.interpolation; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Interpolant; import hu.bme.mit.theta.solver.ItpMarker; - import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; - public class SmtLibInterpolant implements Interpolant { private final Map> itpMap; @@ -39,5 +38,4 @@ public Expr eval(final ItpMarker marker) { checkNotNull(itpExpr); return itpExpr; } - } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpMarker.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpMarker.java index 54c21663bb..daed4f7b75 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpMarker.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.interpolation; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - public class SmtLibItpMarker implements ItpMarker { private final Stack, String>> terms; diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpPattern.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpPattern.java index 93587e081c..4baf7c604f 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpPattern.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/interpolation/SmtLibItpPattern.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.interpolation; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.Lists; import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.ItpMarkerTree; import hu.bme.mit.theta.solver.ItpPattern; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - -public class SmtLibItpPattern implements ItpPattern.Binary, - ItpPattern.Sequence, ItpPattern.Tree { +public class SmtLibItpPattern + implements ItpPattern.Binary, ItpPattern.Sequence, ItpPattern.Tree { final ItpMarkerTree markerTree; @@ -89,11 +88,10 @@ public E visit(ItpPatternVisitor visitor) { } private boolean isBinary() { - return - markerTree != null && - markerTree.getChildrenNumber() == 1 && - markerTree.getChild(0) != null && - markerTree.getChild(0).getChildrenNumber() == 0; + return markerTree != null + && markerTree.getChildrenNumber() == 1 + && markerTree.getChild(0) != null + && markerTree.getChild(0).getChildrenNumber() == 0; } private boolean isSequence() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibModel.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibModel.java index eeaa51d79e..23271cf046 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibModel.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibValuation.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibValuation.java index 0f88e2d4ff..395bfec84b 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibValuation.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/model/SmtLibValuation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.model; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.Decl; @@ -27,11 +29,8 @@ import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibSymbolTable; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; - import java.util.*; -import static com.google.common.base.Preconditions.checkNotNull; - public final class SmtLibValuation extends Valuation { private final SmtLibSymbolTable symbolTable; @@ -45,8 +44,8 @@ public final class SmtLibValuation extends Valuation { public SmtLibValuation( final SmtLibSymbolTable symbolTable, final SmtLibTransformationManager transformationManager, - final SmtLibTermTransformer termTransformer, final SmtLibModel model - ) { + final SmtLibTermTransformer termTransformer, + final SmtLibModel model) { this.symbolTable = symbolTable; this.transformationManager = transformationManager; this.termTransformer = termTransformer; @@ -82,7 +81,8 @@ public Optional> eval(Decl d } } - @SuppressWarnings("unchecked") final LitExpr tVal = (LitExpr) val; + @SuppressWarnings("unchecked") + final LitExpr tVal = (LitExpr) val; return Optional.ofNullable(tVal); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/CheckSatResponse.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/CheckSatResponse.java index 84ea04906d..ec972f8b87 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/CheckSatResponse.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/CheckSatResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,19 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.parser; -import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Check_sat_responseContext; -import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolverException; - import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.PS_Sat; import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.PS_Unknown; import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.PS_Unsat; +import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Check_sat_responseContext; +import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolverException; + public class CheckSatResponse extends SpecificResponse { private enum Status { - SAT, UNSAT, UNKNOWN + SAT, + UNSAT, + UNKNOWN } private final Status status; @@ -44,7 +46,6 @@ public static CheckSatResponse fromContext(final Check_sat_responseContext ctx) return new CheckSatResponse(Status.UNKNOWN); default: throw new SmtLibSolverException("Invalid interface"); - } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GeneralResponse.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GeneralResponse.java index a771fbb75e..aae88fd8b7 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GeneralResponse.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GeneralResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.parser; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2BaseVisitor; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.General_response_errorContext; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.General_response_successContext; @@ -22,8 +24,6 @@ import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.ResponseContext; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Specific_success_responseContext; -import static com.google.common.base.Preconditions.checkState; - public class GeneralResponse { private final boolean successful; @@ -37,30 +37,32 @@ private GeneralResponse(boolean successful, String reason, SpecificResponse spec } public static GeneralResponse fromContext(final ResponseContext ctx) { - return ctx.accept(new SMTLIBv2BaseVisitor<>() { - @Override - public GeneralResponse visitGeneral_response_success( - General_response_successContext ctx) { - return new GeneralResponse(true, null, null); - } + return ctx.accept( + new SMTLIBv2BaseVisitor<>() { + @Override + public GeneralResponse visitGeneral_response_success( + General_response_successContext ctx) { + return new GeneralResponse(true, null, null); + } - @Override - public GeneralResponse visitGeneral_response_unsupported( - General_response_unsupportedContext ctx) { - return new GeneralResponse(false, "Unsupported", null); - } + @Override + public GeneralResponse visitGeneral_response_unsupported( + General_response_unsupportedContext ctx) { + return new GeneralResponse(false, "Unsupported", null); + } - @Override - public GeneralResponse visitSpecific_success_response( - Specific_success_responseContext ctx) { - return new GeneralResponse(true, null, SpecificResponse.fromContext(ctx)); - } + @Override + public GeneralResponse visitSpecific_success_response( + Specific_success_responseContext ctx) { + return new GeneralResponse(true, null, SpecificResponse.fromContext(ctx)); + } - @Override - public GeneralResponse visitGeneral_response_error(General_response_errorContext ctx) { - return new GeneralResponse(false, ctx.reason.getText(), null); - } - }); + @Override + public GeneralResponse visitGeneral_response_error( + General_response_errorContext ctx) { + return new GeneralResponse(false, ctx.reason.getText(), null); + } + }); } public boolean isSuccessful() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetModelResponse.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetModelResponse.java index d7f8d76d62..79d831a281 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetModelResponse.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetModelResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,21 +15,20 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.parser; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Get_model_responseContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_funContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_fun_recContext; +import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_funs_recContext; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2BaseVisitor; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_mathsatContext; import hu.bme.mit.theta.solver.smtlib.solver.model.SmtLibModel; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.misc.Interval; - import java.util.Collections; import java.util.Map; import java.util.stream.Collectors; - -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Get_model_responseContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_funContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_fun_recContext; -import static hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Model_response_funs_recContext; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; public class GetModelResponse extends SpecificResponse { @@ -40,38 +39,56 @@ private GetModelResponse(final Map values) { } public static GetModelResponse fromContext(final Get_model_responseContext ctx) { - return new GetModelResponse(ctx.model_response().stream() - .map(member -> member.accept(new SMTLIBv2BaseVisitor>() { - @Override - public Tuple2 visitModel_response_fun( - Model_response_funContext ctx) { - return Tuple2.of(extractString(ctx.function_def().symbol()), - extractString(ctx.function_def())); - } + return new GetModelResponse( + ctx.model_response().stream() + .map( + member -> + member.accept( + new SMTLIBv2BaseVisitor>() { + @Override + public Tuple2 + visitModel_response_fun( + Model_response_funContext ctx) { + return Tuple2.of( + extractString( + ctx.function_def() + .symbol()), + extractString(ctx.function_def())); + } - @Override - public Tuple2 visitModel_response_mathsat( - Model_response_mathsatContext ctx) { - final var functionDef = String.format( - "%s () (_ theta_type unknown) %s", - extractString(ctx.symbol()), - extractString(ctx.term()) - ); - return Tuple2.of(extractString(ctx.symbol()), functionDef); - } + @Override + public Tuple2 + visitModel_response_mathsat( + Model_response_mathsatContext + ctx) { + final var functionDef = + String.format( + "%s () (_ theta_type" + + " unknown) %s", + extractString(ctx.symbol()), + extractString(ctx.term())); + return Tuple2.of( + extractString(ctx.symbol()), + functionDef); + } - @Override - public Tuple2 visitModel_response_fun_rec( - Model_response_fun_recContext ctx) { - throw new UnsupportedOperationException(); - } + @Override + public Tuple2 + visitModel_response_fun_rec( + Model_response_fun_recContext + ctx) { + throw new UnsupportedOperationException(); + } - @Override - public Tuple2 visitModel_response_funs_rec( - Model_response_funs_recContext ctx) { - throw new UnsupportedOperationException(); - } - })).collect(Collectors.toUnmodifiableMap(Tuple2::get1, Tuple2::get2))); + @Override + public Tuple2 + visitModel_response_funs_rec( + Model_response_funs_recContext + ctx) { + throw new UnsupportedOperationException(); + } + })) + .collect(Collectors.toUnmodifiableMap(Tuple2::get1, Tuple2::get2))); } public static GetModelResponse empty() { @@ -83,7 +100,8 @@ public SmtLibModel getModel() { } public static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetProofResponse.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetProofResponse.java index 67643c6779..f416cd203a 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetProofResponse.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetProofResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,19 +19,21 @@ import hu.bme.mit.theta.common.Tuple3; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Proof_responseContext; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.SortContext; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.misc.Interval; - import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; public class GetProofResponse extends SpecificResponse { private final String proofTerm; - private final Map, SortContext, String>> funDeclarations; // name -> [inSorts, outSort, declaration] + private final Map, SortContext, String>> + funDeclarations; // name -> [inSorts, outSort, declaration] - private GetProofResponse(String proofNode, Map, SortContext, String>> funDeclarations) { + private GetProofResponse( + String proofNode, + Map, SortContext, String>> funDeclarations) { this.proofTerm = proofNode; this.funDeclarations = funDeclarations; } @@ -39,17 +41,18 @@ private GetProofResponse(String proofNode, Map, public static GetProofResponse fromContext(final Proof_responseContext ctx) { return new GetProofResponse( extractString(ctx.proof_term().term()), - ctx.proof_funs().stream().map(it -> Tuple2.of( - extractString(it.symbol()), - Tuple3.of( - it.in, - it.out, - extractString(it) - ))).collect(Collectors.toMap(Tuple2::get1, Tuple2::get2))); + ctx.proof_funs().stream() + .map( + it -> + Tuple2.of( + extractString(it.symbol()), + Tuple3.of(it.in, it.out, extractString(it)))) + .collect(Collectors.toMap(Tuple2::get1, Tuple2::get2))); } public static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetUnsatCoreResponse.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetUnsatCoreResponse.java index 95e001e707..c468651331 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetUnsatCoreResponse.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/GetUnsatCoreResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,11 +16,10 @@ package hu.bme.mit.theta.solver.smtlib.solver.parser; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Get_unsat_core_responseContext; -import org.antlr.v4.runtime.RuleContext; - import java.util.Collection; import java.util.Collections; import java.util.stream.Collectors; +import org.antlr.v4.runtime.RuleContext; public class GetUnsatCoreResponse extends SpecificResponse { @@ -32,8 +31,9 @@ private GetUnsatCoreResponse(Collection labels) { public static GetUnsatCoreResponse fromContext(Get_unsat_core_responseContext ctx) { return new GetUnsatCoreResponse( - ctx.symbol().stream().map(RuleContext::getText).collect(Collectors.toUnmodifiableSet()) - ); + ctx.symbol().stream() + .map(RuleContext::getText) + .collect(Collectors.toUnmodifiableSet())); } public static GetUnsatCoreResponse empty() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/SpecificResponse.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/SpecificResponse.java index b7cbff1b58..d2d37ea5c7 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/SpecificResponse.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/SpecificResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,40 +15,41 @@ */ package hu.bme.mit.theta.solver.smtlib.solver.parser; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2BaseVisitor; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Proof_responseContext; import hu.bme.mit.theta.solver.smtlib.dsl.gen.SMTLIBv2Parser.Specific_success_responseContext; -import static com.google.common.base.Preconditions.checkState; - public abstract class SpecificResponse { static SpecificResponse fromContext(final Specific_success_responseContext ctx) { - return ctx.accept(new SMTLIBv2BaseVisitor<>() { - @Override - public SpecificResponse visitCheck_sat_response( - SMTLIBv2Parser.Check_sat_responseContext ctx) { - return CheckSatResponse.fromContext(ctx); - } + return ctx.accept( + new SMTLIBv2BaseVisitor<>() { + @Override + public SpecificResponse visitCheck_sat_response( + SMTLIBv2Parser.Check_sat_responseContext ctx) { + return CheckSatResponse.fromContext(ctx); + } - @Override - public SpecificResponse visitGet_unsat_core_response( - SMTLIBv2Parser.Get_unsat_core_responseContext ctx) { - return GetUnsatCoreResponse.fromContext(ctx); - } + @Override + public SpecificResponse visitGet_unsat_core_response( + SMTLIBv2Parser.Get_unsat_core_responseContext ctx) { + return GetUnsatCoreResponse.fromContext(ctx); + } - @Override - public SpecificResponse visitGet_model_response( - SMTLIBv2Parser.Get_model_responseContext ctx) { - return GetModelResponse.fromContext(ctx); - } + @Override + public SpecificResponse visitGet_model_response( + SMTLIBv2Parser.Get_model_responseContext ctx) { + return GetModelResponse.fromContext(ctx); + } - @Override - public SpecificResponse visitProof_response(Proof_responseContext ctx) { - return GetProofResponse.fromContext(ctx); - } - }); + @Override + public SpecificResponse visitProof_response(Proof_responseContext ctx) { + return GetProofResponse.fromContext(ctx); + } + }); } public boolean isCheckSatResponse() { @@ -56,17 +57,15 @@ public boolean isCheckSatResponse() { } public boolean isGetUnsatCoreResponse() { - return - this instanceof GetUnsatCoreResponse || - this instanceof GetModelResponse - && ((GetModelResponse) this).getModel().size() == 0; + return this instanceof GetUnsatCoreResponse + || this instanceof GetModelResponse + && ((GetModelResponse) this).getModel().size() == 0; } public boolean isGetModelResponse() { - return - this instanceof GetModelResponse || - this instanceof GetUnsatCoreResponse - && ((GetUnsatCoreResponse) this).getLabels().size() == 0; + return this instanceof GetModelResponse + || this instanceof GetUnsatCoreResponse + && ((GetUnsatCoreResponse) this).getLabels().size() == 0; } public boolean isGetProofResponse() { diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/ThrowExceptionErrorListener.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/ThrowExceptionErrorListener.java index 50d57b484d..57fe97e4d7 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/ThrowExceptionErrorListener.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/parser/ThrowExceptionErrorListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,8 +24,13 @@ public class ThrowExceptionErrorListener extends BaseErrorListener implements ANTLRErrorListener { @Override - public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, - int charPositionInLine, String msg, RecognitionException e) { + public void syntaxError( + Recognizer recognizer, + Object offendingSymbol, + int line, + int charPositionInLine, + String msg, + RecognitionException e) { throw new SmtLibSolverException(String.format("Invalid Expression: %s", msg), e); } -} \ No newline at end of file +} diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibDeclTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibDeclTransformer.java index c43114d1a3..0ec4fba540 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibDeclTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibDeclTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibExprTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibExprTransformer.java index 8abb52349d..5a5cdc60d5 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibExprTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibSymbolTable.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibSymbolTable.java index 32d122c6a0..4f7113f996 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibSymbolTable.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibSymbolTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTermTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTermTransformer.java index 0836d29006..d2f96135ec 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTermTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTermTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,15 +25,15 @@ public interface SmtLibTermTransformer { -

LitExpr> toFuncLitExpr(String funcLitImpl, - FuncType type, SmtLibModel model); +

LitExpr> toFuncLitExpr( + String funcLitImpl, FuncType type, SmtLibModel model); Expr toExpr(String term, T type, SmtLibModel model); LitExpr toLitExpr(String litImpl, T type, SmtLibModel model); - LitExpr> toArrayLitExpr(String arrayLitImpl, - ArrayType type, SmtLibModel model); + LitExpr> toArrayLitExpr( + String arrayLitImpl, ArrayType type, SmtLibModel model); LitExpr toBvLitExpr(String bvLitImpl, BvType type, SmtLibModel model); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTransformationManager.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTransformationManager.java index b4dced7f43..7cf43ea1e3 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTransformationManager.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTransformationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTypeTransformer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTypeTransformer.java index 505e56b0bf..5bd75e818c 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTypeTransformer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/solver/transformer/SmtLibTypeTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/Compress.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/Compress.java index bb385b9caf..b152c50c4b 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/Compress.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/Compress.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.solver.smtlib.utils; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -22,64 +27,83 @@ import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; - public class Compress { - private Compress() { - } + private Compress() {} public enum CompressionType { - ZIP, TARGZ, TARBZ2 + ZIP, + TARGZ, + TARBZ2 } - public static void extract(final InputStream inputStream, final Path extractDir, final CompressionType compressionType) throws IOException { + public static void extract( + final InputStream inputStream, + final Path extractDir, + final CompressionType compressionType) + throws IOException { extract(inputStream, extractDir, compressionType, false); } - public static void extractTarbomb(final InputStream inputStream, final Path extractDir, final CompressionType compressionType) throws IOException { + public static void extractTarbomb( + final InputStream inputStream, + final Path extractDir, + final CompressionType compressionType) + throws IOException { extract(inputStream, extractDir, compressionType, true); } - private static void extract(final InputStream inputStream, final Path extractDir, - final CompressionType compressionType, final boolean tarbomb) throws IOException { + private static void extract( + final InputStream inputStream, + final Path extractDir, + final CompressionType compressionType, + final boolean tarbomb) + throws IOException { switch (compressionType) { case ZIP: extract(new ZipArchiveInputStream(inputStream), extractDir, tarbomb); break; case TARGZ: - extract(new TarArchiveInputStream( - new GzipCompressorInputStream(new BufferedInputStream(inputStream))), - extractDir, tarbomb); + extract( + new TarArchiveInputStream( + new GzipCompressorInputStream( + new BufferedInputStream(inputStream))), + extractDir, + tarbomb); break; case TARBZ2: - extract(new TarArchiveInputStream( - new BZip2CompressorInputStream(new BufferedInputStream(inputStream))), - extractDir, tarbomb); + extract( + new TarArchiveInputStream( + new BZip2CompressorInputStream( + new BufferedInputStream(inputStream))), + extractDir, + tarbomb); break; default: throw new AssertionError(); } } - private static void extract(final ArchiveInputStream archiveInputStream, final Path extractDir, final boolean tarbomb) + private static void extract( + final ArchiveInputStream archiveInputStream, + final Path extractDir, + final boolean tarbomb) throws IOException { - for (ArchiveEntry entry = archiveInputStream.getNextEntry(); entry != null; - entry = archiveInputStream.getNextEntry()) { + for (ArchiveEntry entry = archiveInputStream.getNextEntry(); + entry != null; + entry = archiveInputStream.getNextEntry()) { final var entryPath = Path.of(entry.getName()); if (entry.isDirectory()) { if (entryPath.getNameCount() > 1) { - final var entryResolvedPath = extractDir.resolve( - entryPath.subpath(tarbomb ? 0 : 1, entryPath.getNameCount())); + final var entryResolvedPath = + extractDir.resolve( + entryPath.subpath(tarbomb ? 0 : 1, entryPath.getNameCount())); Files.createDirectories(entryResolvedPath); } } else { - final var entryResolvedPath = extractDir.resolve( - entryPath.subpath(tarbomb ? 0 : 1, entryPath.getNameCount())); + final var entryResolvedPath = + extractDir.resolve( + entryPath.subpath(tarbomb ? 0 : 1, entryPath.getNameCount())); Files.createDirectories(entryResolvedPath.getParent()); Files.copy(archiveInputStream, entryResolvedPath); } diff --git a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/SemVer.java b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/SemVer.java index 563b0799e9..50f9d79564 100644 --- a/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/SemVer.java +++ b/subprojects/solver/solver-smtlib/src/main/java/hu/bme/mit/theta/solver/smtlib/utils/SemVer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.solver.smtlib.utils; -import hu.bme.mit.theta.common.OsHelper; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import hu.bme.mit.theta.common.OsHelper; import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - public class SemVer implements Comparable { private final int[] version; @@ -109,8 +108,9 @@ public static class VersionDecoder { private final SemVer version; private final Map> string; - private VersionDecoder(final SemVer version, - final Map> string) { + private VersionDecoder( + final SemVer version, + final Map> string) { this.version = version; this.string = string; } @@ -123,14 +123,15 @@ public SemVer getVersion() { return version; } - public String getOsArchString(final OsHelper.OperatingSystem os, - final OsHelper.Architecture arch) { + public String getOsArchString( + final OsHelper.OperatingSystem os, final OsHelper.Architecture arch) { if (!string.containsKey(os)) { throw new UnsupportedOperationException( String.format("Operating system %s is not supported by z3", os)); } else if (!string.get(os).containsKey(arch)) { throw new UnsupportedOperationException( - String.format("Architecture %s on operating system %s is not supported by z3", + String.format( + "Architecture %s on operating system %s is not supported by z3", arch, os)); } else { return string.get(os).get(arch); @@ -147,8 +148,10 @@ private Builder(final SemVer version) { this.string = new HashMap<>(); } - public VersionDecoder.Builder addString(final OsHelper.OperatingSystem os, - final OsHelper.Architecture arch, final String string) { + public VersionDecoder.Builder addString( + final OsHelper.OperatingSystem os, + final OsHelper.Architecture arch, + final String string) { if (!this.string.containsKey(os)) { this.string.put(os, new HashMap<>()); } 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 8f416abf73..120e8874d5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibItpSolverTest.java b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibItpSolverTest.java index 0165b54878..7061945ec5 100644 --- a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibItpSolverTest.java +++ b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibItpSolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,23 @@ */ package hu.bme.mit.theta.solver.smtlib; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Neq; +import static hu.bme.mit.theta.solver.ItpMarkerTree.Leaf; +import static hu.bme.mit.theta.solver.ItpMarkerTree.Subtree; +import static hu.bme.mit.theta.solver.ItpMarkerTree.Tree; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.NullLogger; @@ -32,6 +49,8 @@ import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; +import java.io.IOException; +import java.nio.file.Path; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Assume; @@ -39,26 +58,6 @@ import org.junit.BeforeClass; import org.junit.Test; -import java.io.IOException; -import java.nio.file.Path; - -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Neq; -import static hu.bme.mit.theta.solver.ItpMarkerTree.Leaf; -import static hu.bme.mit.theta.solver.ItpMarkerTree.Subtree; -import static hu.bme.mit.theta.solver.ItpMarkerTree.Tree; - public final class SmtLibItpSolverTest { private static boolean solverInstalled = false; @@ -178,8 +177,8 @@ public void testTreeInterpolation() { final ItpMarker I3 = solver.createMarker(); final ItpMarker I4 = solver.createMarker(); final ItpMarker I5 = solver.createMarker(); - final ItpPattern pattern = solver.createTreePattern( - Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); + final ItpPattern pattern = + solver.createTreePattern(Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); solver.add(I1, Eq(a, Int(0))); solver.add(I2, Eq(a, b)); @@ -290,5 +289,4 @@ public void testPushPop() { System.out.println(itp.eval(A)); System.out.println("----------"); } - } diff --git a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibParserTest.java b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibParserTest.java index bb9f0fda86..c6bc4a083a 100644 --- a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibParserTest.java +++ b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,13 +23,12 @@ import hu.bme.mit.theta.solver.smtlib.solver.model.SmtLibModel; import hu.bme.mit.theta.solver.smtlib.solver.parser.GeneralResponse; import hu.bme.mit.theta.solver.smtlib.solver.parser.ThrowExceptionErrorListener; +import java.util.Map; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import org.junit.Assert; import org.junit.Test; -import java.util.Map; - public class SmtLibParserTest { @Test @@ -56,11 +55,12 @@ public void ambiguousParsingTest() { @Test public void letTest() { - final var response = "" + - "(let ((a!1 (* (mod 15 4294967296)\n" + - " (mod (+ 1 (mod 15 4294967296)) 4294967296))))\n" + - "(let ((a!2 (* (- 1) (mod (div (mod a!1 4294967296) 2) 4294967296))))\n" + - " (= (+ 16 a!2) 0)))"; + final var response = + "" + + "(let ((a!1 (* (mod 15 4294967296)\n" + + " (mod (+ 1 (mod 15 4294967296)) 4294967296))))\n" + + "(let ((a!2 (* (- 1) (mod (div (mod a!1 4294967296) 2) 4294967296))))\n" + + " (= (+ 16 a!2) 0)))"; final var lexer = new SMTLIBv2Lexer(CharStreams.fromString(response)); final var parser = new SMTLIBv2Parser(new CommonTokenStream(lexer)); @@ -71,8 +71,8 @@ public void letTest() { final var symbolTable = new GenericSmtLibSymbolTable(); final var termTransformer = new GenericSmtLibTermTransformer(symbolTable); - final var expr = termTransformer.toExpr(response, BoolExprs.Bool(), - new SmtLibModel(Map.of())); + final var expr = + termTransformer.toExpr(response, BoolExprs.Bool(), new SmtLibModel(Map.of())); Assert.assertNotNull(expr); } diff --git a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverBVTest.java b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverBVTest.java index ea4bf9ae3b..cb09097aaf 100644 --- a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverBVTest.java +++ b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverBVTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.solver.smtlib; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.NullLogger; import hu.bme.mit.theta.core.type.Expr; @@ -23,6 +28,11 @@ import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.AfterClass; import org.junit.Assume; import org.junit.BeforeClass; @@ -30,17 +40,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collection; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class SmtLibSolverBVTest { @@ -82,12 +81,11 @@ public static void destroy() throws SmtLibSolverInstallerException { @Parameters(name = "expr: {0}, expected: {1}, actual: {2}") public static Collection operations() { return Stream.concat( - BvTestUtils.BasicOperations().stream(), - Stream.concat( - BvTestUtils.BitvectorOperations().stream(), - BvTestUtils.RelationalOperations().stream() - ) - ).collect(Collectors.toUnmodifiableList()); + BvTestUtils.BasicOperations().stream(), + Stream.concat( + BvTestUtils.BitvectorOperations().stream(), + BvTestUtils.RelationalOperations().stream())) + .collect(Collectors.toUnmodifiableList()); } @Test @@ -101,16 +99,19 @@ public void testOperationEquals() throws Exception { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check try (final Solver solver = solverManager.getSolverFactory(SOLVER, VERSION).createSolver()) { diff --git a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverFPTest.java b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverFPTest.java index 42cc151d14..63fb538c89 100644 --- a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverFPTest.java +++ b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverFPTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,16 @@ */ package hu.bme.mit.theta.solver.smtlib; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.NullLogger; import hu.bme.mit.theta.core.type.Expr; @@ -27,6 +37,10 @@ import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collection; +import java.util.stream.Collectors; import org.junit.AfterClass; import org.junit.Assume; import org.junit.BeforeClass; @@ -35,21 +49,6 @@ import org.junit.runners.Parameterized; import org.kframework.mpfr.BigFloat; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collection; -import java.util.stream.Collectors; - -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class SmtLibSolverFPTest { @@ -105,16 +104,19 @@ public void testOperationEquals() throws Exception { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check try (final Solver solver = solverManager.getSolverFactory(SOLVER, VERSION).createSolver()) { @@ -130,10 +132,15 @@ public void testOperationEquals() throws Exception { solver.add(EqExpr.create2(expected, actual)); } else { //noinspection unchecked - FpLeqExpr leq = Leq(Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), - FpUtils.bigFloatToFpLitExpr(new BigFloat("1e-2", - FpUtils.getMathContext((FpType) actual.getType(), RNE)), - (FpType) actual.getType())); + FpLeqExpr leq = + Leq( + Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), + FpUtils.bigFloatToFpLitExpr( + new BigFloat( + "1e-2", + FpUtils.getMathContext( + (FpType) actual.getType(), RNE)), + (FpType) actual.getType())); solver.add(leq); } } else { diff --git a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverTest.java b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverTest.java index 84d57bdba3..42a62bf049 100644 --- a/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverTest.java +++ b/subprojects/solver/solver-smtlib/src/test/java/hu/bme/mit/theta/solver/smtlib/SmtLibSolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,18 @@ */ package hu.bme.mit.theta.solver.smtlib; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import hu.bme.mit.theta.common.OsHelper; import hu.bme.mit.theta.common.logging.NullLogger; import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; @@ -31,7 +39,6 @@ import hu.bme.mit.theta.core.type.booltype.ForallExpr; import hu.bme.mit.theta.core.type.bvtype.BvExprs; import hu.bme.mit.theta.core.type.bvtype.BvType; -import hu.bme.mit.theta.core.type.functype.FuncType; import hu.bme.mit.theta.core.type.inttype.IntExprs; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.Solver; @@ -42,30 +49,16 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.installer.SmtLibSolverInstallerException; import hu.bme.mit.theta.solver.smtlib.solver.model.SmtLibModel; -import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - import java.io.IOException; import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.Optional; - -import static com.google.common.collect.ImmutableList.of; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.junit.AfterClass; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; public final class SmtLibSolverTest { private static boolean solverInstalled = false; @@ -110,13 +103,16 @@ public void test() { final var x = Const("x", BvExprs.BvType(4)); symbolTable.put(x, "x", "(declare-fun x () (_ BitVec 4))"); - final var expr = termTransformer.toExpr( - "(forall ((y (Array (_ BitVec 4) Int))) (= (select y x) 0))", - BoolExprs.Bool(), new SmtLibModel(Map.of()) - ); + final var expr = + termTransformer.toExpr( + "(forall ((y (Array (_ BitVec 4) Int))) (= (select y x) 0))", + BoolExprs.Bool(), + new SmtLibModel(Map.of())); assertNotNull(expr); assertTrue(expr instanceof ForallExpr); - assertEquals(Array(x.getType(), IntExprs.Int()), ((ForallExpr) expr).getParamDecls().get(0).getType()); + assertEquals( + Array(x.getType(), IntExprs.Int()), + ((ForallExpr) expr).getParamDecls().get(0).getType()); } @Test @@ -210,37 +206,43 @@ public void testModel() { assertEquals(BoolExprs.Bool(true), model.eval(u).orElseThrow()); } -// @Test -// public void testFunc() { -// // Arrange -// final Solver solver = solverFactory.createSolver(); -// final ConstDecl> ca = Const("a", Func(IntExprs.Int(), IntExprs.Int())); -// final Expr> a = ca.getRef(); -// final ParamDecl px = Param("x", IntExprs.Int()); -// final Expr x = px.getRef(); -// -// solver.add(BoolExprs.Forall(of(px), BoolExprs.Imply(IntExprs.Leq(x, IntExprs.Int(0)), IntExprs.Eq(App(a, x), IntExprs.Int(0))))); -// solver.add(BoolExprs.Forall(of(px), BoolExprs.Imply(IntExprs.Geq(x, IntExprs.Int(1)), IntExprs.Eq(App(a, x), IntExprs.Int(1))))); -// -// // Act -// final SolverStatus status = solver.check(); -// assertTrue(status.isSat()); -// final Valuation model = solver.getModel(); -// final Optional>> optVal = model.eval(ca); -// final Expr> val = optVal.get(); -// -// // Assert -// assertEquals(ca.getType(), val.getType()); -// } + // @Test + // public void testFunc() { + // // Arrange + // final Solver solver = solverFactory.createSolver(); + // final ConstDecl> ca = Const("a", Func(IntExprs.Int(), + // IntExprs.Int())); + // final Expr> a = ca.getRef(); + // final ParamDecl px = Param("x", IntExprs.Int()); + // final Expr x = px.getRef(); + // + // solver.add(BoolExprs.Forall(of(px), BoolExprs.Imply(IntExprs.Leq(x, IntExprs.Int(0)), + // IntExprs.Eq(App(a, x), IntExprs.Int(0))))); + // solver.add(BoolExprs.Forall(of(px), BoolExprs.Imply(IntExprs.Geq(x, IntExprs.Int(1)), + // IntExprs.Eq(App(a, x), IntExprs.Int(1))))); + // + // // Act + // final SolverStatus status = solver.check(); + // assertTrue(status.isSat()); + // final Valuation model = solver.getModel(); + // final Optional>> optVal = model.eval(ca); + // final Expr> val = optVal.get(); + // + // // Assert + // assertEquals(ca.getType(), val.getType()); + // } @Test public void testArray() { final Solver solver = solverFactory.createSolver(); - final ConstDecl> arr = Const("arr", Array(IntExprs.Int(), IntExprs.Int())); + final ConstDecl> arr = + Const("arr", Array(IntExprs.Int(), IntExprs.Int())); - solver.add(ArrayExprs.Eq(Write(arr.getRef(), IntExprs.Int(0), IntExprs.Int(1)), arr.getRef())); - solver.add(ArrayExprs.Eq(Write(arr.getRef(), IntExprs.Int(1), IntExprs.Int(2)), arr.getRef())); + solver.add( + ArrayExprs.Eq(Write(arr.getRef(), IntExprs.Int(0), IntExprs.Int(1)), arr.getRef())); + solver.add( + ArrayExprs.Eq(Write(arr.getRef(), IntExprs.Int(1), IntExprs.Int(2)), arr.getRef())); // Check, the expression should be satisfiable SolverStatus status = solver.check(); @@ -252,8 +254,10 @@ public void testArray() { assertTrue(val instanceof ArrayLitExpr); var valLit = (ArrayLitExpr) val; assertTrue(2 <= valLit.getElements().size()); - assertEquals(IntExprs.Int(1), Read(valLit, IntExprs.Int(0)).eval(ImmutableValuation.empty())); - assertEquals(IntExprs.Int(2), Read(valLit, IntExprs.Int(1)).eval(ImmutableValuation.empty())); + assertEquals( + IntExprs.Int(1), Read(valLit, IntExprs.Int(0)).eval(ImmutableValuation.empty())); + assertEquals( + IntExprs.Int(2), Read(valLit, IntExprs.Int(1)).eval(ImmutableValuation.empty())); } @Test @@ -265,8 +269,8 @@ public void testBV1() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cx.getRef(), cy.getRef())); SolverStatus status = solver.check(); @@ -284,7 +288,7 @@ public void testBV2() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); solver.add(BvExprs.Neq(cx.getRef(), cz.getRef())); SolverStatus status = solver.check(); @@ -306,8 +310,14 @@ public void testBV3() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); - solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Add(List.of(cx.getRef(), Bv(new boolean[]{false, false, false, true}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Add( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, false, true}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -328,8 +338,11 @@ public void testBV4() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Sub(cx.getRef(), Bv(new boolean[]{false, false, false, true})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Sub(cx.getRef(), Bv(new boolean[] {false, false, false, true})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -350,7 +363,7 @@ public void testBV5() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Neg(cx.getRef()))); SolverStatus status = solver.check(); @@ -372,8 +385,14 @@ public void testBV6() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Mul(List.of(cx.getRef(), Bv(new boolean[]{false, false, true, false}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Mul( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, true, false}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -394,8 +413,8 @@ public void testBV7() { solver.push(); - solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[]{true, true, true, true}))); - solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[]{true, true, true, true}))); + solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[] {true, true, true, true}))); + solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[] {true, true, true, true}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -416,8 +435,11 @@ public void testBV8() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{true, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), BvExprs.SMod(cx.getRef(), Bv(new boolean[]{false, true, false, false})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {true, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.SMod(cx.getRef(), Bv(new boolean[] {false, true, false, false})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -438,8 +460,11 @@ public void testBV9() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Or(List.of(cx.getRef(), cy.getRef())), Bv(new boolean[]{true, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Or(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {true, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -460,8 +485,11 @@ public void testBV10() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.And(List.of(cx.getRef(), cy.getRef())), Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.And(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -482,8 +510,11 @@ public void testBV11() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -504,8 +535,12 @@ public void testBV12() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.ArithShiftRight(cy.getRef(), Bv(new boolean[]{false, false, false, true})), cx.getRef())); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.ArithShiftRight( + cy.getRef(), Bv(new boolean[] {false, false, false, true})), + cx.getRef())); SolverStatus status = solver.check(); assertTrue(status.isSat()); diff --git a/subprojects/solver/solver-z3-legacy/build.gradle.kts b/subprojects/solver/solver-z3-legacy/build.gradle.kts index 42fd4a62eb..1d84a0566f 100644 --- a/subprojects/solver/solver-z3-legacy/build.gradle.kts +++ b/subprojects/solver/solver-z3-legacy/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3DeclTransformer.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3DeclTransformer.java index 096ec534ff..ee6a750f82 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3DeclTransformer.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3DeclTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.collect.ImmutableList; import com.microsoft.z3legacy.Context; import hu.bme.mit.theta.common.Tuple2; @@ -22,11 +24,8 @@ import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.functype.FuncType; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; - final class Z3DeclTransformer { private final Z3TransformationManager transformer; @@ -35,8 +34,10 @@ final class Z3DeclTransformer { private int symbolCount; - Z3DeclTransformer(final Z3TransformationManager transformer, final Z3SymbolTable symbolTable, - final Context context) { + Z3DeclTransformer( + final Z3TransformationManager transformer, + final Z3SymbolTable symbolTable, + final Context context) { this.transformer = transformer; this.symbolTable = symbolTable; this.context = context; @@ -64,9 +65,10 @@ private com.microsoft.z3legacy.FuncDecl transformConst(final ConstDecl decl) final Type returnType = extractedTypes.get2(); final com.microsoft.z3legacy.Sort returnSort = transformer.toSort(returnType); - final com.microsoft.z3legacy.Sort[] paramSorts = paramTypes.stream() - .map(t -> transformer.toSort(t)) - .toArray(size -> new com.microsoft.z3legacy.Sort[size]); + final com.microsoft.z3legacy.Sort[] paramSorts = + paramTypes.stream() + .map(t -> transformer.toSort(t)) + .toArray(size -> new com.microsoft.z3legacy.Sort[size]); symbol = context.mkFuncDecl(symbolNameFor(decl), paramSorts, returnSort); symbolTable.put(decl, symbol); @@ -87,8 +89,8 @@ private Tuple2, Type> extractTypes(final Type type) { final Tuple2, Type> subResult = extractTypes(resultType); final List paramTypes = subResult.get1(); final Type newResultType = subResult.get2(); - final List newParamTypes = ImmutableList.builder().add(paramType) - .addAll(paramTypes).build(); + final List newParamTypes = + ImmutableList.builder().add(paramType).addAll(paramTypes).build(); final Tuple2, Type> result = Tuple2.of(newParamTypes, newResultType); return result; @@ -100,5 +102,4 @@ private Tuple2, Type> extractTypes(final Type type) { private String symbolNameFor(final Decl decl) { return String.format("%s_%d", decl.getName(), symbolCount++); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ExprTransformer.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ExprTransformer.java index 128fa0d8c9..f9841fda37 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ExprTransformer.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,12 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; + import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableList; import com.microsoft.z3legacy.*; import hu.bme.mit.theta.common.DispatchTable; import hu.bme.mit.theta.common.Tuple2; @@ -44,15 +47,10 @@ import hu.bme.mit.theta.core.type.inttype.*; import hu.bme.mit.theta.core.type.rattype.*; import hu.bme.mit.theta.core.utils.BvUtils; - import java.util.List; import java.util.concurrent.ExecutionException; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; - final class Z3ExprTransformer { private static final int CACHE_SIZE = 1000; @@ -71,255 +69,152 @@ public Z3ExprTransformer(final Z3TransformationManager transformer, final Contex exprToTerm = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(); - table = DispatchTable.builder() - - // General - - .addCase(RefExpr.class, this::transformRef) - - .addCase(IteExpr.class, this::transformIte) - - // Boolean - - .addCase(FalseExpr.class, this::transformFalse) - - .addCase(TrueExpr.class, this::transformTrue) - - .addCase(NotExpr.class, this::transformNot) - - .addCase(ImplyExpr.class, this::transformImply) - - .addCase(IffExpr.class, this::transformIff) - - .addCase(XorExpr.class, this::transformXor) - - .addCase(AndExpr.class, this::transformAnd) - - .addCase(OrExpr.class, this::transformOr) - - .addCase(ExistsExpr.class, this::transformExists) - - .addCase(ForallExpr.class, this::transformForall) - - // Rationals - - .addCase(RatLitExpr.class, this::transformRatLit) - - .addCase(RatAddExpr.class, this::transformRatAdd) - - .addCase(RatSubExpr.class, this::transformRatSub) - - .addCase(RatPosExpr.class, this::transformRatPos) - - .addCase(RatNegExpr.class, this::transformRatNeg) - - .addCase(RatMulExpr.class, this::transformRatMul) - - .addCase(RatDivExpr.class, this::transformRatDiv) - - .addCase(RatEqExpr.class, this::transformRatEq) - - .addCase(RatNeqExpr.class, this::transformRatNeq) - - .addCase(RatGeqExpr.class, this::transformRatGeq) - - .addCase(RatGtExpr.class, this::transformRatGt) - - .addCase(RatLeqExpr.class, this::transformRatLeq) - - .addCase(RatLtExpr.class, this::transformRatLt) - - .addCase(RatToIntExpr.class, this::transformRatToInt) - - // Integers - - .addCase(IntLitExpr.class, this::transformIntLit) - - .addCase(IntAddExpr.class, this::transformIntAdd) - - .addCase(IntSubExpr.class, this::transformIntSub) - - .addCase(IntPosExpr.class, this::transformIntPos) - - .addCase(IntNegExpr.class, this::transformIntNeg) - - .addCase(IntMulExpr.class, this::transformIntMul) - - .addCase(IntDivExpr.class, this::transformIntDiv) - - .addCase(IntModExpr.class, this::transformIntMod) - - .addCase(IntRemExpr.class, this::transformIntRem) - - .addCase(IntEqExpr.class, this::transformIntEq) - - .addCase(IntNeqExpr.class, this::transformIntNeq) - - .addCase(IntGeqExpr.class, this::transformIntGeq) - - .addCase(IntGtExpr.class, this::transformIntGt) - - .addCase(IntLeqExpr.class, this::transformIntLeq) - - .addCase(IntLtExpr.class, this::transformIntLt) - - .addCase(IntToRatExpr.class, this::transformIntToRat) - - // Bitvectors - - .addCase(BvLitExpr.class, this::transformBvLit) - - .addCase(BvConcatExpr.class, this::transformBvConcat) - - .addCase(BvExtractExpr.class, this::transformBvExtract) - - .addCase(BvZExtExpr.class, this::transformBvZExt) - - .addCase(BvSExtExpr.class, this::transformBvSExt) - - .addCase(BvAddExpr.class, this::transformBvAdd) - - .addCase(BvSubExpr.class, this::transformBvSub) - - .addCase(BvPosExpr.class, this::transformBvPos) - - .addCase(BvSignChangeExpr.class, this::transformBvSignChange) - - .addCase(BvNegExpr.class, this::transformBvNeg) - - .addCase(BvMulExpr.class, this::transformBvMul) - - .addCase(BvUDivExpr.class, this::transformBvUDiv) - - .addCase(BvSDivExpr.class, this::transformBvSDiv) - - .addCase(BvSModExpr.class, this::transformBvSMod) - - .addCase(BvURemExpr.class, this::transformBvURem) - - .addCase(BvSRemExpr.class, this::transformBvSRem) - - .addCase(BvAndExpr.class, this::transformBvAnd) - - .addCase(BvOrExpr.class, this::transformBvOr) - - .addCase(BvXorExpr.class, this::transformBvXor) - - .addCase(BvNotExpr.class, this::transformBvNot) - - .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) - - .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) - - .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) - - .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) - - .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) - - .addCase(BvEqExpr.class, this::transformBvEq) - - .addCase(BvNeqExpr.class, this::transformBvNeq) - - .addCase(BvUGeqExpr.class, this::transformBvUGeq) - - .addCase(BvUGtExpr.class, this::transformBvUGt) - - .addCase(BvULeqExpr.class, this::transformBvULeq) - - .addCase(BvULtExpr.class, this::transformBvULt) - - .addCase(BvSGeqExpr.class, this::transformBvSGeq) - - .addCase(BvSGtExpr.class, this::transformBvSGt) - - .addCase(BvSLeqExpr.class, this::transformBvSLeq) - - .addCase(BvSLtExpr.class, this::transformBvSLt) - - // Floating points - - .addCase(FpLitExpr.class, this::transformFpLit) - - .addCase(FpAddExpr.class, this::transformFpAdd) - - .addCase(FpSubExpr.class, this::transformFpSub) - - .addCase(FpPosExpr.class, this::transformFpPos) - - .addCase(FpNegExpr.class, this::transformFpNeg) - - .addCase(FpMulExpr.class, this::transformFpMul) - - .addCase(FpDivExpr.class, this::transformFpDiv) - - .addCase(FpEqExpr.class, this::transformFpEq) - - .addCase(FpAssignExpr.class, this::transformFpAssign) - - .addCase(FpGeqExpr.class, this::transformFpGeq) - - .addCase(FpLeqExpr.class, this::transformFpLeq) - - .addCase(FpGtExpr.class, this::transformFpGt) - - .addCase(FpLtExpr.class, this::transformFpLt) - - .addCase(FpNeqExpr.class, this::transformFpNeq) - - .addCase(FpAbsExpr.class, this::transformFpAbs) - - .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) - - .addCase(FpMaxExpr.class, this::transformFpMax) - - .addCase(FpMinExpr.class, this::transformFpMin) - - .addCase(FpSqrtExpr.class, this::transformFpSqrt) - - .addCase(FpRemExpr.class, this::transformFpRem) - - .addCase(FpIsNanExpr.class, this::transformFpIsNan) - - .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) - - .addCase(FpFromBvExpr.class, this::transformFpFromBv) - - .addCase(FpToBvExpr.class, this::transformFpToBv) - - .addCase(FpToFpExpr.class, this::transformFpToFp) - - // Functions - - .addCase(FuncAppExpr.class, this::transformFuncApp) - - // Arrays - - .addCase(ArrayReadExpr.class, this::transformArrayRead) - - .addCase(ArrayWriteExpr.class, this::transformArrayWrite) - - .addCase(ArrayEqExpr.class, this::transformArrayEq) - - .addCase(ArrayNeqExpr.class, this::transformArrayNeq) - - .addCase(ArrayLitExpr.class, this::transformArrayLit) - - .addCase(ArrayInitExpr.class, this::transformArrayInit) - - // dereference - - .addCase(Dereference.class, this::transformDereference) - - // Enums - - .addCase(EnumLitExpr.class, this::transformEnumLit) - - .addCase(EnumEqExpr.class, this::transformEnumEq) - - .addCase(EnumNeqExpr.class, this::transformEnumNeq) - - .build(); + table = + DispatchTable.builder() + + // General + + .addCase(RefExpr.class, this::transformRef) + .addCase(IteExpr.class, this::transformIte) + + // Boolean + + .addCase(FalseExpr.class, this::transformFalse) + .addCase(TrueExpr.class, this::transformTrue) + .addCase(NotExpr.class, this::transformNot) + .addCase(ImplyExpr.class, this::transformImply) + .addCase(IffExpr.class, this::transformIff) + .addCase(XorExpr.class, this::transformXor) + .addCase(AndExpr.class, this::transformAnd) + .addCase(OrExpr.class, this::transformOr) + .addCase(ExistsExpr.class, this::transformExists) + .addCase(ForallExpr.class, this::transformForall) + + // Rationals + + .addCase(RatLitExpr.class, this::transformRatLit) + .addCase(RatAddExpr.class, this::transformRatAdd) + .addCase(RatSubExpr.class, this::transformRatSub) + .addCase(RatPosExpr.class, this::transformRatPos) + .addCase(RatNegExpr.class, this::transformRatNeg) + .addCase(RatMulExpr.class, this::transformRatMul) + .addCase(RatDivExpr.class, this::transformRatDiv) + .addCase(RatEqExpr.class, this::transformRatEq) + .addCase(RatNeqExpr.class, this::transformRatNeq) + .addCase(RatGeqExpr.class, this::transformRatGeq) + .addCase(RatGtExpr.class, this::transformRatGt) + .addCase(RatLeqExpr.class, this::transformRatLeq) + .addCase(RatLtExpr.class, this::transformRatLt) + .addCase(RatToIntExpr.class, this::transformRatToInt) + + // Integers + + .addCase(IntLitExpr.class, this::transformIntLit) + .addCase(IntAddExpr.class, this::transformIntAdd) + .addCase(IntSubExpr.class, this::transformIntSub) + .addCase(IntPosExpr.class, this::transformIntPos) + .addCase(IntNegExpr.class, this::transformIntNeg) + .addCase(IntMulExpr.class, this::transformIntMul) + .addCase(IntDivExpr.class, this::transformIntDiv) + .addCase(IntModExpr.class, this::transformIntMod) + .addCase(IntRemExpr.class, this::transformIntRem) + .addCase(IntEqExpr.class, this::transformIntEq) + .addCase(IntNeqExpr.class, this::transformIntNeq) + .addCase(IntGeqExpr.class, this::transformIntGeq) + .addCase(IntGtExpr.class, this::transformIntGt) + .addCase(IntLeqExpr.class, this::transformIntLeq) + .addCase(IntLtExpr.class, this::transformIntLt) + .addCase(IntToRatExpr.class, this::transformIntToRat) + + // Bitvectors + + .addCase(BvLitExpr.class, this::transformBvLit) + .addCase(BvConcatExpr.class, this::transformBvConcat) + .addCase(BvExtractExpr.class, this::transformBvExtract) + .addCase(BvZExtExpr.class, this::transformBvZExt) + .addCase(BvSExtExpr.class, this::transformBvSExt) + .addCase(BvAddExpr.class, this::transformBvAdd) + .addCase(BvSubExpr.class, this::transformBvSub) + .addCase(BvPosExpr.class, this::transformBvPos) + .addCase(BvSignChangeExpr.class, this::transformBvSignChange) + .addCase(BvNegExpr.class, this::transformBvNeg) + .addCase(BvMulExpr.class, this::transformBvMul) + .addCase(BvUDivExpr.class, this::transformBvUDiv) + .addCase(BvSDivExpr.class, this::transformBvSDiv) + .addCase(BvSModExpr.class, this::transformBvSMod) + .addCase(BvURemExpr.class, this::transformBvURem) + .addCase(BvSRemExpr.class, this::transformBvSRem) + .addCase(BvAndExpr.class, this::transformBvAnd) + .addCase(BvOrExpr.class, this::transformBvOr) + .addCase(BvXorExpr.class, this::transformBvXor) + .addCase(BvNotExpr.class, this::transformBvNot) + .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) + .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) + .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) + .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) + .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) + .addCase(BvEqExpr.class, this::transformBvEq) + .addCase(BvNeqExpr.class, this::transformBvNeq) + .addCase(BvUGeqExpr.class, this::transformBvUGeq) + .addCase(BvUGtExpr.class, this::transformBvUGt) + .addCase(BvULeqExpr.class, this::transformBvULeq) + .addCase(BvULtExpr.class, this::transformBvULt) + .addCase(BvSGeqExpr.class, this::transformBvSGeq) + .addCase(BvSGtExpr.class, this::transformBvSGt) + .addCase(BvSLeqExpr.class, this::transformBvSLeq) + .addCase(BvSLtExpr.class, this::transformBvSLt) + + // Floating points + + .addCase(FpLitExpr.class, this::transformFpLit) + .addCase(FpAddExpr.class, this::transformFpAdd) + .addCase(FpSubExpr.class, this::transformFpSub) + .addCase(FpPosExpr.class, this::transformFpPos) + .addCase(FpNegExpr.class, this::transformFpNeg) + .addCase(FpMulExpr.class, this::transformFpMul) + .addCase(FpDivExpr.class, this::transformFpDiv) + .addCase(FpEqExpr.class, this::transformFpEq) + .addCase(FpAssignExpr.class, this::transformFpAssign) + .addCase(FpGeqExpr.class, this::transformFpGeq) + .addCase(FpLeqExpr.class, this::transformFpLeq) + .addCase(FpGtExpr.class, this::transformFpGt) + .addCase(FpLtExpr.class, this::transformFpLt) + .addCase(FpNeqExpr.class, this::transformFpNeq) + .addCase(FpAbsExpr.class, this::transformFpAbs) + .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) + .addCase(FpMaxExpr.class, this::transformFpMax) + .addCase(FpMinExpr.class, this::transformFpMin) + .addCase(FpSqrtExpr.class, this::transformFpSqrt) + .addCase(FpRemExpr.class, this::transformFpRem) + .addCase(FpIsNanExpr.class, this::transformFpIsNan) + .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) + .addCase(FpFromBvExpr.class, this::transformFpFromBv) + .addCase(FpToBvExpr.class, this::transformFpToBv) + .addCase(FpToFpExpr.class, this::transformFpToFp) + + // Functions + + .addCase(FuncAppExpr.class, this::transformFuncApp) + + // Arrays + + .addCase(ArrayReadExpr.class, this::transformArrayRead) + .addCase(ArrayWriteExpr.class, this::transformArrayWrite) + .addCase(ArrayEqExpr.class, this::transformArrayEq) + .addCase(ArrayNeqExpr.class, this::transformArrayNeq) + .addCase(ArrayLitExpr.class, this::transformArrayLit) + .addCase(ArrayInitExpr.class, this::transformArrayInit) + + // dereference + + .addCase(Dereference.class, this::transformDereference) + + // Enums + + .addCase(EnumLitExpr.class, this::transformEnumLit) + .addCase(EnumEqExpr.class, this::transformEnumEq) + .addCase(EnumNeqExpr.class, this::transformEnumNeq) + .build(); } //// @@ -342,8 +237,8 @@ private com.microsoft.z3legacy.Expr transformRef(final RefExpr expr) { final com.microsoft.z3legacy.FuncDecl funcDecl = transformer.toSymbol(decl); return context.mkConst(funcDecl); } else if (decl instanceof ParamDecl) { - final com.microsoft.z3legacy.FuncDecl funcDecl = (com.microsoft.z3legacy.FuncDecl) env.eval( - DeclSymbol.of(decl)); + final com.microsoft.z3legacy.FuncDecl funcDecl = + (com.microsoft.z3legacy.FuncDecl) env.eval(DeclSymbol.of(decl)); return context.mkConst(funcDecl); } else { throw new UnsupportedOperationException( @@ -364,7 +259,6 @@ private com.microsoft.z3legacy.Expr transformIte(final IteExpr expr) { private com.microsoft.z3legacy.Expr transformFalse(final FalseExpr expr) { return context.mkFalse(); - } private com.microsoft.z3legacy.Expr transformTrue(final TrueExpr expr) { @@ -395,16 +289,14 @@ private com.microsoft.z3legacy.Expr transformXor(final XorExpr expr) { } private com.microsoft.z3legacy.Expr transformAnd(final AndExpr expr) { - final BoolExpr[] opTerms = expr.getOps().stream() - .map(e -> (BoolExpr) toTerm(e)) - .toArray(BoolExpr[]::new); + final BoolExpr[] opTerms = + expr.getOps().stream().map(e -> (BoolExpr) toTerm(e)).toArray(BoolExpr[]::new); return context.mkAnd(opTerms); } private com.microsoft.z3legacy.Expr transformOr(final OrExpr expr) { - final BoolExpr[] opTerms = expr.getOps().stream() - .map(e -> (BoolExpr) toTerm(e)) - .toArray(BoolExpr[]::new); + final BoolExpr[] opTerms = + expr.getOps().stream().map(e -> (BoolExpr) toTerm(e)).toArray(BoolExpr[]::new); return context.mkOr(opTerms); } @@ -427,7 +319,8 @@ private com.microsoft.z3legacy.Expr transformForall(final ForallExpr expr) { } private com.microsoft.z3legacy.Expr[] transformParamDecls(final List> paramDecls) { - final com.microsoft.z3legacy.Expr[] paramTerms = new com.microsoft.z3legacy.Expr[paramDecls.size()]; + final com.microsoft.z3legacy.Expr[] paramTerms = + new com.microsoft.z3legacy.Expr[paramDecls.size()]; int i = 0; for (final ParamDecl paramDecl : paramDecls) { final com.microsoft.z3legacy.FuncDecl paramSymbol = transformParamDecl(paramDecl); @@ -459,17 +352,18 @@ private com.microsoft.z3legacy.Expr transformRatLit(final RatLitExpr expr) { } private com.microsoft.z3legacy.Expr transformRatAdd(final RatAddExpr expr) { - final com.microsoft.z3legacy.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3legacy.ArithExpr[]::new); + final com.microsoft.z3legacy.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3legacy.ArithExpr[]::new); return context.mkAdd(opTerms); } private com.microsoft.z3legacy.Expr transformRatSub(final RatSubExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkSub(leftOpTerm, rightOpTerm); } @@ -478,22 +372,24 @@ private com.microsoft.z3legacy.Expr transformRatPos(final RatPosExpr expr) { } private com.microsoft.z3legacy.Expr transformRatNeg(final RatNegExpr expr) { - final com.microsoft.z3legacy.ArithExpr opTerm = (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getOp()); + final com.microsoft.z3legacy.ArithExpr opTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getOp()); return context.mkUnaryMinus(opTerm); } private com.microsoft.z3legacy.Expr transformRatMul(final RatMulExpr expr) { - final com.microsoft.z3legacy.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3legacy.ArithExpr[]::new); + final com.microsoft.z3legacy.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3legacy.ArithExpr[]::new); return context.mkMul(opTerms); } private com.microsoft.z3legacy.Expr transformRatDiv(final RatDivExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkDiv(leftOpTerm, rightOpTerm); } @@ -510,34 +406,34 @@ private com.microsoft.z3legacy.Expr transformRatNeq(final RatNeqExpr expr) { } private com.microsoft.z3legacy.Expr transformRatGeq(final RatGeqExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkGe(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformRatGt(final RatGtExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkGt(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformRatLeq(final RatLeqExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkLe(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformRatLt(final RatLtExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkLt(leftOpTerm, rightOpTerm); } @@ -546,7 +442,8 @@ private com.microsoft.z3legacy.Expr transformRatLt(final RatLtExpr expr) { */ private com.microsoft.z3legacy.Expr transformRatToInt(final RatToIntExpr expr) { - final com.microsoft.z3legacy.RealExpr opTerm = (com.microsoft.z3legacy.RealExpr) toTerm(expr.getOp()); + final com.microsoft.z3legacy.RealExpr opTerm = + (com.microsoft.z3legacy.RealExpr) toTerm(expr.getOp()); return context.mkReal2Int(opTerm); } @@ -555,17 +452,18 @@ private com.microsoft.z3legacy.Expr transformIntLit(final IntLitExpr expr) { } private com.microsoft.z3legacy.Expr transformIntAdd(final IntAddExpr expr) { - final com.microsoft.z3legacy.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3legacy.ArithExpr[]::new); + final com.microsoft.z3legacy.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3legacy.ArithExpr[]::new); return context.mkAdd(opTerms); } private com.microsoft.z3legacy.Expr transformIntSub(final IntSubExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkSub(leftOpTerm, rightOpTerm); } @@ -574,38 +472,40 @@ private com.microsoft.z3legacy.Expr transformIntPos(final IntPosExpr expr) { } private com.microsoft.z3legacy.Expr transformIntNeg(final IntNegExpr expr) { - final com.microsoft.z3legacy.ArithExpr opTerm = (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getOp()); + final com.microsoft.z3legacy.ArithExpr opTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getOp()); return context.mkUnaryMinus(opTerm); } private com.microsoft.z3legacy.Expr transformIntMul(final IntMulExpr expr) { - final com.microsoft.z3legacy.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3legacy.ArithExpr[]::new); + final com.microsoft.z3legacy.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3legacy.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3legacy.ArithExpr[]::new); return context.mkMul(opTerms); } private com.microsoft.z3legacy.Expr transformIntDiv(final IntDivExpr expr) { - final com.microsoft.z3legacy.IntExpr leftOpTerm = (com.microsoft.z3legacy.IntExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.IntExpr rightOpTerm = (com.microsoft.z3legacy.IntExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.IntExpr leftOpTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.IntExpr rightOpTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getRightOp()); return context.mkDiv(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformIntMod(final IntModExpr expr) { - final com.microsoft.z3legacy.IntExpr leftOpTerm = (com.microsoft.z3legacy.IntExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.IntExpr rightOpTerm = (com.microsoft.z3legacy.IntExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.IntExpr leftOpTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.IntExpr rightOpTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getRightOp()); return context.mkMod(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformIntRem(final IntRemExpr expr) { - final com.microsoft.z3legacy.IntExpr leftOpTerm = (com.microsoft.z3legacy.IntExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.IntExpr rightOpTerm = (com.microsoft.z3legacy.IntExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.IntExpr leftOpTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.IntExpr rightOpTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getRightOp()); return context.mkRem(leftOpTerm, rightOpTerm); } @@ -622,34 +522,34 @@ private com.microsoft.z3legacy.Expr transformIntNeq(final IntNeqExpr expr) { } private com.microsoft.z3legacy.Expr transformIntGeq(final IntGeqExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkGe(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformIntGt(final IntGtExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkGt(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformIntLeq(final IntLeqExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkLe(leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformIntLt(final IntLtExpr expr) { - final com.microsoft.z3legacy.ArithExpr leftOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3legacy.ArithExpr rightOpTerm = (com.microsoft.z3legacy.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3legacy.ArithExpr leftOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3legacy.ArithExpr rightOpTerm = + (com.microsoft.z3legacy.ArithExpr) toTerm(expr.getRightOp()); return context.mkLt(leftOpTerm, rightOpTerm); } @@ -658,13 +558,14 @@ private com.microsoft.z3legacy.Expr transformIntLt(final IntLtExpr expr) { */ private com.microsoft.z3legacy.Expr transformIntToRat(final IntToRatExpr expr) { - final com.microsoft.z3legacy.IntExpr opTerm = (com.microsoft.z3legacy.IntExpr) toTerm(expr.getOp()); + final com.microsoft.z3legacy.IntExpr opTerm = + (com.microsoft.z3legacy.IntExpr) toTerm(expr.getOp()); return context.mkInt2Real(opTerm); } private com.microsoft.z3legacy.Expr transformBvLit(final BvLitExpr expr) { - return context.mkBV(BvUtils.neutralBvLitExprToBigInteger(expr).toString(), - expr.getType().getSize()); + return context.mkBV( + BvUtils.neutralBvLitExprToBigInteger(expr).toString(), expr.getType().getSize()); } private com.microsoft.z3legacy.Expr transformBvEq(final BvEqExpr expr) { @@ -680,9 +581,8 @@ private com.microsoft.z3legacy.Expr transformBvNeq(final BvNeqExpr expr) { } private com.microsoft.z3legacy.Expr transformBvConcat(final BvConcatExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkConcat); } @@ -710,9 +610,8 @@ private com.microsoft.z3legacy.Expr transformBvSExt(final BvSExtExpr expr) { } private com.microsoft.z3legacy.Expr transformBvAdd(final BvAddExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVAdd); } @@ -737,9 +636,8 @@ private com.microsoft.z3legacy.Expr transformBvNeg(final BvNegExpr expr) { } private com.microsoft.z3legacy.Expr transformBvMul(final BvMulExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVMul); } @@ -780,25 +678,22 @@ private com.microsoft.z3legacy.Expr transformBvSRem(final BvSRemExpr expr) { } private com.microsoft.z3legacy.Expr transformBvAnd(final BvAndExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVAND); } private com.microsoft.z3legacy.Expr transformBvOr(final BvOrExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVOR); } private com.microsoft.z3legacy.Expr transformBvXor(final BvXorExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVXOR); } @@ -816,14 +711,16 @@ private com.microsoft.z3legacy.Expr transformBvShiftLeft(final BvShiftLeftExpr e return context.mkBVSHL(leftOpTerm, rightOpTerm); } - private com.microsoft.z3legacy.Expr transformBvArithShiftRight(final BvArithShiftRightExpr expr) { + private com.microsoft.z3legacy.Expr transformBvArithShiftRight( + final BvArithShiftRightExpr expr) { final BitVecExpr leftOpTerm = (BitVecExpr) toTerm(expr.getLeftOp()); final BitVecExpr rightOpTerm = (BitVecExpr) toTerm(expr.getRightOp()); return context.mkBVASHR(leftOpTerm, rightOpTerm); } - private com.microsoft.z3legacy.Expr transformBvLogicShiftRight(final BvLogicShiftRightExpr expr) { + private com.microsoft.z3legacy.Expr transformBvLogicShiftRight( + final BvLogicShiftRightExpr expr) { final BitVecExpr leftOpTerm = (BitVecExpr) toTerm(expr.getLeftOp()); final BitVecExpr rightOpTerm = (BitVecExpr) toTerm(expr.getRightOp()); @@ -905,25 +802,30 @@ private com.microsoft.z3legacy.Expr transformBvSLt(final BvSLtExpr expr) { } private com.microsoft.z3legacy.Expr transformFpLit(final FpLitExpr expr) { - return context.mkFP(context.mkBV(expr.getHidden() ? 1 : 0, 1), - (BitVecExpr) toTerm(expr.getExponent()), (BitVecExpr) toTerm(expr.getSignificand())); + return context.mkFP( + context.mkBV(expr.getHidden() ? 1 : 0, 1), + (BitVecExpr) toTerm(expr.getExponent()), + (BitVecExpr) toTerm(expr.getSignificand())); } private com.microsoft.z3legacy.Expr transformFpAdd(final FpAddExpr expr) { - final FPExpr[] opTerms = expr.getOps().stream() - .map(e -> (FPExpr) toTerm(e)) - .toArray(FPExpr[]::new); + final FPExpr[] opTerms = + expr.getOps().stream().map(e -> (FPExpr) toTerm(e)).toArray(FPExpr[]::new); - return Stream.of(opTerms).skip(1).reduce(opTerms[0], - (op1, op2) -> context.mkFPAdd(transformFpRoundingMode(expr.getRoundingMode()), op1, - op2)); + return Stream.of(opTerms) + .skip(1) + .reduce( + opTerms[0], + (op1, op2) -> + context.mkFPAdd( + transformFpRoundingMode(expr.getRoundingMode()), op1, op2)); } private com.microsoft.z3legacy.Expr transformFpSub(final FpSubExpr expr) { final FPExpr leftOpTerm = (FPExpr) toTerm(expr.getLeftOp()); final FPExpr rightOpTerm = (FPExpr) toTerm(expr.getRightOp()); - return context.mkFPSub(transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, - rightOpTerm); + return context.mkFPSub( + transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformFpPos(final FpPosExpr expr) { @@ -955,27 +857,31 @@ private com.microsoft.z3legacy.Expr transformFpSqrt(final FpSqrtExpr expr) { return context.mkFPSqrt(transformFpRoundingMode(expr.getRoundingMode()), opTerm); } - private com.microsoft.z3legacy.Expr transformFpRoundToIntegral(final FpRoundToIntegralExpr expr) { + private com.microsoft.z3legacy.Expr transformFpRoundToIntegral( + final FpRoundToIntegralExpr expr) { final FPExpr opTerm = (FPExpr) toTerm(expr.getOp()); return context.mkFPRoundToIntegral(transformFpRoundingMode(expr.getRoundingMode()), opTerm); } private com.microsoft.z3legacy.Expr transformFpMul(final FpMulExpr expr) { - final FPExpr[] opTerms = expr.getOps().stream() - .map(e -> (FPExpr) toTerm(e)) - .toArray(FPExpr[]::new); + final FPExpr[] opTerms = + expr.getOps().stream().map(e -> (FPExpr) toTerm(e)).toArray(FPExpr[]::new); - return Stream.of(opTerms).skip(1).reduce(opTerms[0], - (op1, op2) -> context.mkFPMul(transformFpRoundingMode(expr.getRoundingMode()), op1, - op2)); + return Stream.of(opTerms) + .skip(1) + .reduce( + opTerms[0], + (op1, op2) -> + context.mkFPMul( + transformFpRoundingMode(expr.getRoundingMode()), op1, op2)); } private com.microsoft.z3legacy.Expr transformFpDiv(final FpDivExpr expr) { final FPExpr leftOpTerm = (FPExpr) toTerm(expr.getLeftOp()); final FPExpr rightOpTerm = (FPExpr) toTerm(expr.getRightOp()); - return context.mkFPDiv(transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, - rightOpTerm); + return context.mkFPDiv( + transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, rightOpTerm); } private com.microsoft.z3legacy.Expr transformFpRem(final FpRemExpr expr) { @@ -1026,7 +932,8 @@ private com.microsoft.z3legacy.Expr transformFpLt(final FpLtExpr expr) { return context.mkFPLt((FPExpr) leftOpTerm, (FPExpr) rightOpTerm); } - private com.microsoft.z3legacy.FPRMExpr transformFpRoundingMode(final FpRoundingMode roundingMode) { + private com.microsoft.z3legacy.FPRMExpr transformFpRoundingMode( + final FpRoundingMode roundingMode) { switch (roundingMode) { case RNE: return context.mkFPRoundNearestTiesToEven(); @@ -1057,9 +964,12 @@ private com.microsoft.z3legacy.Expr transformFpMin(final FpMinExpr expr) { private com.microsoft.z3legacy.Expr transformFpFromBv(final FpFromBvExpr expr) { final BitVecExpr val = (BitVecExpr) toTerm(expr.getOp()); - final FPSort fpSort = context.mkFPSort(expr.getFpType().getExponent(), - expr.getFpType().getSignificand()); - return context.mkFPToFP(transformFpRoundingMode(expr.getRoundingMode()), val, fpSort, + final FPSort fpSort = + context.mkFPSort(expr.getFpType().getExponent(), expr.getFpType().getSignificand()); + return context.mkFPToFP( + transformFpRoundingMode(expr.getRoundingMode()), + val, + fpSort, expr.isSigned()); // TODO: is this OK? FP2FP when BV2FP is used? } @@ -1070,6 +980,7 @@ private com.microsoft.z3legacy.Expr transformFpToBv(final FpToBvExpr expr) { return context.mkFPToBV(transformFpRoundingMode(expr.getRoundingMode()), op, size, sgn); } + /* * Arrays */ @@ -1077,20 +988,22 @@ private com.microsoft.z3legacy.Expr transformFpToBv(final FpToBvExpr expr) { private com.microsoft.z3legacy.Expr transformFpToFp(final FpToFpExpr expr) { final FPExpr op = (FPExpr) toTerm(expr.getOp()); - return context.mkFPToFP(transformFpRoundingMode(expr.getRoundingMode()), op, + return context.mkFPToFP( + transformFpRoundingMode(expr.getRoundingMode()), + op, new FPSort(context, expr.getExpBits(), expr.getSignBits())); } private com.microsoft.z3legacy.Expr transformArrayRead(final ArrayReadExpr expr) { - final com.microsoft.z3legacy.ArrayExpr arrayTerm = (com.microsoft.z3legacy.ArrayExpr) toTerm( - expr.getArray()); + final com.microsoft.z3legacy.ArrayExpr arrayTerm = + (com.microsoft.z3legacy.ArrayExpr) toTerm(expr.getArray()); final com.microsoft.z3legacy.Expr indexTerm = toTerm(expr.getIndex()); return context.mkSelect(arrayTerm, indexTerm); } private com.microsoft.z3legacy.Expr transformArrayWrite(final ArrayWriteExpr expr) { - final com.microsoft.z3legacy.ArrayExpr arrayTerm = (com.microsoft.z3legacy.ArrayExpr) toTerm( - expr.getArray()); + final com.microsoft.z3legacy.ArrayExpr arrayTerm = + (com.microsoft.z3legacy.ArrayExpr) toTerm(expr.getArray()); final com.microsoft.z3legacy.Expr indexTerm = toTerm(expr.getIndex()); final com.microsoft.z3legacy.Expr elemTerm = toTerm(expr.getElem()); return context.mkStore(arrayTerm, indexTerm, elemTerm); @@ -1113,8 +1026,10 @@ private com.microsoft.z3legacy.Expr transformArrayNeq(final ArrayNeqExpr e */ private com.microsoft.z3legacy.Expr transformArrayLit(final ArrayLitExpr expr) { - com.microsoft.z3legacy.ArrayExpr running = context.mkConstArray( - transformer.toSort(expr.getType().getIndexType()), toTerm(expr.getElseElem())); + com.microsoft.z3legacy.ArrayExpr running = + context.mkConstArray( + transformer.toSort(expr.getType().getIndexType()), + toTerm(expr.getElseElem())); for (Tuple2, ? extends Expr> elem : expr.getElements()) { running = context.mkStore(running, toTerm(elem.get1()), toTerm(elem.get2())); } @@ -1122,8 +1037,10 @@ private com.microsoft.z3legacy.Expr transformArrayLit(final ArrayLitExpr e } private com.microsoft.z3legacy.Expr transformArrayInit(final ArrayInitExpr expr) { - com.microsoft.z3legacy.ArrayExpr running = context.mkConstArray( - transformer.toSort(expr.getType().getIndexType()), toTerm(expr.getElseElem())); + com.microsoft.z3legacy.ArrayExpr running = + context.mkConstArray( + transformer.toSort(expr.getType().getIndexType()), + toTerm(expr.getElseElem())); for (Tuple2, ? extends Expr> elem : expr.getElements()) { running = context.mkStore(running, toTerm(elem.get1()), toTerm(elem.get2())); } @@ -1138,9 +1055,8 @@ private com.microsoft.z3legacy.Expr transformFuncApp(final FuncAppExpr exp final Decl decl = ref.getDecl(); final com.microsoft.z3legacy.FuncDecl funcDecl = transformer.toSymbol(decl); final List> args = funcAndArgs.get2(); - final com.microsoft.z3legacy.Expr[] argTerms = args.stream() - .map(this::toTerm) - .toArray(com.microsoft.z3legacy.Expr[]::new); + final com.microsoft.z3legacy.Expr[] argTerms = + args.stream().map(this::toTerm).toArray(com.microsoft.z3legacy.Expr[]::new); return context.mkApp(funcDecl, argTerms); } else { throw new UnsupportedOperationException( @@ -1149,16 +1065,27 @@ private com.microsoft.z3legacy.Expr transformFuncApp(final FuncAppExpr exp } private com.microsoft.z3legacy.Expr transformDereference(final Dereference expr) { - checkState(expr.getUniquenessIdx().isPresent(), "Incomplete dereferences (missing uniquenessIdx) are not handled properly."); + checkState( + expr.getUniquenessIdx().isPresent(), + "Incomplete dereferences (missing uniquenessIdx) are not handled properly."); final var sort = transformer.toSort(expr.getArray().getType()); final var constSort = transformer.toSort(Int()); - final var func = context.mkFuncDecl("deref", new Sort[]{sort, sort, constSort}, transformer.toSort(expr.getType())); - return context.mkApp(func, toTerm(expr.getArray()), toTerm(expr.getOffset()), toTerm(expr.getUniquenessIdx().get())); + final var func = + context.mkFuncDecl( + "deref", + new Sort[] {sort, sort, constSort}, + transformer.toSort(expr.getType())); + return context.mkApp( + func, + toTerm(expr.getArray()), + toTerm(expr.getOffset()), + toTerm(expr.getUniquenessIdx().get())); } private com.microsoft.z3legacy.Expr transformEnumLit(final EnumLitExpr expr) { EnumType enumType = expr.getType(); - return ((EnumSort) transformer.toSort(enumType)).getConst(enumType.getIntValue(expr.getValue())); + return ((EnumSort) transformer.toSort(enumType)) + .getConst(enumType.getIntValue(expr.getValue())); } private com.microsoft.z3legacy.Expr transformEnumEq(final EnumEqExpr expr) { @@ -1176,5 +1103,4 @@ private com.microsoft.z3legacy.Expr transformEnumNeq(final EnumNeqExpr expr) { public void reset() { exprToTerm.invalidateAll(); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Interpolant.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Interpolant.java index 481a7b3cad..45de190de7 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Interpolant.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Interpolant.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,11 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Interpolant; import hu.bme.mit.theta.solver.ItpMarker; +import java.util.Map; final class Z3Interpolant implements Interpolant { @@ -39,5 +38,4 @@ public Expr eval(final ItpMarker marker) { checkNotNull(itpExpr); return itpExpr; } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpMarker.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpMarker.java index 67fb8bd382..8e522cd714 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpMarker.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - final class Z3ItpMarker implements ItpMarker { private final Stack terms; @@ -46,5 +45,4 @@ public void pop(final int n) { public Collection getTerms() { return terms.toCollection(); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpPattern.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpPattern.java index fa4f619c0e..51d46ee940 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpPattern.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpPattern.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,20 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.Lists; import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.ItpMarkerTree; import hu.bme.mit.theta.solver.ItpPattern; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - -public class Z3ItpPattern implements ItpPattern.Binary, - ItpPattern.Sequence, ItpPattern.Tree { +public class Z3ItpPattern + implements ItpPattern.Binary, + ItpPattern.Sequence, + ItpPattern.Tree { final ItpMarkerTree markerTree; @@ -89,11 +90,10 @@ public E visit(ItpPatternVisitor visitor) { } private boolean isBinary() { - return - markerTree != null && - markerTree.getChildrenNumber() == 1 && - markerTree.getChild(0) != null && - markerTree.getChild(0).getChildrenNumber() == 0; + return markerTree != null + && markerTree.getChildrenNumber() == 1 + && markerTree.getChild(0) != null + && markerTree.getChild(0).getChildrenNumber() == 0; } private boolean isSequence() { diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolver.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolver.java index b0df1cfccc..b13fa21281 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolver.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; @@ -28,16 +32,11 @@ import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; - import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - final class Z3ItpSolver implements ItpSolver, Solver { private final Z3TransformationManager transformationManager; @@ -50,18 +49,20 @@ final class Z3ItpSolver implements ItpSolver, Solver { private final Stack markers; - public Z3ItpSolver(final Z3SymbolTable symbolTable, - final Z3TransformationManager transformationManager, - final Z3TermTransformer termTransformer, - final com.microsoft.z3legacy.InterpolationContext z3Context, - final com.microsoft.z3legacy.Solver z3Solver) { + public Z3ItpSolver( + final Z3SymbolTable symbolTable, + final Z3TransformationManager transformationManager, + final Z3TermTransformer termTransformer, + final com.microsoft.z3legacy.InterpolationContext z3Context, + final com.microsoft.z3legacy.Solver z3Solver) { this.transformationManager = transformationManager; this.termTransformer = termTransformer; this.z3Context = z3Context; this.z3Solver = z3Solver; - solver = new Z3Solver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + solver = + new Z3Solver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); markers = new StackImpl<>(); } @@ -85,15 +86,16 @@ public void add(final ItpMarker marker, final Expr assertion) { checkNotNull(assertion); checkArgument(markers.toCollection().contains(marker), "Marker not found in solver"); final Z3ItpMarker z3Marker = (Z3ItpMarker) marker; - final com.microsoft.z3legacy.BoolExpr term = (com.microsoft.z3legacy.BoolExpr) transformationManager.toTerm( - assertion); + final com.microsoft.z3legacy.BoolExpr term = + (com.microsoft.z3legacy.BoolExpr) transformationManager.toTerm(assertion); solver.add(assertion, term); z3Marker.add(term); } @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(solver.getStatus() == SolverStatus.UNSAT, + checkState( + solver.getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof Z3ItpPattern); final Z3ItpPattern z3ItpPattern = (Z3ItpPattern) pattern; @@ -102,12 +104,13 @@ public Interpolant getInterpolant(final ItpPattern pattern) { final com.microsoft.z3legacy.Expr term = patternToTerm(z3ItpPattern.getRoot()); final com.microsoft.z3legacy.Params params = z3Context.mkParams(); - final com.microsoft.z3legacy.BoolExpr[] itpArray = z3Context.GetInterpolant(proof, term, params); + final com.microsoft.z3legacy.BoolExpr[] itpArray = + z3Context.GetInterpolant(proof, term, params); final List> itpList = new LinkedList<>(); for (final com.microsoft.z3legacy.BoolExpr itpTerm : itpArray) { - @SuppressWarnings("unchecked") final Expr itpExpr = (Expr) termTransformer.toExpr( - itpTerm); + @SuppressWarnings("unchecked") + final Expr itpExpr = (Expr) termTransformer.toExpr(itpTerm); itpList.add(itpExpr); } @@ -117,7 +120,8 @@ public Interpolant getInterpolant(final ItpPattern pattern) { return new Z3Interpolant(itpMap); } - private com.microsoft.z3legacy.BoolExpr patternToTerm(final ItpMarkerTree markerTree) { + private com.microsoft.z3legacy.BoolExpr patternToTerm( + final ItpMarkerTree markerTree) { final Collection opTerms = new LinkedList<>(); final Z3ItpMarker marker = (Z3ItpMarker) markerTree.getMarker(); @@ -128,15 +132,17 @@ private com.microsoft.z3legacy.BoolExpr patternToTerm(final ItpMarkerTree pattern, - final List> itpList, - final Map> itpMap) { + private void buildItpMapFormList( + final ItpMarkerTree pattern, + final List> itpList, + final Map> itpMap) { for (final ItpMarkerTree child : pattern.getChildren()) { buildItpMapFormList(child, itpList, itpMap); } @@ -206,4 +212,4 @@ public Collection> getAssertions() { public void close() { solver.close(); } -} \ No newline at end of file +} diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3LegacySolverFactory.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3LegacySolverFactory.java index 43964ed8a9..091e79615e 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3LegacySolverFactory.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3LegacySolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -31,8 +31,7 @@ public final class Z3LegacySolverFactory implements SolverFactory { INSTANCE = new Z3LegacySolverFactory(); } - private Z3LegacySolverFactory() { - } + private Z3LegacySolverFactory() {} public static Z3LegacySolverFactory getInstance() { return INSTANCE; @@ -58,12 +57,12 @@ public Solver createSolver() { final com.microsoft.z3legacy.Solver z3Solver = z3Context.mkSimpleSolver(); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3Solver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3Solver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } @Override @@ -72,12 +71,12 @@ public UCSolver createUCSolver() { final com.microsoft.z3legacy.Solver z3Solver = z3Context.mkSimpleSolver(); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3Solver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3Solver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } @Override @@ -86,12 +85,11 @@ public ItpSolver createItpSolver() { final com.microsoft.z3legacy.Solver z3Solver = z3Context.mkSimpleSolver(); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3ItpSolver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3ItpSolver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Solver.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Solver.java index 0a06cacc78..49e5dc4ab9 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Solver.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3Solver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.ImmutableList; import com.microsoft.z3legacy.FuncDecl; import com.microsoft.z3legacy.Status; @@ -32,15 +35,11 @@ import hu.bme.mit.theta.core.type.enumtype.EnumLitExpr; import hu.bme.mit.theta.core.type.enumtype.EnumType; import hu.bme.mit.theta.core.type.functype.FuncType; -import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.*; +import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; - import java.util.*; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - final class Z3Solver implements UCSolver, Solver { private final Z3SymbolTable symbolTable; @@ -60,10 +59,12 @@ final class Z3Solver implements UCSolver, Solver { private Collection> unsatCore; private SolverStatus status; - public Z3Solver(final Z3SymbolTable symbolTable, - final Z3TransformationManager transformationManager, - final Z3TermTransformer termTransformer, final com.microsoft.z3legacy.Context z3Context, - final com.microsoft.z3legacy.Solver z3Solver) { + public Z3Solver( + final Z3SymbolTable symbolTable, + final Z3TransformationManager transformationManager, + final Z3TermTransformer termTransformer, + final com.microsoft.z3legacy.Context z3Context, + final com.microsoft.z3legacy.Solver z3Solver) { this.symbolTable = symbolTable; this.transformationManager = transformationManager; this.termTransformer = termTransformer; @@ -79,8 +80,8 @@ public Z3Solver(final Z3SymbolTable symbolTable, @Override public void add(final Expr assertion) { checkNotNull(assertion); - final com.microsoft.z3legacy.BoolExpr term = (com.microsoft.z3legacy.BoolExpr) transformationManager.toTerm( - assertion); + final com.microsoft.z3legacy.BoolExpr term = + (com.microsoft.z3legacy.BoolExpr) transformationManager.toTerm(assertion); add(assertion, term); } @@ -95,8 +96,8 @@ public void track(final Expr assertion) { checkNotNull(assertion); assertions.add(assertion); - final com.microsoft.z3legacy.BoolExpr term = (com.microsoft.z3legacy.BoolExpr) transformationManager.toTerm( - assertion); + final com.microsoft.z3legacy.BoolExpr term = + (com.microsoft.z3legacy.BoolExpr) transformationManager.toTerm(assertion); final String label = String.format(ASSUMPTION_LABEL, labelNum++); final com.microsoft.z3legacy.BoolExpr labelTerm = z3Context.mkBoolConst(label); @@ -268,7 +269,8 @@ public Optional> eval(final Decl tVal = (LitExpr) val; + @SuppressWarnings("unchecked") + final LitExpr tVal = (LitExpr) val; return Optional.ofNullable(tVal); } @@ -289,14 +291,14 @@ private LitExpr extractLiteral(final ConstDecl extractFuncLiteral(final FuncDecl funcDecl) { - final Expr expr = termTransformer.toFuncLitExpr(funcDecl, z3Model, - new ArrayList<>()); + final Expr expr = + termTransformer.toFuncLitExpr(funcDecl, z3Model, new ArrayList<>()); return (LitExpr) expr; } private LitExpr extractArrayLiteral(final FuncDecl funcDecl) { - final Expr expr = termTransformer.toArrayLitExpr(funcDecl, z3Model, - new ArrayList<>()); + final Expr expr = + termTransformer.toArrayLitExpr(funcDecl, z3Model, new ArrayList<>()); return (LitExpr) expr; } @@ -309,7 +311,8 @@ private LitExpr extractBvConstLiteral(final FuncDecl funcDecl) { } } - private LitExpr extractEnumLiteral(final ConstDecl constDecl, final FuncDecl funcDecl) { + private LitExpr extractEnumLiteral( + final ConstDecl constDecl, final FuncDecl funcDecl) { final com.microsoft.z3legacy.Expr term = z3Model.getConstInterp(funcDecl); if (term == null) { return null; @@ -351,5 +354,4 @@ private Collection> constDeclsOf(final com.microsoft.z3legacy.Model return builder.build(); } } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverManager.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverManager.java index 312f8424e2..911c356dea 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverManager.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.solver.z3legacy; -import hu.bme.mit.theta.solver.*; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import hu.bme.mit.theta.solver.*; import java.util.HashSet; import java.util.Set; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - public final class Z3SolverManager extends SolverManager { private static final String NAME = "Z3"; @@ -30,8 +29,7 @@ public final class Z3SolverManager extends SolverManager { private boolean closed = false; private final Set instantiatedSolvers = new HashSet<>(); - private Z3SolverManager() { - } + private Z3SolverManager() {} public static Z3SolverManager create() { return new Z3SolverManager(); diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SymbolTable.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SymbolTable.java index 8d547037a2..d6dab17624 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SymbolTable.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3SymbolTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; import hu.bme.mit.theta.core.decl.ConstDecl; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - final class Z3SymbolTable { private final BiMap, com.microsoft.z3legacy.FuncDecl> constToSymbol; @@ -41,8 +41,8 @@ public boolean definesSymbol(final com.microsoft.z3legacy.FuncDecl symbol) { } public com.microsoft.z3legacy.FuncDecl getSymbol(final ConstDecl constDecl) { - checkArgument(definesConst(constDecl), "Declaration %s not found in symbol table", - constDecl); + checkArgument( + definesConst(constDecl), "Declaration %s not found in symbol table", constDecl); return constToSymbol.get(constDecl); } @@ -61,5 +61,4 @@ public void put(final ConstDecl constDecl, final com.microsoft.z3legacy.FuncD public void clear() { constToSymbol.clear(); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TermTransformer.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TermTransformer.java index ad0ae49302..eb81c43a05 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TermTransformer.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TermTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TransformationManager.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TransformationManager.java index fe64006472..c1fb3e4547 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TransformationManager.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TransformationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TypeTransformer.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TypeTransformer.java index 10beea35d3..4d3653ba70 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TypeTransformer.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/Z3TypeTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,13 +26,13 @@ import hu.bme.mit.theta.core.type.fptype.FpType; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.*; final class Z3TypeTransformer { @SuppressWarnings("unused") private final Z3TransformationManager transformer; + private final Context context; private final com.microsoft.z3legacy.BoolSort boolSort; @@ -63,26 +63,30 @@ public com.microsoft.z3legacy.Sort toSort(final Type type) { return realSort; } else if (type instanceof BvType) { final BvType bvType = (BvType) type; - final Optional bvSort = bvSorts.stream() - .filter(sort -> sort.getSize() == bvType.getSize()).findAny(); + final Optional bvSort = + bvSorts.stream().filter(sort -> sort.getSize() == bvType.getSize()).findAny(); if (bvSort.isPresent()) { return bvSort.get(); } else { - final com.microsoft.z3legacy.BitVecSort newBvSort = context.mkBitVecSort( - bvType.getSize()); + final com.microsoft.z3legacy.BitVecSort newBvSort = + context.mkBitVecSort(bvType.getSize()); bvSorts.add(newBvSort); return newBvSort; } } else if (type instanceof FpType) { final FpType fpType = (FpType) type; - final Optional fpSort = fpSorts.stream().filter( - sort -> sort.getEBits() == fpType.getExponent() - && sort.getSBits() == fpType.getSignificand()).findAny(); + final Optional fpSort = + fpSorts.stream() + .filter( + sort -> + sort.getEBits() == fpType.getExponent() + && sort.getSBits() == fpType.getSignificand()) + .findAny(); if (fpSort.isPresent()) { return fpSort.get(); } else { - final com.microsoft.z3legacy.FPSort newFpSort = context.mkFPSort(fpType.getExponent(), - fpType.getSignificand()); + final com.microsoft.z3legacy.FPSort newFpSort = + context.mkFPSort(fpType.getExponent(), fpType.getSignificand()); fpSorts.add(newFpSort); return newFpSort; } @@ -104,7 +108,10 @@ public void reset() { } private EnumSort createEnumSort(EnumType enumType) { - return context.mkEnumSort(enumType.getName(), enumType.getValues().stream().map(lit -> EnumType.makeLongName(enumType, lit)).toArray(String[]::new)); + return context.mkEnumSort( + enumType.getName(), + enumType.getValues().stream() + .map(lit -> EnumType.makeLongName(enumType, lit)) + .toArray(String[]::new)); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/package-info.java b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/package-info.java index e186ee5a37..f92445d3f4 100644 --- a/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/package-info.java +++ b/subprojects/solver/solver-z3-legacy/src/main/java/hu/bme/mit/theta/solver/z3legacy/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -14,10 +14,9 @@ * limitations under the License. */ /** - * This package contains the wrapper classes for Z3. Normally, only - * {@link hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory} should be used from this project to create - * solver instances. Then, the common interfaces should be preferred (e.g., - * {@link hu.bme.mit.theta.solver.Solver}). + * This package contains the wrapper classes for Z3. Normally, only {@link + * hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory} should be used from this project to + * create solver instances. Then, the common interfaces should be preferred (e.g., {@link + * hu.bme.mit.theta.solver.Solver}). */ - -package hu.bme.mit.theta.solver.z3legacy; \ No newline at end of file +package hu.bme.mit.theta.solver.z3legacy; diff --git a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/SolverUtilsTest.java b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/SolverUtilsTest.java index 8b6faf5471..800c17e642 100644 --- a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/SolverUtilsTest.java +++ b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/SolverUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Gt; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; @@ -23,15 +27,10 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.utils.SolverUtils; +import java.util.stream.Stream; import org.junit.Assert; import org.junit.Test; -import java.util.stream.Stream; - -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Gt; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - public class SolverUtilsTest { @Test @@ -49,5 +48,4 @@ public void testModels() { // Act models.limit(5).forEach(m -> Assert.assertTrue(((BoolLitExpr) (expr.eval(m))).getValue())); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolverTest.java b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolverTest.java index 250c7ec0a5..87e3b11603 100644 --- a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolverTest.java +++ b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ItpSolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,6 @@ */ package hu.bme.mit.theta.solver.z3legacy; -import com.google.common.collect.ImmutableList; -import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.decl.ParamDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.functype.FuncType; -import hu.bme.mit.theta.core.type.inttype.IntType; -import hu.bme.mit.theta.core.utils.ExprUtils; -import hu.bme.mit.theta.solver.Interpolant; -import hu.bme.mit.theta.solver.ItpMarker; -import hu.bme.mit.theta.solver.ItpPattern; -import hu.bme.mit.theta.solver.ItpSolver; -import hu.bme.mit.theta.solver.SolverStatus; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.decl.Decls.Param; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; @@ -49,6 +32,23 @@ import static hu.bme.mit.theta.solver.ItpMarkerTree.Subtree; import static hu.bme.mit.theta.solver.ItpMarkerTree.Tree; +import com.google.common.collect.ImmutableList; +import hu.bme.mit.theta.core.decl.ConstDecl; +import hu.bme.mit.theta.core.decl.ParamDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.functype.FuncType; +import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.core.utils.ExprUtils; +import hu.bme.mit.theta.solver.Interpolant; +import hu.bme.mit.theta.solver.ItpMarker; +import hu.bme.mit.theta.solver.ItpPattern; +import hu.bme.mit.theta.solver.ItpSolver; +import hu.bme.mit.theta.solver.SolverStatus; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + public final class Z3ItpSolverTest { ItpSolver solver; @@ -136,8 +136,8 @@ public void testTreeInterpolation() { final ItpMarker I3 = solver.createMarker(); final ItpMarker I4 = solver.createMarker(); final ItpMarker I5 = solver.createMarker(); - final ItpPattern pattern = solver.createTreePattern( - Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); + final ItpPattern pattern = + solver.createTreePattern(Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); solver.add(I1, Eq(a, Int(0))); solver.add(I2, Eq(a, b)); @@ -248,5 +248,4 @@ public void testPushPop() { System.out.println(itp.eval(A)); System.out.println("----------"); } - } diff --git a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ModelTest.java b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ModelTest.java index 74d74f9ada..1e9ec3dc1a 100644 --- a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ModelTest.java +++ b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3ModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverBVTest.java b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverBVTest.java index b0b9d8cfea..cd80afbd91 100644 --- a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverBVTest.java +++ b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverBVTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,22 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.BvTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.util.Collection; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public class Z3SolverBVTest { @@ -48,12 +47,11 @@ public class Z3SolverBVTest { @Parameters(name = "expr: {0}, expected: {1}, actual: {2}") public static Collection operations() { return Stream.concat( - BvTestUtils.BasicOperations().stream(), - Stream.concat( - BvTestUtils.BitvectorOperations().stream(), - BvTestUtils.RelationalOperations().stream() - ) - ).collect(Collectors.toUnmodifiableList()); + BvTestUtils.BasicOperations().stream(), + Stream.concat( + BvTestUtils.BitvectorOperations().stream(), + BvTestUtils.RelationalOperations().stream())) + .collect(Collectors.toUnmodifiableList()); } @Test @@ -65,16 +63,19 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check final Solver solver = Z3LegacySolverFactory.getInstance().createSolver(); diff --git a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverFPTest.java b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverFPTest.java index 2d6a20c27b..e5254bdcef 100644 --- a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverFPTest.java +++ b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverFPTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,16 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.fptype.FpLeqExpr; @@ -24,24 +34,13 @@ import hu.bme.mit.theta.core.utils.FpUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; +import java.util.stream.Collectors; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.kframework.mpfr.BigFloat; -import java.util.Collection; -import java.util.stream.Collectors; - -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class Z3SolverFPTest { @@ -68,16 +67,19 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check final Solver solver = Z3LegacySolverFactory.getInstance().createSolver(); @@ -93,10 +95,15 @@ public void testOperationEquals() { solver.add(EqExpr.create2(expected, actual)); } else { //noinspection unchecked - FpLeqExpr leq = Leq(Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), - FpUtils.bigFloatToFpLitExpr(new BigFloat("1e-2", - FpUtils.getMathContext((FpType) actual.getType(), RNE)), - (FpType) actual.getType())); + FpLeqExpr leq = + Leq( + Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), + FpUtils.bigFloatToFpLitExpr( + new BigFloat( + "1e-2", + FpUtils.getMathContext( + (FpType) actual.getType(), RNE)), + (FpType) actual.getType())); solver.add(leq); } } else { diff --git a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverTest.java b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverTest.java index beeac67625..7e79e8a914 100644 --- a/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverTest.java +++ b/subprojects/solver/solver-z3-legacy/src/test/java/hu/bme/mit/theta/solver/z3legacy/Z3SolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,25 @@ */ package hu.bme.mit.theta.solver.z3legacy; +import static com.google.common.collect.ImmutableList.of; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.ArrayInit; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.ParamDecl; @@ -36,31 +55,11 @@ import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.UCSolver; -import org.junit.Before; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; import java.util.Optional; - -import static com.google.common.collect.ImmutableList.of; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.ArrayInit; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; public final class Z3SolverTest { @@ -120,10 +119,12 @@ public void testFunc() { final ParamDecl px = Param("x", Int()); final Expr x = px.getRef(); - solver.add(BoolExprs.Forall(of(px), - BoolExprs.Imply(IntExprs.Leq(x, Int(0)), Eq(App(a, x), Int(0))))); - solver.add(BoolExprs.Forall(of(px), - BoolExprs.Imply(IntExprs.Geq(x, Int(1)), Eq(App(a, x), Int(1))))); + solver.add( + BoolExprs.Forall( + of(px), BoolExprs.Imply(IntExprs.Leq(x, Int(0)), Eq(App(a, x), Int(0))))); + solver.add( + BoolExprs.Forall( + of(px), BoolExprs.Imply(IntExprs.Geq(x, Int(1)), Eq(App(a, x), Int(1))))); // Act final SolverStatus status = solver.check(); @@ -226,8 +227,8 @@ public void testBV1() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cx.getRef(), cy.getRef())); SolverStatus status = solver.check(); @@ -243,7 +244,7 @@ public void testBV2() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); solver.add(BvExprs.Neq(cx.getRef(), cz.getRef())); SolverStatus status = solver.check(); @@ -263,9 +264,14 @@ public void testBV3() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Add(List.of(cx.getRef(), Bv(new boolean[]{false, false, false, true}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Add( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, false, true}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -284,9 +290,11 @@ public void testBV4() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Sub(cx.getRef(), Bv(new boolean[]{false, false, false, true})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Sub(cx.getRef(), Bv(new boolean[] {false, false, false, true})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -305,7 +313,7 @@ public void testBV5() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Neg(cx.getRef()))); SolverStatus status = solver.check(); @@ -325,9 +333,14 @@ public void testBV6() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Mul(List.of(cx.getRef(), Bv(new boolean[]{false, false, true, false}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Mul( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, true, false}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -346,8 +359,8 @@ public void testBV7() { solver.push(); - solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[]{true, true, true, true}))); - solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[]{true, true, true, true}))); + solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[] {true, true, true, true}))); + solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[] {true, true, true, true}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -366,9 +379,11 @@ public void testBV8() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{true, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.SMod(cx.getRef(), Bv(new boolean[]{false, true, false, false})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {true, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.SMod(cx.getRef(), Bv(new boolean[] {false, true, false, false})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -387,9 +402,11 @@ public void testBV9() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Or(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{true, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Or(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {true, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -408,9 +425,11 @@ public void testBV10() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.And(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.And(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -429,9 +448,11 @@ public void testBV11() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -450,10 +471,12 @@ public void testBV12() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq( - BvExprs.ArithShiftRight(cy.getRef(), Bv(new boolean[]{false, false, false, true})), - cx.getRef())); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.ArithShiftRight( + cy.getRef(), Bv(new boolean[] {false, false, false, true})), + cx.getRef())); SolverStatus status = solver.check(); assertTrue(status.isSat()); diff --git a/subprojects/solver/solver-z3/build.gradle.kts b/subprojects/solver/solver-z3/build.gradle.kts index c174647f4d..d6f6ba9d3d 100644 --- a/subprojects/solver/solver-z3/build.gradle.kts +++ b/subprojects/solver/solver-z3/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3DeclTransformer.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3DeclTransformer.java index ba9881ded1..49e6b50490 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3DeclTransformer.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3DeclTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.solver.z3; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.collect.ImmutableList; import com.microsoft.z3.Context; import hu.bme.mit.theta.common.Tuple2; @@ -22,11 +24,8 @@ import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.functype.FuncType; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; - final class Z3DeclTransformer { private final Z3TransformationManager transformer; @@ -35,8 +34,10 @@ final class Z3DeclTransformer { private int symbolCount; - Z3DeclTransformer(final Z3TransformationManager transformer, final Z3SymbolTable symbolTable, - final Context context) { + Z3DeclTransformer( + final Z3TransformationManager transformer, + final Z3SymbolTable symbolTable, + final Context context) { this.transformer = transformer; this.symbolTable = symbolTable; this.context = context; @@ -64,9 +65,10 @@ private com.microsoft.z3.FuncDecl transformConst(final ConstDecl decl) { final Type returnType = extractedTypes.get2(); final com.microsoft.z3.Sort returnSort = transformer.toSort(returnType); - final com.microsoft.z3.Sort[] paramSorts = paramTypes.stream() - .map(t -> transformer.toSort(t)) - .toArray(size -> new com.microsoft.z3.Sort[size]); + final com.microsoft.z3.Sort[] paramSorts = + paramTypes.stream() + .map(t -> transformer.toSort(t)) + .toArray(size -> new com.microsoft.z3.Sort[size]); symbol = context.mkFuncDecl(symbolNameFor(decl), paramSorts, returnSort); symbolTable.put(decl, symbol); @@ -87,8 +89,8 @@ private Tuple2, Type> extractTypes(final Type type) { final Tuple2, Type> subResult = extractTypes(resultType); final List paramTypes = subResult.get1(); final Type newResultType = subResult.get2(); - final List newParamTypes = ImmutableList.builder().add(paramType) - .addAll(paramTypes).build(); + final List newParamTypes = + ImmutableList.builder().add(paramType).addAll(paramTypes).build(); final Tuple2, Type> result = Tuple2.of(newParamTypes, newResultType); return result; @@ -100,5 +102,4 @@ private Tuple2, Type> extractTypes(final Type type) { private String symbolNameFor(final Decl decl) { return String.format("%s_%d", decl.getName(), symbolCount++); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ExprTransformer.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ExprTransformer.java index ceada6f538..ef8497d332 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ExprTransformer.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ExprTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,10 @@ */ package hu.bme.mit.theta.solver.z3; +import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; + import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableList; import com.microsoft.z3.*; import com.microsoft.z3.BitVecExpr; import com.microsoft.z3.BoolExpr; @@ -50,14 +51,11 @@ import hu.bme.mit.theta.core.type.rattype.*; import hu.bme.mit.theta.core.utils.BvUtils; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.stream.Stream; -import static hu.bme.mit.theta.core.utils.ExprUtils.extractFuncAndArgs; - final class Z3ExprTransformer { private static final int CACHE_SIZE = 1000; @@ -76,251 +74,148 @@ public Z3ExprTransformer(final Z3TransformationManager transformer, final Contex exprToTerm = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(); - table = DispatchTable.builder() - - // General - - .addCase(RefExpr.class, this::transformRef) - - .addCase(IteExpr.class, this::transformIte) - - // Boolean - - .addCase(FalseExpr.class, this::transformFalse) - - .addCase(TrueExpr.class, this::transformTrue) - - .addCase(NotExpr.class, this::transformNot) - - .addCase(ImplyExpr.class, this::transformImply) - - .addCase(IffExpr.class, this::transformIff) - - .addCase(XorExpr.class, this::transformXor) - - .addCase(AndExpr.class, this::transformAnd) - - .addCase(OrExpr.class, this::transformOr) - - .addCase(ExistsExpr.class, this::transformExists) - - .addCase(ForallExpr.class, this::transformForall) - - // Rationals - - .addCase(RatLitExpr.class, this::transformRatLit) - - .addCase(RatAddExpr.class, this::transformRatAdd) - - .addCase(RatSubExpr.class, this::transformRatSub) - - .addCase(RatPosExpr.class, this::transformRatPos) - - .addCase(RatNegExpr.class, this::transformRatNeg) - - .addCase(RatMulExpr.class, this::transformRatMul) - - .addCase(RatDivExpr.class, this::transformRatDiv) - - .addCase(RatEqExpr.class, this::transformRatEq) - - .addCase(RatNeqExpr.class, this::transformRatNeq) - - .addCase(RatGeqExpr.class, this::transformRatGeq) - - .addCase(RatGtExpr.class, this::transformRatGt) - - .addCase(RatLeqExpr.class, this::transformRatLeq) - - .addCase(RatLtExpr.class, this::transformRatLt) - - .addCase(RatToIntExpr.class, this::transformRatToInt) - - // Integers - - .addCase(IntLitExpr.class, this::transformIntLit) - - .addCase(IntAddExpr.class, this::transformIntAdd) - - .addCase(IntSubExpr.class, this::transformIntSub) - - .addCase(IntPosExpr.class, this::transformIntPos) - - .addCase(IntNegExpr.class, this::transformIntNeg) - - .addCase(IntMulExpr.class, this::transformIntMul) - - .addCase(IntDivExpr.class, this::transformIntDiv) - - .addCase(IntModExpr.class, this::transformIntMod) - - .addCase(IntRemExpr.class, this::transformIntRem) - - .addCase(IntEqExpr.class, this::transformIntEq) - - .addCase(IntNeqExpr.class, this::transformIntNeq) - - .addCase(IntGeqExpr.class, this::transformIntGeq) - - .addCase(IntGtExpr.class, this::transformIntGt) - - .addCase(IntLeqExpr.class, this::transformIntLeq) - - .addCase(IntLtExpr.class, this::transformIntLt) - - .addCase(IntToRatExpr.class, this::transformIntToRat) - - // Bitvectors - - .addCase(BvLitExpr.class, this::transformBvLit) - - .addCase(BvConcatExpr.class, this::transformBvConcat) - - .addCase(BvExtractExpr.class, this::transformBvExtract) - - .addCase(BvZExtExpr.class, this::transformBvZExt) - - .addCase(BvSExtExpr.class, this::transformBvSExt) - - .addCase(BvAddExpr.class, this::transformBvAdd) - - .addCase(BvSubExpr.class, this::transformBvSub) - - .addCase(BvPosExpr.class, this::transformBvPos) - - .addCase(BvSignChangeExpr.class, this::transformBvSignChange) - - .addCase(BvNegExpr.class, this::transformBvNeg) - - .addCase(BvMulExpr.class, this::transformBvMul) - - .addCase(BvUDivExpr.class, this::transformBvUDiv) - - .addCase(BvSDivExpr.class, this::transformBvSDiv) - - .addCase(BvSModExpr.class, this::transformBvSMod) - - .addCase(BvURemExpr.class, this::transformBvURem) - - .addCase(BvSRemExpr.class, this::transformBvSRem) - - .addCase(BvAndExpr.class, this::transformBvAnd) - - .addCase(BvOrExpr.class, this::transformBvOr) - - .addCase(BvXorExpr.class, this::transformBvXor) - - .addCase(BvNotExpr.class, this::transformBvNot) - - .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) - - .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) - - .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) - - .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) - - .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) - - .addCase(BvEqExpr.class, this::transformBvEq) - - .addCase(BvNeqExpr.class, this::transformBvNeq) - - .addCase(BvUGeqExpr.class, this::transformBvUGeq) - - .addCase(BvUGtExpr.class, this::transformBvUGt) - - .addCase(BvULeqExpr.class, this::transformBvULeq) - - .addCase(BvULtExpr.class, this::transformBvULt) - - .addCase(BvSGeqExpr.class, this::transformBvSGeq) - - .addCase(BvSGtExpr.class, this::transformBvSGt) - - .addCase(BvSLeqExpr.class, this::transformBvSLeq) - - .addCase(BvSLtExpr.class, this::transformBvSLt) - - // Floating points - - .addCase(FpLitExpr.class, this::transformFpLit) - - .addCase(FpAddExpr.class, this::transformFpAdd) - - .addCase(FpSubExpr.class, this::transformFpSub) - - .addCase(FpPosExpr.class, this::transformFpPos) - - .addCase(FpNegExpr.class, this::transformFpNeg) - - .addCase(FpMulExpr.class, this::transformFpMul) - - .addCase(FpDivExpr.class, this::transformFpDiv) - - .addCase(FpEqExpr.class, this::transformFpEq) - - .addCase(FpAssignExpr.class, this::transformFpAssign) - - .addCase(FpGeqExpr.class, this::transformFpGeq) - - .addCase(FpLeqExpr.class, this::transformFpLeq) - - .addCase(FpGtExpr.class, this::transformFpGt) - - .addCase(FpLtExpr.class, this::transformFpLt) - - .addCase(FpNeqExpr.class, this::transformFpNeq) - - .addCase(FpAbsExpr.class, this::transformFpAbs) - - .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) - - .addCase(FpMaxExpr.class, this::transformFpMax) - - .addCase(FpMinExpr.class, this::transformFpMin) - - .addCase(FpSqrtExpr.class, this::transformFpSqrt) - - .addCase(FpRemExpr.class, this::transformFpRem) - - .addCase(FpIsNanExpr.class, this::transformFpIsNan) - - .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) - - .addCase(FpFromBvExpr.class, this::transformFpFromBv) - - .addCase(FpToBvExpr.class, this::transformFpToBv) - - .addCase(FpToFpExpr.class, this::transformFpToFp) - - // Functions - - .addCase(FuncAppExpr.class, this::transformFuncApp) - - // Arrays - - .addCase(ArrayReadExpr.class, this::transformArrayRead) - - .addCase(ArrayWriteExpr.class, this::transformArrayWrite) - - .addCase(ArrayEqExpr.class, this::transformArrayEq) - - .addCase(ArrayNeqExpr.class, this::transformArrayNeq) - - .addCase(ArrayLitExpr.class, this::transformArrayLit) - - .addCase(ArrayInitExpr.class, this::transformArrayInit) - - // Enums - - .addCase(EnumLitExpr.class, this::transformEnumLit) - - .addCase(EnumEqExpr.class, this::transformEnumEq) - - .addCase(EnumNeqExpr.class, this::transformEnumNeq) - - .build(); + table = + DispatchTable.builder() + + // General + + .addCase(RefExpr.class, this::transformRef) + .addCase(IteExpr.class, this::transformIte) + + // Boolean + + .addCase(FalseExpr.class, this::transformFalse) + .addCase(TrueExpr.class, this::transformTrue) + .addCase(NotExpr.class, this::transformNot) + .addCase(ImplyExpr.class, this::transformImply) + .addCase(IffExpr.class, this::transformIff) + .addCase(XorExpr.class, this::transformXor) + .addCase(AndExpr.class, this::transformAnd) + .addCase(OrExpr.class, this::transformOr) + .addCase(ExistsExpr.class, this::transformExists) + .addCase(ForallExpr.class, this::transformForall) + + // Rationals + + .addCase(RatLitExpr.class, this::transformRatLit) + .addCase(RatAddExpr.class, this::transformRatAdd) + .addCase(RatSubExpr.class, this::transformRatSub) + .addCase(RatPosExpr.class, this::transformRatPos) + .addCase(RatNegExpr.class, this::transformRatNeg) + .addCase(RatMulExpr.class, this::transformRatMul) + .addCase(RatDivExpr.class, this::transformRatDiv) + .addCase(RatEqExpr.class, this::transformRatEq) + .addCase(RatNeqExpr.class, this::transformRatNeq) + .addCase(RatGeqExpr.class, this::transformRatGeq) + .addCase(RatGtExpr.class, this::transformRatGt) + .addCase(RatLeqExpr.class, this::transformRatLeq) + .addCase(RatLtExpr.class, this::transformRatLt) + .addCase(RatToIntExpr.class, this::transformRatToInt) + + // Integers + + .addCase(IntLitExpr.class, this::transformIntLit) + .addCase(IntAddExpr.class, this::transformIntAdd) + .addCase(IntSubExpr.class, this::transformIntSub) + .addCase(IntPosExpr.class, this::transformIntPos) + .addCase(IntNegExpr.class, this::transformIntNeg) + .addCase(IntMulExpr.class, this::transformIntMul) + .addCase(IntDivExpr.class, this::transformIntDiv) + .addCase(IntModExpr.class, this::transformIntMod) + .addCase(IntRemExpr.class, this::transformIntRem) + .addCase(IntEqExpr.class, this::transformIntEq) + .addCase(IntNeqExpr.class, this::transformIntNeq) + .addCase(IntGeqExpr.class, this::transformIntGeq) + .addCase(IntGtExpr.class, this::transformIntGt) + .addCase(IntLeqExpr.class, this::transformIntLeq) + .addCase(IntLtExpr.class, this::transformIntLt) + .addCase(IntToRatExpr.class, this::transformIntToRat) + + // Bitvectors + + .addCase(BvLitExpr.class, this::transformBvLit) + .addCase(BvConcatExpr.class, this::transformBvConcat) + .addCase(BvExtractExpr.class, this::transformBvExtract) + .addCase(BvZExtExpr.class, this::transformBvZExt) + .addCase(BvSExtExpr.class, this::transformBvSExt) + .addCase(BvAddExpr.class, this::transformBvAdd) + .addCase(BvSubExpr.class, this::transformBvSub) + .addCase(BvPosExpr.class, this::transformBvPos) + .addCase(BvSignChangeExpr.class, this::transformBvSignChange) + .addCase(BvNegExpr.class, this::transformBvNeg) + .addCase(BvMulExpr.class, this::transformBvMul) + .addCase(BvUDivExpr.class, this::transformBvUDiv) + .addCase(BvSDivExpr.class, this::transformBvSDiv) + .addCase(BvSModExpr.class, this::transformBvSMod) + .addCase(BvURemExpr.class, this::transformBvURem) + .addCase(BvSRemExpr.class, this::transformBvSRem) + .addCase(BvAndExpr.class, this::transformBvAnd) + .addCase(BvOrExpr.class, this::transformBvOr) + .addCase(BvXorExpr.class, this::transformBvXor) + .addCase(BvNotExpr.class, this::transformBvNot) + .addCase(BvShiftLeftExpr.class, this::transformBvShiftLeft) + .addCase(BvArithShiftRightExpr.class, this::transformBvArithShiftRight) + .addCase(BvLogicShiftRightExpr.class, this::transformBvLogicShiftRight) + .addCase(BvRotateLeftExpr.class, this::transformBvRotateLeft) + .addCase(BvRotateRightExpr.class, this::transformBvRotateRight) + .addCase(BvEqExpr.class, this::transformBvEq) + .addCase(BvNeqExpr.class, this::transformBvNeq) + .addCase(BvUGeqExpr.class, this::transformBvUGeq) + .addCase(BvUGtExpr.class, this::transformBvUGt) + .addCase(BvULeqExpr.class, this::transformBvULeq) + .addCase(BvULtExpr.class, this::transformBvULt) + .addCase(BvSGeqExpr.class, this::transformBvSGeq) + .addCase(BvSGtExpr.class, this::transformBvSGt) + .addCase(BvSLeqExpr.class, this::transformBvSLeq) + .addCase(BvSLtExpr.class, this::transformBvSLt) + + // Floating points + + .addCase(FpLitExpr.class, this::transformFpLit) + .addCase(FpAddExpr.class, this::transformFpAdd) + .addCase(FpSubExpr.class, this::transformFpSub) + .addCase(FpPosExpr.class, this::transformFpPos) + .addCase(FpNegExpr.class, this::transformFpNeg) + .addCase(FpMulExpr.class, this::transformFpMul) + .addCase(FpDivExpr.class, this::transformFpDiv) + .addCase(FpEqExpr.class, this::transformFpEq) + .addCase(FpAssignExpr.class, this::transformFpAssign) + .addCase(FpGeqExpr.class, this::transformFpGeq) + .addCase(FpLeqExpr.class, this::transformFpLeq) + .addCase(FpGtExpr.class, this::transformFpGt) + .addCase(FpLtExpr.class, this::transformFpLt) + .addCase(FpNeqExpr.class, this::transformFpNeq) + .addCase(FpAbsExpr.class, this::transformFpAbs) + .addCase(FpRoundToIntegralExpr.class, this::transformFpRoundToIntegral) + .addCase(FpMaxExpr.class, this::transformFpMax) + .addCase(FpMinExpr.class, this::transformFpMin) + .addCase(FpSqrtExpr.class, this::transformFpSqrt) + .addCase(FpRemExpr.class, this::transformFpRem) + .addCase(FpIsNanExpr.class, this::transformFpIsNan) + .addCase(FpIsInfiniteExpr.class, this::transformFpIsInfinite) + .addCase(FpFromBvExpr.class, this::transformFpFromBv) + .addCase(FpToBvExpr.class, this::transformFpToBv) + .addCase(FpToFpExpr.class, this::transformFpToFp) + + // Functions + + .addCase(FuncAppExpr.class, this::transformFuncApp) + + // Arrays + + .addCase(ArrayReadExpr.class, this::transformArrayRead) + .addCase(ArrayWriteExpr.class, this::transformArrayWrite) + .addCase(ArrayEqExpr.class, this::transformArrayEq) + .addCase(ArrayNeqExpr.class, this::transformArrayNeq) + .addCase(ArrayLitExpr.class, this::transformArrayLit) + .addCase(ArrayInitExpr.class, this::transformArrayInit) + + // Enums + + .addCase(EnumLitExpr.class, this::transformEnumLit) + .addCase(EnumEqExpr.class, this::transformEnumEq) + .addCase(EnumNeqExpr.class, this::transformEnumNeq) + .build(); } //// @@ -343,8 +238,8 @@ private com.microsoft.z3.Expr transformRef(final RefExpr expr) { final com.microsoft.z3.FuncDecl funcDecl = transformer.toSymbol(decl); return context.mkConst(funcDecl); } else if (decl instanceof ParamDecl) { - final com.microsoft.z3.FuncDecl funcDecl = (com.microsoft.z3.FuncDecl) env.eval( - DeclSymbol.of(decl)); + final com.microsoft.z3.FuncDecl funcDecl = + (com.microsoft.z3.FuncDecl) env.eval(DeclSymbol.of(decl)); return context.mkConst(funcDecl); } else { throw new UnsupportedOperationException( @@ -365,7 +260,6 @@ private com.microsoft.z3.Expr transformIte(final IteExpr expr) { private com.microsoft.z3.Expr transformFalse(final FalseExpr expr) { return context.mkFalse(); - } private com.microsoft.z3.Expr transformTrue(final TrueExpr expr) { @@ -396,16 +290,14 @@ private com.microsoft.z3.Expr transformXor(final XorExpr expr) { } private com.microsoft.z3.Expr transformAnd(final AndExpr expr) { - final BoolExpr[] opTerms = expr.getOps().stream() - .map(e -> (BoolExpr) toTerm(e)) - .toArray(BoolExpr[]::new); + final BoolExpr[] opTerms = + expr.getOps().stream().map(e -> (BoolExpr) toTerm(e)).toArray(BoolExpr[]::new); return context.mkAnd(opTerms); } private com.microsoft.z3.Expr transformOr(final OrExpr expr) { - final BoolExpr[] opTerms = expr.getOps().stream() - .map(e -> (BoolExpr) toTerm(e)) - .toArray(BoolExpr[]::new); + final BoolExpr[] opTerms = + expr.getOps().stream().map(e -> (BoolExpr) toTerm(e)).toArray(BoolExpr[]::new); return context.mkOr(opTerms); } @@ -460,17 +352,18 @@ private com.microsoft.z3.Expr transformRatLit(final RatLitExpr expr) { } private com.microsoft.z3.Expr transformRatAdd(final RatAddExpr expr) { - final com.microsoft.z3.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3.ArithExpr[]::new); + final com.microsoft.z3.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3.ArithExpr[]::new); return context.mkAdd(opTerms); } private com.microsoft.z3.Expr transformRatSub(final RatSubExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkSub(leftOpTerm, rightOpTerm); } @@ -484,17 +377,18 @@ private com.microsoft.z3.Expr transformRatNeg(final RatNegExpr expr) { } private com.microsoft.z3.Expr transformRatMul(final RatMulExpr expr) { - final com.microsoft.z3.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3.ArithExpr[]::new); + final com.microsoft.z3.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3.ArithExpr[]::new); return context.mkMul(opTerms); } private com.microsoft.z3.Expr transformRatDiv(final RatDivExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkDiv(leftOpTerm, rightOpTerm); } @@ -511,34 +405,34 @@ private com.microsoft.z3.Expr transformRatNeq(final RatNeqExpr expr) { } private com.microsoft.z3.Expr transformRatGeq(final RatGeqExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkGe(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformRatGt(final RatGtExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkGt(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformRatLeq(final RatLeqExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkLe(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformRatLt(final RatLtExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkLt(leftOpTerm, rightOpTerm); } @@ -556,17 +450,18 @@ private com.microsoft.z3.Expr transformIntLit(final IntLitExpr expr) { } private com.microsoft.z3.Expr transformIntAdd(final IntAddExpr expr) { - final com.microsoft.z3.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3.ArithExpr[]::new); + final com.microsoft.z3.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3.ArithExpr[]::new); return context.mkAdd(opTerms); } private com.microsoft.z3.Expr transformIntSub(final IntSubExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkSub(leftOpTerm, rightOpTerm); } @@ -580,33 +475,34 @@ private com.microsoft.z3.Expr transformIntNeg(final IntNegExpr expr) { } private com.microsoft.z3.Expr transformIntMul(final IntMulExpr expr) { - final com.microsoft.z3.ArithExpr[] opTerms = expr.getOps().stream() - .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) - .toArray(com.microsoft.z3.ArithExpr[]::new); + final com.microsoft.z3.ArithExpr[] opTerms = + expr.getOps().stream() + .map(e -> (com.microsoft.z3.ArithExpr) toTerm(e)) + .toArray(com.microsoft.z3.ArithExpr[]::new); return context.mkMul(opTerms); } private com.microsoft.z3.Expr transformIntDiv(final IntDivExpr expr) { - final com.microsoft.z3.IntExpr leftOpTerm = (com.microsoft.z3.IntExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.IntExpr rightOpTerm = (com.microsoft.z3.IntExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.IntExpr leftOpTerm = + (com.microsoft.z3.IntExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.IntExpr rightOpTerm = + (com.microsoft.z3.IntExpr) toTerm(expr.getRightOp()); return context.mkDiv(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformIntMod(final IntModExpr expr) { - final com.microsoft.z3.IntExpr leftOpTerm = (com.microsoft.z3.IntExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.IntExpr rightOpTerm = (com.microsoft.z3.IntExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.IntExpr leftOpTerm = + (com.microsoft.z3.IntExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.IntExpr rightOpTerm = + (com.microsoft.z3.IntExpr) toTerm(expr.getRightOp()); return context.mkMod(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformIntRem(final IntRemExpr expr) { - final com.microsoft.z3.IntExpr leftOpTerm = (com.microsoft.z3.IntExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.IntExpr rightOpTerm = (com.microsoft.z3.IntExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.IntExpr leftOpTerm = + (com.microsoft.z3.IntExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.IntExpr rightOpTerm = + (com.microsoft.z3.IntExpr) toTerm(expr.getRightOp()); return context.mkRem(leftOpTerm, rightOpTerm); } @@ -623,34 +519,34 @@ private com.microsoft.z3.Expr transformIntNeq(final IntNeqExpr expr) { } private com.microsoft.z3.Expr transformIntGeq(final IntGeqExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkGe(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformIntGt(final IntGtExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkGt(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformIntLeq(final IntLeqExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkLe(leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformIntLt(final IntLtExpr expr) { - final com.microsoft.z3.ArithExpr leftOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getLeftOp()); - final com.microsoft.z3.ArithExpr rightOpTerm = (com.microsoft.z3.ArithExpr) toTerm( - expr.getRightOp()); + final com.microsoft.z3.ArithExpr leftOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getLeftOp()); + final com.microsoft.z3.ArithExpr rightOpTerm = + (com.microsoft.z3.ArithExpr) toTerm(expr.getRightOp()); return context.mkLt(leftOpTerm, rightOpTerm); } @@ -664,8 +560,8 @@ private com.microsoft.z3.Expr transformIntToRat(final IntToRatExpr expr) { } private com.microsoft.z3.Expr transformBvLit(final BvLitExpr expr) { - return context.mkBV(BvUtils.neutralBvLitExprToBigInteger(expr).toString(), - expr.getType().getSize()); + return context.mkBV( + BvUtils.neutralBvLitExprToBigInteger(expr).toString(), expr.getType().getSize()); } private com.microsoft.z3.Expr transformBvEq(final BvEqExpr expr) { @@ -681,9 +577,8 @@ private com.microsoft.z3.Expr transformBvNeq(final BvNeqExpr expr) { } private com.microsoft.z3.Expr transformBvConcat(final BvConcatExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkConcat); } @@ -711,9 +606,8 @@ private com.microsoft.z3.Expr transformBvSExt(final BvSExtExpr expr) { } private com.microsoft.z3.Expr transformBvAdd(final BvAddExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVAdd); } @@ -738,9 +632,8 @@ private com.microsoft.z3.Expr transformBvNeg(final BvNegExpr expr) { } private com.microsoft.z3.Expr transformBvMul(final BvMulExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVMul); } @@ -781,25 +674,22 @@ private com.microsoft.z3.Expr transformBvSRem(final BvSRemExpr expr) { } private com.microsoft.z3.Expr transformBvAnd(final BvAndExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVAND); } private com.microsoft.z3.Expr transformBvOr(final BvOrExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVOR); } private com.microsoft.z3.Expr transformBvXor(final BvXorExpr expr) { - final BitVecExpr[] opTerms = expr.getOps().stream() - .map(e -> (BitVecExpr) toTerm(e)) - .toArray(BitVecExpr[]::new); + final BitVecExpr[] opTerms = + expr.getOps().stream().map(e -> (BitVecExpr) toTerm(e)).toArray(BitVecExpr[]::new); return Stream.of(opTerms).skip(1).reduce(opTerms[0], context::mkBVXOR); } @@ -906,25 +796,30 @@ private com.microsoft.z3.Expr transformBvSLt(final BvSLtExpr expr) { } private com.microsoft.z3.Expr transformFpLit(final FpLitExpr expr) { - return context.mkFP(context.mkBV(expr.getHidden() ? 1 : 0, 1), - (BitVecExpr) toTerm(expr.getExponent()), (BitVecExpr) toTerm(expr.getSignificand())); + return context.mkFP( + context.mkBV(expr.getHidden() ? 1 : 0, 1), + (BitVecExpr) toTerm(expr.getExponent()), + (BitVecExpr) toTerm(expr.getSignificand())); } private com.microsoft.z3.Expr transformFpAdd(final FpAddExpr expr) { - final FPExpr[] opTerms = expr.getOps().stream() - .map(e -> (FPExpr) toTerm(e)) - .toArray(FPExpr[]::new); + final FPExpr[] opTerms = + expr.getOps().stream().map(e -> (FPExpr) toTerm(e)).toArray(FPExpr[]::new); - return Stream.of(opTerms).skip(1).reduce(opTerms[0], - (op1, op2) -> context.mkFPAdd(transformFpRoundingMode(expr.getRoundingMode()), op1, - op2)); + return Stream.of(opTerms) + .skip(1) + .reduce( + opTerms[0], + (op1, op2) -> + context.mkFPAdd( + transformFpRoundingMode(expr.getRoundingMode()), op1, op2)); } private com.microsoft.z3.Expr transformFpSub(final FpSubExpr expr) { final FPExpr leftOpTerm = (FPExpr) toTerm(expr.getLeftOp()); final FPExpr rightOpTerm = (FPExpr) toTerm(expr.getRightOp()); - return context.mkFPSub(transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, - rightOpTerm); + return context.mkFPSub( + transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformFpPos(final FpPosExpr expr) { @@ -962,21 +857,24 @@ private com.microsoft.z3.Expr transformFpRoundToIntegral(final FpRoundToIntegral } private com.microsoft.z3.Expr transformFpMul(final FpMulExpr expr) { - final FPExpr[] opTerms = expr.getOps().stream() - .map(e -> (FPExpr) toTerm(e)) - .toArray(FPExpr[]::new); + final FPExpr[] opTerms = + expr.getOps().stream().map(e -> (FPExpr) toTerm(e)).toArray(FPExpr[]::new); - return Stream.of(opTerms).skip(1).reduce(opTerms[0], - (op1, op2) -> context.mkFPMul(transformFpRoundingMode(expr.getRoundingMode()), op1, - op2)); + return Stream.of(opTerms) + .skip(1) + .reduce( + opTerms[0], + (op1, op2) -> + context.mkFPMul( + transformFpRoundingMode(expr.getRoundingMode()), op1, op2)); } private com.microsoft.z3.Expr transformFpDiv(final FpDivExpr expr) { final FPExpr leftOpTerm = (FPExpr) toTerm(expr.getLeftOp()); final FPExpr rightOpTerm = (FPExpr) toTerm(expr.getRightOp()); - return context.mkFPDiv(transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, - rightOpTerm); + return context.mkFPDiv( + transformFpRoundingMode(expr.getRoundingMode()), leftOpTerm, rightOpTerm); } private com.microsoft.z3.Expr transformFpRem(final FpRemExpr expr) { @@ -1058,10 +956,13 @@ private com.microsoft.z3.Expr transformFpMin(final FpMinExpr expr) { private com.microsoft.z3.Expr transformFpFromBv(final FpFromBvExpr expr) { final BitVecExpr val = (BitVecExpr) toTerm(expr.getOp()); - final FPSort fpSort = context.mkFPSort(expr.getFpType().getExponent(), - expr.getFpType().getSignificand()); - return context.mkFPToFP(transformFpRoundingMode(expr.getRoundingMode()), val, fpSort, - expr.isSigned()); // TODO: is this OK? FP2FP when BV2FP is used? + final FPSort fpSort = + context.mkFPSort(expr.getFpType().getExponent(), expr.getFpType().getSignificand()); + return context.mkFPToFP( + transformFpRoundingMode(expr.getRoundingMode()), + val, + fpSort, + expr.isSigned()); // TODO: is this OK? FP2FP when BV2FP is used? } private com.microsoft.z3.Expr transformFpToBv(final FpToBvExpr expr) { @@ -1071,6 +972,7 @@ private com.microsoft.z3.Expr transformFpToBv(final FpToBvExpr expr) { return context.mkFPToBV(transformFpRoundingMode(expr.getRoundingMode()), op, size, sgn); } + /* * Arrays */ @@ -1078,20 +980,22 @@ private com.microsoft.z3.Expr transformFpToBv(final FpToBvExpr expr) { private com.microsoft.z3.Expr transformFpToFp(final FpToFpExpr expr) { final FPExpr op = (FPExpr) toTerm(expr.getOp()); - return context.mkFPToFP(transformFpRoundingMode(expr.getRoundingMode()), op, + return context.mkFPToFP( + transformFpRoundingMode(expr.getRoundingMode()), + op, new FPSort(context, expr.getExpBits(), expr.getSignBits())); } private com.microsoft.z3.Expr transformArrayRead(final ArrayReadExpr expr) { - final com.microsoft.z3.ArrayExpr arrayTerm = (com.microsoft.z3.ArrayExpr) toTerm( - expr.getArray()); + final com.microsoft.z3.ArrayExpr arrayTerm = + (com.microsoft.z3.ArrayExpr) toTerm(expr.getArray()); final com.microsoft.z3.Expr indexTerm = toTerm(expr.getIndex()); return context.mkSelect(arrayTerm, indexTerm); } private com.microsoft.z3.Expr transformArrayWrite(final ArrayWriteExpr expr) { - final com.microsoft.z3.ArrayExpr arrayTerm = (com.microsoft.z3.ArrayExpr) toTerm( - expr.getArray()); + final com.microsoft.z3.ArrayExpr arrayTerm = + (com.microsoft.z3.ArrayExpr) toTerm(expr.getArray()); final com.microsoft.z3.Expr indexTerm = toTerm(expr.getIndex()); final com.microsoft.z3.Expr elemTerm = toTerm(expr.getElem()); return context.mkStore(arrayTerm, indexTerm, elemTerm); @@ -1114,8 +1018,10 @@ private com.microsoft.z3.Expr transformArrayNeq(final ArrayNeqExpr expr) { */ private com.microsoft.z3.Expr transformArrayLit(final ArrayLitExpr expr) { - com.microsoft.z3.ArrayExpr running = context.mkConstArray( - transformer.toSort(expr.getType().getIndexType()), toTerm(expr.getElseElem())); + com.microsoft.z3.ArrayExpr running = + context.mkConstArray( + transformer.toSort(expr.getType().getIndexType()), + toTerm(expr.getElseElem())); for (Tuple2, ? extends Expr> elem : expr.getElements()) { running = context.mkStore(running, toTerm(elem.get1()), toTerm(elem.get2())); } @@ -1123,8 +1029,10 @@ private com.microsoft.z3.Expr transformArrayLit(final ArrayLitExpr expr) { } private com.microsoft.z3.Expr transformArrayInit(final ArrayInitExpr expr) { - com.microsoft.z3.ArrayExpr running = context.mkConstArray( - transformer.toSort(expr.getType().getIndexType()), toTerm(expr.getElseElem())); + com.microsoft.z3.ArrayExpr running = + context.mkConstArray( + transformer.toSort(expr.getType().getIndexType()), + toTerm(expr.getElseElem())); for (Tuple2, ? extends Expr> elem : expr.getElements()) { running = context.mkStore(running, toTerm(elem.get1()), toTerm(elem.get2())); } @@ -1139,9 +1047,8 @@ private com.microsoft.z3.Expr transformFuncApp(final FuncAppExpr expr) { final RefExpr ref = (RefExpr) func; final Decl decl = ref.getDecl(); final com.microsoft.z3.FuncDecl funcDecl = transformer.toSymbol(decl); - final com.microsoft.z3.Expr[] argTerms = args.stream() - .map(this::toTerm) - .toArray(com.microsoft.z3.Expr[]::new); + final com.microsoft.z3.Expr[] argTerms = + args.stream().map(this::toTerm).toArray(com.microsoft.z3.Expr[]::new); return context.mkApp(funcDecl, argTerms); } else if (func instanceof FuncLitExpr) { Expr replaced = func; @@ -1149,7 +1056,9 @@ private com.microsoft.z3.Expr transformFuncApp(final FuncAppExpr expr) { while (replaced instanceof FuncLitExpr) { final ParamDecl param = ((FuncLitExpr) replaced).getParam(); final Expr funcExpr = ((FuncLitExpr) replaced).getResult(); - replaced = ExprUtils.changeDecls(funcExpr, Map.of(param, ((RefExpr) args.get(i++)).getDecl())); + replaced = + ExprUtils.changeDecls( + funcExpr, Map.of(param, ((RefExpr) args.get(i++)).getDecl())); } return toTerm(replaced); } else { @@ -1160,7 +1069,8 @@ private com.microsoft.z3.Expr transformFuncApp(final FuncAppExpr expr) { private com.microsoft.z3.Expr transformEnumLit(final EnumLitExpr expr) { EnumType enumType = expr.getType(); - return ((EnumSort) transformer.toSort(enumType)).getConst(enumType.getIntValue(expr.getValue())); + return ((EnumSort) transformer.toSort(enumType)) + .getConst(enumType.getIntValue(expr.getValue())); } private com.microsoft.z3.Expr transformEnumEq(final EnumEqExpr expr) { @@ -1178,5 +1088,4 @@ private com.microsoft.z3.Expr transformEnumNeq(final EnumNeqExpr expr) { public void reset() { exprToTerm.invalidateAll(); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3HornSolver.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3HornSolver.java index 6753c87f41..a2c568c6bc 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3HornSolver.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3HornSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,55 +15,39 @@ */ package hu.bme.mit.theta.solver.z3; -import com.google.common.collect.ImmutableList; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.UnsafeApp; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.microsoft.z3.Context; -import com.microsoft.z3.FuncDecl; import com.microsoft.z3.Solver; -import com.microsoft.z3.Status; import com.microsoft.z3.Z3Exception; import com.microsoft.z3.enumerations.Z3_decl_kind; -import hu.bme.mit.theta.common.container.Containers; -import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; -import hu.bme.mit.theta.core.type.arraytype.ArrayType; import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.bvtype.BvLitExpr; -import hu.bme.mit.theta.core.type.bvtype.BvType; import hu.bme.mit.theta.core.type.functype.FuncType; import hu.bme.mit.theta.solver.HornSolver; import hu.bme.mit.theta.solver.ProofNode; import hu.bme.mit.theta.solver.ProofNode.Builder; import hu.bme.mit.theta.solver.SolverStatus; -import hu.bme.mit.theta.solver.Stack; -import hu.bme.mit.theta.solver.UCSolver; -import hu.bme.mit.theta.solver.UnknownSolverStatusException; -import hu.bme.mit.theta.solver.impl.StackImpl; - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; import java.util.Deque; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Optional; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.UnsafeApp; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; final class Z3HornSolver extends Z3Solver implements HornSolver { - public Z3HornSolver(Z3SymbolTable symbolTable, Z3TransformationManager transformationManager, Z3TermTransformer termTransformer, Context z3Context, Solver z3Solver) { + public Z3HornSolver( + Z3SymbolTable symbolTable, + Z3TransformationManager transformationManager, + Z3TermTransformer termTransformer, + Context z3Context, + Solver z3Solver) { super(symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } @@ -76,9 +60,11 @@ private Expr toProofExpr(com.microsoft.z3.Expr expr) { final var name = lastArg.getFuncDecl().getName().toString(); final var params = lastArg.getArgs(); final var paramValues = Arrays.stream(params).map(termTransformer::toExpr).toList(); - final List paramTypes = paramValues.stream().map(expr1 -> (Type) expr1.getType()).toList(); + final List paramTypes = + paramValues.stream().map(expr1 -> (Type) expr1.getType()).toList(); - final var funcType = paramTypes.stream().reduce(Bool(), (res, param) -> FuncType.of(param, res)); + final var funcType = + paramTypes.stream().reduce(Bool(), (res, param) -> FuncType.of(param, res)); final var decl = Const(name, funcType); Expr func = decl.getRef(); for (Expr paramValue : paramValues) { @@ -88,8 +74,8 @@ private Expr toProofExpr(com.microsoft.z3.Expr expr) { } /** - * This is a best-effort solution, hopefully would support (most) CHCs at least. - * Taken from https://github.com/ethereum/solidity/blob/5917fd82b3ca4cab5f817f78b8da8ebe409dd02e/libsmtutil/Z3CHCInterface.cpp#L130 + * This is a best-effort solution, hopefully would support (most) CHCs at least. Taken from + * https://github.com/ethereum/solidity/blob/5917fd82b3ca4cab5f817f78b8da8ebe409dd02e/libsmtutil/Z3CHCInterface.cpp#L130 * and adapted to the Java API. */ @Override @@ -113,7 +99,9 @@ public ProofNode getProof() { } final var proofNode = visited.get(proofNodeExpr.getId()); - if (proofNodeExpr.isApp() && proofNodeExpr.getFuncDecl().getDeclKind() == Z3_decl_kind.Z3_OP_PR_HYPER_RESOLVE) { + if (proofNodeExpr.isApp() + && proofNodeExpr.getFuncDecl().getDeclKind() + == Z3_decl_kind.Z3_OP_PR_HYPER_RESOLVE) { if (proofNodeExpr.getArgs().length > 0) { for (int i = 1; i < proofNodeExpr.getArgs().length - 1; ++i) { final var child = proofNodeExpr.getArgs()[i]; @@ -127,8 +115,6 @@ public ProofNode getProof() { } } - return rootBuilder.build(); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Interpolant.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Interpolant.java index e9c40763b4..f283528cc3 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Interpolant.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Interpolant.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,11 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Map; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Interpolant; import hu.bme.mit.theta.solver.ItpMarker; +import java.util.Map; final class Z3Interpolant implements Interpolant { @@ -39,5 +38,4 @@ public Expr eval(final ItpMarker marker) { checkNotNull(itpExpr); return itpExpr; } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpMarker.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpMarker.java index 2cf80408be..1e1a05ab53 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpMarker.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.solver.z3; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.Stack; import hu.bme.mit.theta.solver.impl.StackImpl; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - final class Z3ItpMarker implements ItpMarker { private final Stack> terms; @@ -48,5 +47,4 @@ public void pop(final int n) { public Collection> getTerms() { return terms.toCollection(); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpPattern.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpPattern.java index 581c537009..485de586bf 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpPattern.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpPattern.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,20 @@ */ package hu.bme.mit.theta.solver.z3; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + import com.google.common.collect.Lists; import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.ItpMarkerTree; import hu.bme.mit.theta.solver.ItpPattern; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - -public class Z3ItpPattern implements ItpPattern.Binary, - ItpPattern.Sequence, ItpPattern.Tree { +public class Z3ItpPattern + implements ItpPattern.Binary, + ItpPattern.Sequence, + ItpPattern.Tree { final ItpMarkerTree markerTree; @@ -89,11 +90,10 @@ public E visit(ItpPatternVisitor visitor) { } private boolean isBinary() { - return - markerTree != null && - markerTree.getChildrenNumber() == 1 && - markerTree.getChild(0) != null && - markerTree.getChild(0).getChildrenNumber() == 0; + return markerTree != null + && markerTree.getChildrenNumber() == 1 + && markerTree.getChild(0) != null + && markerTree.getChild(0).getChildrenNumber() == 0; } private boolean isSequence() { diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpSolver.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpSolver.java index 8fdac727a3..349fd5dfa9 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpSolver.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3ItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,12 @@ */ package hu.bme.mit.theta.solver.z3; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import com.microsoft.z3.Native; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.model.Valuation; @@ -40,11 +46,6 @@ import hu.bme.mit.theta.solver.smtlib.solver.parser.ThrowExceptionErrorListener; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTermTransformer; import hu.bme.mit.theta.solver.smtlib.solver.transformer.SmtLibTransformationManager; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.misc.Interval; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -53,12 +54,10 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.misc.Interval; final class Z3ItpSolver implements ItpSolver, Solver { @@ -71,26 +70,26 @@ final class Z3ItpSolver implements ItpSolver, Solver { private final Stack> declarationStack; - private final GenericSmtLibSymbolTable smtLibSymbolTable; private final SmtLibTransformationManager smtLibTransformationManager; private final SmtLibTermTransformer smtLibTermTransformer; - public Z3ItpSolver(final Z3SymbolTable symbolTable, - final Z3TransformationManager transformationManager, - final Z3TermTransformer termTransformer, - final com.microsoft.z3.Context z3Context, - final com.microsoft.z3.Solver z3Solver) { + public Z3ItpSolver( + final Z3SymbolTable symbolTable, + final Z3TransformationManager transformationManager, + final Z3TermTransformer termTransformer, + final com.microsoft.z3.Context z3Context, + final com.microsoft.z3.Solver z3Solver) { this.transformationManager = transformationManager; this.z3Context = z3Context; - solver = new Z3Solver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + solver = + new Z3Solver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); markers = new StackImpl<>(); declarationStack = new StackImpl<>(); - smtLibSymbolTable = new GenericSmtLibSymbolTable(); smtLibTransformationManager = new GenericSmtLibTransformationManager(smtLibSymbolTable); smtLibTermTransformer = new GenericSmtLibTermTransformer(smtLibSymbolTable); @@ -115,15 +114,16 @@ public void add(final ItpMarker marker, final Expr assertion) { checkNotNull(assertion); checkArgument(markers.toCollection().contains(marker), "Marker not found in solver"); final Z3ItpMarker z3Marker = (Z3ItpMarker) marker; - final com.microsoft.z3.BoolExpr term = (com.microsoft.z3.BoolExpr) transformationManager.toTerm( - assertion); + final com.microsoft.z3.BoolExpr term = + (com.microsoft.z3.BoolExpr) transformationManager.toTerm(assertion); solver.add(assertion, term); z3Marker.add(assertion); } @Override public Interpolant getInterpolant(final ItpPattern pattern) { - checkState(solver.getStatus() == SolverStatus.UNSAT, + checkState( + solver.getStatus() == SolverStatus.UNSAT, "Cannot get interpolant if status is not UNSAT."); checkArgument(pattern instanceof Z3ItpPattern); final Z3ItpPattern z3ItpPattern = (Z3ItpPattern) pattern; @@ -139,29 +139,45 @@ public Interpolant getInterpolant(final ItpPattern pattern) { if (B.size() != 0) { final var localConstDecls = new LinkedHashSet>(); - final var aTerm = A.stream().flatMap(m -> m.getTerms().stream()) - .peek(boolTypeExpr -> localConstDecls.addAll(ExprUtils.getConstants(boolTypeExpr))) - .map(smtLibTransformationManager::toTerm); - final var bTerm = B.stream().flatMap(m -> m.getTerms().stream()) - .peek(boolTypeExpr -> localConstDecls.addAll(ExprUtils.getConstants(boolTypeExpr))) - .map(smtLibTransformationManager::toTerm); - - final var smtLibString = String.format("(get-interpolant (and %s) (and %s))", - aTerm.collect(Collectors.joining(" ")), - bTerm.collect(Collectors.joining(" "))); + final var aTerm = + A.stream() + .flatMap(m -> m.getTerms().stream()) + .peek( + boolTypeExpr -> + localConstDecls.addAll( + ExprUtils.getConstants(boolTypeExpr))) + .map(smtLibTransformationManager::toTerm); + final var bTerm = + B.stream() + .flatMap(m -> m.getTerms().stream()) + .peek( + boolTypeExpr -> + localConstDecls.addAll( + ExprUtils.getConstants(boolTypeExpr))) + .map(smtLibTransformationManager::toTerm); + + final var smtLibString = + String.format( + "(get-interpolant (and %s) (and %s))", + aTerm.collect(Collectors.joining(" ")), + bTerm.collect(Collectors.joining(" "))); localConstDecls.removeAll(declarationStack.toCollection()); declarationStack.add(localConstDecls); - final var smtLibDeclString = localConstDecls.stream() - .map(smtLibSymbolTable::getDeclaration) - .collect(Collectors.joining(" ")); + final var smtLibDeclString = + localConstDecls.stream() + .map(smtLibSymbolTable::getDeclaration) + .collect(Collectors.joining(" ")); Native.evalSmtlib2String(z3Context.nCtx(), smtLibDeclString); final var response = Native.evalSmtlib2String(z3Context.nCtx(), smtLibString); - itpMap.put(marker, - smtLibTermTransformer.toExpr(parseItpResponse(response), Bool(), + itpMap.put( + marker, + smtLibTermTransformer.toExpr( + parseItpResponse(response), + Bool(), new SmtLibModel(Collections.emptyMap()))); } else { itpMap.put(marker, False()); @@ -190,7 +206,8 @@ private static String parseItpResponse(final String response) { } private static String extractString(final ParserRuleContext ctx) { - return ctx.start.getInputStream() + return ctx.start + .getInputStream() .getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())); } @@ -218,7 +235,7 @@ public void push() { for (final Z3ItpMarker marker : markers) { marker.push(); } -// declarationStack.push(); + // declarationStack.push(); solver.push(); } @@ -228,7 +245,7 @@ public void pop(final int n) { for (final Z3ItpMarker marker : markers) { marker.pop(n); } -// declarationStack.pop(n); + // declarationStack.pop(n); solver.pop(n); } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Solver.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Solver.java index f3d6b95678..6fbf4fac56 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Solver.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3Solver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverFactory.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverFactory.java index dcf42464a9..3a2f040f3c 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverFactory.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,8 +22,6 @@ import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.UCSolver; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public final class Z3SolverFactory implements SolverFactory { private static final Z3SolverFactory INSTANCE; @@ -33,8 +31,7 @@ public final class Z3SolverFactory implements SolverFactory { INSTANCE = new Z3SolverFactory(); } - private Z3SolverFactory() { - } + private Z3SolverFactory() {} public static Z3SolverFactory getInstance() { return INSTANCE; @@ -60,12 +57,12 @@ public Solver createSolver() { final com.microsoft.z3.Solver z3Solver = z3Context.mkSimpleSolver(); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3Solver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3Solver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } @Override @@ -74,12 +71,12 @@ public UCSolver createUCSolver() { final com.microsoft.z3.Solver z3Solver = z3Context.mkSimpleSolver(); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3Solver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3Solver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } @Override @@ -88,12 +85,12 @@ public ItpSolver createItpSolver() { final com.microsoft.z3.Solver z3Solver = z3Context.mkSimpleSolver(); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3ItpSolver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3ItpSolver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } public HornSolver createHornSolver() { @@ -102,12 +99,11 @@ public HornSolver createHornSolver() { final com.microsoft.z3.Solver z3Solver = z3Context.mkSolver("HORN"); final Z3SymbolTable symbolTable = new Z3SymbolTable(); - final Z3TransformationManager transformationManager = new Z3TransformationManager( - symbolTable, z3Context); + final Z3TransformationManager transformationManager = + new Z3TransformationManager(symbolTable, z3Context); final Z3TermTransformer termTransformer = new Z3TermTransformer(symbolTable); - return new Z3HornSolver(symbolTable, transformationManager, termTransformer, z3Context, - z3Solver); + return new Z3HornSolver( + symbolTable, transformationManager, termTransformer, z3Context, z3Solver); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverManager.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverManager.java index 75a64916e2..992652eef5 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverManager.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SolverManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.solver.z3; -import hu.bme.mit.theta.solver.*; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; +import hu.bme.mit.theta.solver.*; import java.util.HashSet; import java.util.Set; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - public final class Z3SolverManager extends SolverManager { private static final String NAME = "Z3:4.13"; @@ -30,8 +29,7 @@ public final class Z3SolverManager extends SolverManager { private boolean closed = false; private final Set instantiatedSolvers = new HashSet<>(); - private Z3SolverManager() { - } + private Z3SolverManager() {} public static Z3SolverManager create() { return new Z3SolverManager(); diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SymbolTable.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SymbolTable.java index c699ad4a3e..88388200dd 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SymbolTable.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3SymbolTable.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,7 +22,6 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; - import hu.bme.mit.theta.core.decl.ConstDecl; final class Z3SymbolTable { @@ -42,8 +41,8 @@ public boolean definesSymbol(final com.microsoft.z3.FuncDecl symbol) { } public com.microsoft.z3.FuncDecl getSymbol(final ConstDecl constDecl) { - checkArgument(definesConst(constDecl), "Declaration %s not found in symbol table", - constDecl); + checkArgument( + definesConst(constDecl), "Declaration %s not found in symbol table", constDecl); return constToSymbol.get(constDecl); } @@ -62,5 +61,4 @@ public void put(final ConstDecl constDecl, final com.microsoft.z3.FuncDecl sy public void clear() { constToSymbol.clear(); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TermTransformer.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TermTransformer.java index c91c77d0d1..d9357afd0c 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TermTransformer.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TermTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,25 @@ */ package hu.bme.mit.theta.solver.z3; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static hu.bme.mit.theta.common.Utils.head; +import static hu.bme.mit.theta.common.Utils.tail; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.UnsafeApp; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static java.lang.String.format; + import com.google.common.collect.ImmutableList; import com.microsoft.z3.ArrayExpr; import com.microsoft.z3.ArraySort; @@ -65,8 +84,6 @@ import hu.bme.mit.theta.core.utils.BvUtils; import hu.bme.mit.theta.core.utils.FpUtils; import hu.bme.mit.theta.core.utils.TypeUtils; -import org.kframework.mpfr.BigFloat; - import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; @@ -78,32 +95,15 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static hu.bme.mit.theta.common.Utils.head; -import static hu.bme.mit.theta.common.Utils.tail; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.UnsafeApp; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static java.lang.String.format; +import org.kframework.mpfr.BigFloat; final class Z3TermTransformer { private static final String PARAM_NAME_FORMAT = "_p%d"; private final Z3SymbolTable symbolTable; - private final Map>, Expr>> environment; + private final Map>, Expr>> + environment; public Z3TermTransformer(final Z3SymbolTable symbolTable) { this.symbolTable = symbolTable; @@ -137,9 +137,10 @@ public Expr toExpr(final com.microsoft.z3.Expr term) { return transform(term, null, new ArrayList<>()); } - public Expr toFuncLitExpr(final FuncDecl funcDecl, final Model model, - final List> vars) { - checkNotNull(model, + public Expr toFuncLitExpr( + final FuncDecl funcDecl, final Model model, final List> vars) { + checkNotNull( + model, "Unsupported function '" + funcDecl.getName() + "' in Z3 back-transformation."); final com.microsoft.z3.FuncInterp funcInterp = model.getFuncInterp(funcDecl); final List> paramDecls = transformParams(vars, funcDecl.getDomain()); @@ -149,11 +150,11 @@ public Expr toFuncLitExpr(final FuncDecl funcDecl, final Model model, return funcLitExpr; } - public Expr toArrayLitExpr(final FuncDecl funcDecl, final Model model, - final List> vars) { + public Expr toArrayLitExpr( + final FuncDecl funcDecl, final Model model, final List> vars) { final com.microsoft.z3.FuncInterp funcInterp = model.getFuncInterp(funcDecl); - final List>, Expr>> entryExprs = createEntryExprs(funcInterp, model, - vars); + final List>, Expr>> entryExprs = + createEntryExprs(funcInterp, model, vars); final Expr elseExpr = transform(funcInterp.getElse(), model, vars); final ArraySort sort = (ArraySort) funcDecl.getRange(); @@ -161,27 +162,38 @@ public Expr toArrayLitExpr(final FuncDecl funcDecl, final Model model, return createArrayLitExpr(sort, entryExprs, elseExpr); } - private Expr createArrayLitExpr(ArraySort sort, - List>, Expr>> entryExprs, Expr elseExpr) { - return this.createIndexValueArrayLitExpr(transformSort(sort.getDomain()), - transformSort(sort.getRange()), entryExprs, elseExpr); + private Expr createArrayLitExpr( + ArraySort sort, List>, Expr>> entryExprs, Expr elseExpr) { + return this.createIndexValueArrayLitExpr( + transformSort(sort.getDomain()), + transformSort(sort.getRange()), + entryExprs, + elseExpr); } @SuppressWarnings("unchecked") - private Expr createIndexValueArrayLitExpr(I indexType, - E elemType, List>, Expr>> entryExprs, Expr elseExpr) { - return Array(entryExprs.stream().map(entry -> { - checkState(entry.get1().size() == 1); - return Tuple2.of((Expr) entry.get1().get(0), (Expr) entry.get2()); - }).collect(Collectors.toUnmodifiableList()), + private Expr createIndexValueArrayLitExpr( + I indexType, + E elemType, + List>, Expr>> entryExprs, + Expr elseExpr) { + return Array( + entryExprs.stream() + .map( + entry -> { + checkState(entry.get1().size() == 1); + return Tuple2.of( + (Expr) entry.get1().get(0), (Expr) entry.get2()); + }) + .collect(Collectors.toUnmodifiableList()), (Expr) elseExpr, ArrayType.of(indexType, elemType)); } //////// - private Expr transform(final com.microsoft.z3.Expr term, final Model model, - final List> vars) { + private Expr transform( + final com.microsoft.z3.Expr term, final Model model, final List> vars) { if (term.isIntNum()) { return transformIntLit(term); @@ -189,7 +201,8 @@ private Expr transform(final com.microsoft.z3.Expr term, final Model model, return transformRatLit(term); // BitVecNum is not BVNumeral? Potential bug? - } else if (/* term.isBVNumeral() */ term instanceof com.microsoft.z3.BitVecNum) { + } else if ( + /* term.isBVNumeral() */ term instanceof com.microsoft.z3.BitVecNum) { return transformBvLit(term); } else if (term instanceof FPNum) { @@ -233,12 +246,12 @@ private Expr transformRatLit(final com.microsoft.z3.Expr term) { return Rat(num, denom); } - private Expr transformArrLit(final com.microsoft.z3.Expr term, final Model model, - final List> vars) { + private Expr transformArrLit( + final com.microsoft.z3.Expr term, final Model model, final List> vars) { final ArrayExpr arrayExpr = (ArrayExpr) term; final ArraySort sort = (ArraySort) arrayExpr.getSort(); - return createArrayLitExpr(sort, Arrays.asList(), - transform(arrayExpr.getArgs()[0], model, vars)); + return createArrayLitExpr( + sort, Arrays.asList(), transform(arrayExpr.getArgs()[0], model, vars)); } private Expr transformBvLit(final com.microsoft.z3.Expr term) { @@ -254,11 +267,11 @@ private Expr transformFpLit(final com.microsoft.z3.Expr term) { FpType type = FpType.of((fpTerm).getEBits(), (fpTerm).getSBits()); String printed = term.toString(); if (printed.equals("+oo")) { - return FpUtils.bigFloatToFpLitExpr(BigFloat.positiveInfinity(type.getSignificand()), - type); + return FpUtils.bigFloatToFpLitExpr( + BigFloat.positiveInfinity(type.getSignificand()), type); } else if (printed.equals("-oo")) { - return FpUtils.bigFloatToFpLitExpr(BigFloat.negativeInfinity(type.getSignificand()), - type); + return FpUtils.bigFloatToFpLitExpr( + BigFloat.negativeInfinity(type.getSignificand()), type); } else if (printed.equals("NaN")) { return FpUtils.bigFloatToFpLitExpr(BigFloat.NaN(type.getSignificand()), type); } else if (printed.equals("+zero")) { @@ -266,24 +279,31 @@ private Expr transformFpLit(final com.microsoft.z3.Expr term) { } else if (printed.equals("-zero")) { return FpUtils.bigFloatToFpLitExpr(BigFloat.negativeZero(type.getSignificand()), type); } - BigFloat bigFloat = new BigFloat((fpTerm).getSignificand(), - FpUtils.getMathContext(type, FpRoundingMode.RNE)).multiply( - new BigFloat("2", FpUtils.getMathContext(type, FpRoundingMode.RNE)).pow( - new BigFloat((fpTerm).getExponent(true), - FpUtils.getMathContext(type, FpRoundingMode.RNE)), - FpUtils.getMathContext(type, FpRoundingMode.RNE)), - FpUtils.getMathContext(type, FpRoundingMode.RNE)); + BigFloat bigFloat = + new BigFloat( + (fpTerm).getSignificand(), + FpUtils.getMathContext(type, FpRoundingMode.RNE)) + .multiply( + new BigFloat("2", FpUtils.getMathContext(type, FpRoundingMode.RNE)) + .pow( + new BigFloat( + (fpTerm).getExponent(true), + FpUtils.getMathContext( + type, FpRoundingMode.RNE)), + FpUtils.getMathContext(type, FpRoundingMode.RNE)), + FpUtils.getMathContext(type, FpRoundingMode.RNE)); return FpUtils.bigFloatToFpLitExpr(bigFloat, type); } - private Expr transformEnumLit(final com.microsoft.z3.Expr term, final EnumType enumType) { + private Expr transformEnumLit( + final com.microsoft.z3.Expr term, final EnumType enumType) { String longName = term.getFuncDecl().getName().toString(); String literal = EnumType.getShortName(longName); return EnumLitExpr.of(enumType, literal); } - private Expr transformApp(final com.microsoft.z3.Expr term, final Model model, - final List> vars) { + private Expr transformApp( + final com.microsoft.z3.Expr term, final Model model, final List> vars) { final FuncDecl funcDecl = term.getFuncDecl(); final String symbol = funcDecl.getName().toString(); @@ -301,11 +321,15 @@ private Expr transformApp(final com.microsoft.z3.Expr term, final Model model } } - private Expr transformFuncInterp(final com.microsoft.z3.FuncInterp funcInterp, - final Model model, final List> vars) { + private Expr transformFuncInterp( + final com.microsoft.z3.FuncInterp funcInterp, + final Model model, + final List> vars) { checkArgument(funcInterp.getArity() >= 1); - final List> params = vars.subList(vars.size() - funcInterp.getArity(), vars.size()).stream() - .map(decl -> (ParamDecl) decl).collect(Collectors.toList()); + final List> params = + vars.subList(vars.size() - funcInterp.getArity(), vars.size()).stream() + .map(decl -> (ParamDecl) decl) + .collect(Collectors.toList()); Expr op = createFuncLitExprBody(params, funcInterp, model, vars); for (ParamDecl param : params) { op = Func(param, op); @@ -313,30 +337,33 @@ private Expr transformFuncInterp(final com.microsoft.z3.FuncInterp funcInterp return op; } - private Expr createFuncLitExprBody(final List> paramDecl, - final com.microsoft.z3.FuncInterp funcInterp, - final Model model, final List> vars) { - final List>, Expr>> entryExprs = createEntryExprs(funcInterp, model, - vars); + private Expr createFuncLitExprBody( + final List> paramDecl, + final com.microsoft.z3.FuncInterp funcInterp, + final Model model, + final List> vars) { + final List>, Expr>> entryExprs = + createEntryExprs(funcInterp, model, vars); final Expr elseExpr = transform(funcInterp.getElse(), model, vars); return createNestedIteExpr(paramDecl, entryExprs, elseExpr); } - private Expr createNestedIteExpr(final List> paramDecl, - final List>, Expr>> entryExprs, - final Expr elseExpr) { + private Expr createNestedIteExpr( + final List> paramDecl, + final List>, Expr>> entryExprs, + final Expr elseExpr) { if (entryExprs.isEmpty()) { return elseExpr; } else { final Tuple2>, Expr> head = head(entryExprs); - checkState(paramDecl.size() == head.get1().size(), - "Mismatched argument-parameter size!"); + checkState( + paramDecl.size() == head.get1().size(), "Mismatched argument-parameter size!"); final List>, Expr>> tail = tail(entryExprs); Expr cond = null; for (int i = 0; i < paramDecl.size(); i++) { - final Expr newTerm = EqExpr.create2(paramDecl.get(i).getRef(), - head.get1().get(i)); + final Expr newTerm = + EqExpr.create2(paramDecl.get(i).getRef(), head.get1().get(i)); cond = cond == null ? newTerm : And(cond, newTerm); } @@ -348,8 +375,10 @@ private Expr createNestedIteExpr(final List> paramDecl, private List>, Expr>> createEntryExprs( final com.microsoft.z3.FuncInterp funcInterp, - final Model model, final List> vars) { - final ImmutableList.Builder>, Expr>> builder = ImmutableList.builder(); + final Model model, + final List> vars) { + final ImmutableList.Builder>, Expr>> builder = + ImmutableList.builder(); for (final com.microsoft.z3.FuncInterp.Entry entry : funcInterp.getEntries()) { checkArgument(entry.getArgs().length >= 1); final List> args = new ArrayList<>(); @@ -364,8 +393,8 @@ private List>, Expr>> createEntryExprs( return builder.build(); } - private Expr transformQuantifier(final com.microsoft.z3.Quantifier term, final Model model, - final List> vars) { + private Expr transformQuantifier( + final com.microsoft.z3.Quantifier term, final Model model, final List> vars) { if (term.isUniversal()) { return transformForall(term, model, vars); @@ -383,25 +412,35 @@ private Expr transformVar(final com.microsoft.z3.Expr term, final List Expr transformFuncApp(final Expr expr, - final com.microsoft.z3.Expr[] argTerms, final Model model, final List> vars) { - final List terms = Arrays.stream(argTerms) - .collect(Collectors.toList()); + private

Expr transformFuncApp( + final Expr expr, + final com.microsoft.z3.Expr[] argTerms, + final Model model, + final List> vars) { + final List terms = + Arrays.stream(argTerms).collect(Collectors.toList()); return toApp((Expr>) expr, terms, model, vars); } - private

Expr toApp(Expr> expr, - List terms, Model model, List> vars) { + private

Expr toApp( + Expr> expr, + List terms, + Model model, + List> vars) { if (terms.size() == 0) { return expr; } - return UnsafeApp(expr, terms.stream().map(it -> transform(it, model, vars)).collect(Collectors.toUnmodifiableList())); + return UnsafeApp( + expr, + terms.stream() + .map(it -> transform(it, model, vars)) + .collect(Collectors.toUnmodifiableList())); } //// - private Expr transformForall(final com.microsoft.z3.Expr term, final Model model, - final List> vars) { + private Expr transformForall( + final com.microsoft.z3.Expr term, final Model model, final List> vars) { final com.microsoft.z3.Quantifier quantifier = (com.microsoft.z3.Quantifier) term; final com.microsoft.z3.BoolExpr opTerm = quantifier.getBody(); final com.microsoft.z3.Sort[] sorts = quantifier.getBoundVariableSorts(); @@ -414,8 +453,8 @@ private Expr transformForall(final com.microsoft.z3.Expr term, final Model mo return Forall(paramDecls, op); } - private Expr transformExists(final com.microsoft.z3.Expr term, final Model model, - final List> vars) { + private Expr transformExists( + final com.microsoft.z3.Expr term, final Model model, final List> vars) { final com.microsoft.z3.Quantifier quantifier = (com.microsoft.z3.Quantifier) term; final com.microsoft.z3.BoolExpr opTerm = quantifier.getBody(); final com.microsoft.z3.Sort[] sorts = quantifier.getBoundVariableSorts(); @@ -428,8 +467,8 @@ private Expr transformExists(final com.microsoft.z3.Expr term, final Model mo return Exists(paramDecls, op); } - private List> transformParams(final List> vars, - final com.microsoft.z3.Sort[] sorts) { + private List> transformParams( + final List> vars, final com.microsoft.z3.Sort[] sorts) { final ImmutableList.Builder> builder = ImmutableList.builder(); int parambase = vars.size(); for (final com.microsoft.z3.Sort sort : sorts) { @@ -440,8 +479,7 @@ private List> transformParams(final List> vars, return paramDecls; } - private ParamDecl transformParam(final List> vars, - final Sort sort, int i) { + private ParamDecl transformParam(final List> vars, final Sort sort, int i) { final Type type = transformSort(sort); final ParamDecl param = Param(format(PARAM_NAME_FORMAT, i), type); return param; @@ -472,8 +510,8 @@ private void popParams(final List> vars, final List> paramD } } - private Expr transformUnsupported(final com.microsoft.z3.Expr term, final Model model, - final List> vars) { + private Expr transformUnsupported( + final com.microsoft.z3.Expr term, final Model model, final List> vars) { throw new UnsupportedOperationException("Unsupported term: " + term); } @@ -506,16 +544,19 @@ private TriFunction>, Expr> exprBi if (args[0].getSort().getSortKind().equals(Z3_sort_kind.Z3_DATATYPE_SORT)) { // binary operator is on enum types // if either arg is a literal, we need special handling to get its type - // (references' decl kind is Z3_OP_UNINTERPRETED, literals' decl kind is Z3_OP_DT_CONSTRUCTOR) + // (references' decl kind is Z3_OP_UNINTERPRETED, literals' decl kind is + // Z3_OP_DT_CONSTRUCTOR) int litIndex = -1; for (int i = 0; i < 2; i++) { - if (args[i].getFuncDecl().getDeclKind().equals(Z3_decl_kind.Z3_OP_DT_CONSTRUCTOR)) - litIndex = i; + if (args[i].getFuncDecl() + .getDeclKind() + .equals(Z3_decl_kind.Z3_OP_DT_CONSTRUCTOR)) litIndex = i; } if (litIndex > -1) { int refIndex = Math.abs(litIndex - 1); final Expr refOp = transform(args[refIndex], model, vars); - final Expr litExpr = transformEnumLit(args[litIndex], (EnumType) refOp.getType()); + final Expr litExpr = + transformEnumLit(args[litIndex], (EnumType) refOp.getType()); return function.apply(refOp, litExpr); } } @@ -541,11 +582,11 @@ private TriFunction>, Expr> exprMu final Function>, Expr> function) { return (term, model, vars) -> { final com.microsoft.z3.Expr[] args = term.getArgs(); - final List> ops = Stream.of(args).map(arg -> transform(arg, model, vars)) - .collect(toImmutableList()); + final List> ops = + Stream.of(args) + .map(arg -> transform(arg, model, vars)) + .collect(toImmutableList()); return function.apply(ops); }; } - } - diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TransformationManager.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TransformationManager.java index 6e710bca81..d99fbc5cc3 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TransformationManager.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TransformationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,7 +16,6 @@ package hu.bme.mit.theta.solver.z3; import com.microsoft.z3.Context; - import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TypeTransformer.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TypeTransformer.java index 43f3133beb..7ef6b3fba1 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TypeTransformer.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/Z3TypeTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,13 +26,13 @@ import hu.bme.mit.theta.core.type.fptype.FpType; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatType; - import java.util.*; final class Z3TypeTransformer { @SuppressWarnings("unused") private final Z3TransformationManager transformer; + private final Context context; private final com.microsoft.z3.BoolSort boolSort; @@ -63,26 +63,30 @@ public com.microsoft.z3.Sort toSort(final Type type) { return realSort; } else if (type instanceof BvType) { final BvType bvType = (BvType) type; - final Optional bvSort = bvSorts.stream() - .filter(sort -> sort.getSize() == bvType.getSize()).findAny(); + final Optional bvSort = + bvSorts.stream().filter(sort -> sort.getSize() == bvType.getSize()).findAny(); if (bvSort.isPresent()) { return bvSort.get(); } else { - final com.microsoft.z3.BitVecSort newBvSort = context.mkBitVecSort( - bvType.getSize()); + final com.microsoft.z3.BitVecSort newBvSort = + context.mkBitVecSort(bvType.getSize()); bvSorts.add(newBvSort); return newBvSort; } } else if (type instanceof FpType) { final FpType fpType = (FpType) type; - final Optional fpSort = fpSorts.stream().filter( - sort -> sort.getEBits() == fpType.getExponent() - && sort.getSBits() == fpType.getSignificand()).findAny(); + final Optional fpSort = + fpSorts.stream() + .filter( + sort -> + sort.getEBits() == fpType.getExponent() + && sort.getSBits() == fpType.getSignificand()) + .findAny(); if (fpSort.isPresent()) { return fpSort.get(); } else { - final com.microsoft.z3.FPSort newFpSort = context.mkFPSort(fpType.getExponent(), - fpType.getSignificand()); + final com.microsoft.z3.FPSort newFpSort = + context.mkFPSort(fpType.getExponent(), fpType.getSignificand()); fpSorts.add(newFpSort); return newFpSort; } @@ -104,7 +108,10 @@ public void reset() { } private EnumSort createEnumSort(EnumType enumType) { - return context.mkEnumSort(enumType.getName(), enumType.getValues().stream().map(lit -> EnumType.makeLongName(enumType, lit)).toArray(String[]::new)); + return context.mkEnumSort( + enumType.getName(), + enumType.getValues().stream() + .map(lit -> EnumType.makeLongName(enumType, lit)) + .toArray(String[]::new)); } - } diff --git a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/package-info.java b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/package-info.java index 32c2cb3565..c07f804314 100644 --- a/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/package-info.java +++ b/subprojects/solver/solver-z3/src/main/java/hu/bme/mit/theta/solver/z3/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -14,10 +14,9 @@ * limitations under the License. */ /** - * This package contains the wrapper classes for Z3. Normally, only - * {@link hu.bme.mit.theta.solver.z3.Z3SolverFactory} should be used from this project to create - * solver instances. Then, the common interfaces should be preferred (e.g., - * {@link hu.bme.mit.theta.solver.Solver}). + * This package contains the wrapper classes for Z3. Normally, only {@link + * hu.bme.mit.theta.solver.z3.Z3SolverFactory} should be used from this project to create solver + * instances. Then, the common interfaces should be preferred (e.g., {@link + * hu.bme.mit.theta.solver.Solver}). */ - -package hu.bme.mit.theta.solver.z3; \ No newline at end of file +package hu.bme.mit.theta.solver.z3; diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/SolverUtilsTest.java b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/SolverUtilsTest.java index 61ad4340b9..cfde0692df 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/SolverUtilsTest.java +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/SolverUtilsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,19 +19,17 @@ import static hu.bme.mit.theta.core.type.inttype.IntExprs.Gt; import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import java.util.stream.Stream; - -import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; -import org.junit.Assert; -import org.junit.Test; - import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.solver.SolverFactory; import hu.bme.mit.theta.solver.utils.SolverUtils; +import java.util.stream.Stream; +import org.junit.Assert; +import org.junit.Test; public class SolverUtilsTest { @@ -50,5 +48,4 @@ public void testModels() { // Act models.limit(5).forEach(m -> Assert.assertTrue(((BoolLitExpr) (expr.eval(m))).getValue())); } - } 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 ea3b85aba6..fa4bd1bcfd 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ItpSolverTest.java b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ItpSolverTest.java index 26acbec183..55fc82c1ac 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ItpSolverTest.java +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ItpSolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,6 @@ */ package hu.bme.mit.theta.solver.z3; -import com.google.common.collect.ImmutableList; -import hu.bme.mit.theta.core.decl.ConstDecl; -import hu.bme.mit.theta.core.decl.ParamDecl; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.type.functype.FuncType; -import hu.bme.mit.theta.core.type.inttype.IntType; -import hu.bme.mit.theta.core.utils.ExprUtils; -import hu.bme.mit.theta.solver.Interpolant; -import hu.bme.mit.theta.solver.ItpMarker; -import hu.bme.mit.theta.solver.ItpPattern; -import hu.bme.mit.theta.solver.ItpSolver; -import hu.bme.mit.theta.solver.SolverStatus; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - import static hu.bme.mit.theta.core.decl.Decls.Const; import static hu.bme.mit.theta.core.decl.Decls.Param; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; @@ -49,6 +32,23 @@ import static hu.bme.mit.theta.solver.ItpMarkerTree.Subtree; import static hu.bme.mit.theta.solver.ItpMarkerTree.Tree; +import com.google.common.collect.ImmutableList; +import hu.bme.mit.theta.core.decl.ConstDecl; +import hu.bme.mit.theta.core.decl.ParamDecl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.BoolType; +import hu.bme.mit.theta.core.type.functype.FuncType; +import hu.bme.mit.theta.core.type.inttype.IntType; +import hu.bme.mit.theta.core.utils.ExprUtils; +import hu.bme.mit.theta.solver.Interpolant; +import hu.bme.mit.theta.solver.ItpMarker; +import hu.bme.mit.theta.solver.ItpPattern; +import hu.bme.mit.theta.solver.ItpSolver; +import hu.bme.mit.theta.solver.SolverStatus; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + public final class Z3ItpSolverTest { ItpSolver solver; @@ -129,15 +129,15 @@ public void testSequenceInterpolation() { System.out.println("----------"); } - //@Test + // @Test public void testTreeInterpolation() { final ItpMarker I1 = solver.createMarker(); final ItpMarker I2 = solver.createMarker(); final ItpMarker I3 = solver.createMarker(); final ItpMarker I4 = solver.createMarker(); final ItpMarker I5 = solver.createMarker(); - final ItpPattern pattern = solver.createTreePattern( - Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); + final ItpPattern pattern = + solver.createTreePattern(Tree(I3, Subtree(I1, Leaf(I4), Leaf(I5)), Leaf(I2))); solver.add(I1, Eq(a, Int(0))); solver.add(I2, Eq(a, b)); @@ -193,7 +193,7 @@ public void testLIA() { System.out.println("----------"); } - //@Test + // @Test public void testQuantifiers() { final ItpMarker A = solver.createMarker(); final ItpMarker B = solver.createMarker(); @@ -248,5 +248,4 @@ public void testPushPop() { System.out.println(itp.eval(A)); System.out.println("----------"); } - } diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ModelTest.java b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ModelTest.java index 0b6512d673..1698278c1d 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ModelTest.java +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3ModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,12 @@ */ package hu.bme.mit.theta.solver.z3; -import org.junit.Assert; -import org.junit.Test; - import com.microsoft.z3.BoolExpr; import com.microsoft.z3.Context; import com.microsoft.z3.Model; import com.microsoft.z3.Solver; +import org.junit.Assert; +import org.junit.Test; public final class Z3ModelTest { diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverBVTest.java b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverBVTest.java index fcf38f51cf..98cda667b3 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverBVTest.java +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverBVTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,21 +15,20 @@ */ package hu.bme.mit.theta.solver.z3; +import static org.junit.Assert.*; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.utils.BvTestUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.util.Collection; import java.util.stream.Collectors; import java.util.stream.Stream; - -import static org.junit.Assert.*; -import static org.junit.runners.Parameterized.Parameters; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public class Z3SolverBVTest { @@ -46,12 +45,11 @@ public class Z3SolverBVTest { @Parameters(name = "expr: {0}, expected: {1}, actual: {2}") public static Collection operations() { return Stream.concat( - BvTestUtils.BasicOperations().stream(), - Stream.concat( - BvTestUtils.BitvectorOperations().stream(), - BvTestUtils.RelationalOperations().stream() - ) - ).collect(Collectors.toUnmodifiableList()); + BvTestUtils.BasicOperations().stream(), + Stream.concat( + BvTestUtils.BitvectorOperations().stream(), + BvTestUtils.RelationalOperations().stream())) + .collect(Collectors.toUnmodifiableList()); } @Test @@ -63,16 +61,19 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check final Solver solver = Z3SolverFactory.getInstance().createSolver(); diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverFPTest.java b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverFPTest.java index 8d586eed85..21435233d8 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverFPTest.java +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverFPTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,16 @@ */ package hu.bme.mit.theta.solver.z3; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; +import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; +import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.runners.Parameterized.Parameters; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.abstracttype.EqExpr; import hu.bme.mit.theta.core.type.fptype.FpLeqExpr; @@ -24,24 +34,13 @@ import hu.bme.mit.theta.core.utils.FpUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; +import java.util.stream.Collectors; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.kframework.mpfr.BigFloat; -import java.util.Collection; -import java.util.stream.Collectors; - -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Abs; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.IsNan; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Leq; -import static hu.bme.mit.theta.core.type.fptype.FpExprs.Sub; -import static hu.bme.mit.theta.core.type.fptype.FpRoundingMode.RNE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.runners.Parameterized.Parameters; - @RunWith(Parameterized.class) public class Z3SolverFPTest { @@ -68,16 +67,19 @@ public void testOperationEquals() { // Type checks assertTrue( - "The type of actual is " + actual.getClass().getName() + " instead of " + "The type of actual is " + + actual.getClass().getName() + + " instead of " + exprType.getName(), - exprType.isInstance(actual) - ); + exprType.isInstance(actual)); assertEquals( - "The type of expected (" + expected.getType() + ") must match the type of actual (" - + actual.getType() + ")", + "The type of expected (" + + expected.getType() + + ") must match the type of actual (" + + actual.getType() + + ")", expected.getType(), - actual.getType() - ); + actual.getType()); // Equality check final Solver solver = Z3SolverFactory.getInstance().createSolver(); @@ -93,10 +95,15 @@ public void testOperationEquals() { solver.add(EqExpr.create2(expected, actual)); } else { //noinspection unchecked - FpLeqExpr leq = Leq(Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), - FpUtils.bigFloatToFpLitExpr(new BigFloat("1e-2", - FpUtils.getMathContext((FpType) actual.getType(), RNE)), - (FpType) actual.getType())); + FpLeqExpr leq = + Leq( + Abs(Sub(RNE, (FpLitExpr) expected, (Expr) actual)), + FpUtils.bigFloatToFpLitExpr( + new BigFloat( + "1e-2", + FpUtils.getMathContext( + (FpType) actual.getType(), RNE)), + (FpType) actual.getType())); solver.add(leq); } } else { diff --git a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverTest.java b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverTest.java index 0207529e58..023e958ab6 100644 --- a/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverTest.java +++ b/subprojects/solver/solver-z3/src/test/java/hu/bme/mit/theta/solver/z3/Z3SolverTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,25 @@ */ package hu.bme.mit.theta.solver.z3; +import static com.google.common.collect.ImmutableList.of; +import static hu.bme.mit.theta.core.decl.Decls.Const; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.ArrayInit; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; +import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; +import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.core.decl.ConstDecl; import hu.bme.mit.theta.core.decl.ParamDecl; @@ -36,31 +55,11 @@ import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.UCSolver; -import org.junit.Before; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; import java.util.Optional; - -import static com.google.common.collect.ImmutableList.of; -import static hu.bme.mit.theta.core.decl.Decls.Const; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.ArrayInit; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Read; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.Bv; -import static hu.bme.mit.theta.core.type.bvtype.BvExprs.BvType; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.App; -import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Eq; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; public final class Z3SolverTest { @@ -120,10 +119,12 @@ public void testFunc() { final ParamDecl px = Param("x", Int()); final Expr x = px.getRef(); - solver.add(BoolExprs.Forall(of(px), - BoolExprs.Imply(IntExprs.Leq(x, Int(0)), Eq(App(a, x), Int(0))))); - solver.add(BoolExprs.Forall(of(px), - BoolExprs.Imply(IntExprs.Geq(x, Int(1)), Eq(App(a, x), Int(1))))); + solver.add( + BoolExprs.Forall( + of(px), BoolExprs.Imply(IntExprs.Leq(x, Int(0)), Eq(App(a, x), Int(0))))); + solver.add( + BoolExprs.Forall( + of(px), BoolExprs.Imply(IntExprs.Geq(x, Int(1)), Eq(App(a, x), Int(1))))); // Act final SolverStatus status = solver.check(); @@ -136,7 +137,7 @@ public void testFunc() { assertEquals(ca.getType(), val.getType()); } - //@Test + // @Test public void testArray() { final ConstDecl> arr = Const("arr", Array(Int(), Int())); @@ -157,7 +158,7 @@ public void testArray() { assertEquals(Int(2), Read(valLit, Int(1)).eval(ImmutableValuation.empty())); } - //@Test + // @Test public void testArrayInit() { final ConstDecl> arr = Const("arr", Array(Int(), Int())); var elems = new ArrayList, Expr>>(); @@ -226,8 +227,8 @@ public void testBV1() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cx.getRef(), cy.getRef())); SolverStatus status = solver.check(); @@ -243,7 +244,7 @@ public void testBV2() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); solver.add(BvExprs.Neq(cx.getRef(), cz.getRef())); SolverStatus status = solver.check(); @@ -263,9 +264,14 @@ public void testBV3() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, false, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Add(List.of(cx.getRef(), Bv(new boolean[]{false, false, false, true}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, false, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Add( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, false, true}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -284,9 +290,11 @@ public void testBV4() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Sub(cx.getRef(), Bv(new boolean[]{false, false, false, true})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Sub(cx.getRef(), Bv(new boolean[] {false, false, false, true})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -305,7 +313,7 @@ public void testBV5() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); solver.add(BvExprs.Eq(cy.getRef(), BvExprs.Neg(cx.getRef()))); SolverStatus status = solver.check(); @@ -325,9 +333,14 @@ public void testBV6() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{false, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.Mul(List.of(cx.getRef(), Bv(new boolean[]{false, false, true, false}))))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {false, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.Mul( + List.of( + cx.getRef(), + Bv(new boolean[] {false, false, true, false}))))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -346,8 +359,8 @@ public void testBV7() { solver.push(); - solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[]{true, true, true, true}))); - solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[]{true, true, true, true}))); + solver.add(BvExprs.ULt(cx.getRef(), Bv(new boolean[] {true, true, true, true}))); + solver.add(BvExprs.ULt(cy.getRef(), Bv(new boolean[] {true, true, true, true}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -366,9 +379,11 @@ public void testBV8() { solver.push(); - solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[]{true, false, true, false}))); - solver.add(BvExprs.Eq(cy.getRef(), - BvExprs.SMod(cx.getRef(), Bv(new boolean[]{false, true, false, false})))); + solver.add(BvExprs.Eq(cx.getRef(), Bv(new boolean[] {true, false, true, false}))); + solver.add( + BvExprs.Eq( + cy.getRef(), + BvExprs.SMod(cx.getRef(), Bv(new boolean[] {false, true, false, false})))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -387,9 +402,11 @@ public void testBV9() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Or(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{true, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Or(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {true, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -408,9 +425,11 @@ public void testBV10() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.And(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.And(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -429,9 +448,11 @@ public void testBV11() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq(BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), - Bv(new boolean[]{false, true, false, false}))); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.Xor(List.of(cx.getRef(), cy.getRef())), + Bv(new boolean[] {false, true, false, false}))); SolverStatus status = solver.check(); assertTrue(status.isSat()); @@ -450,10 +471,12 @@ public void testBV12() { solver.push(); - solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[]{false, true, false, false}))); - solver.add(BvExprs.Eq( - BvExprs.ArithShiftRight(cy.getRef(), Bv(new boolean[]{false, false, false, true})), - cx.getRef())); + solver.add(BvExprs.Eq(cy.getRef(), Bv(new boolean[] {false, true, false, false}))); + solver.add( + BvExprs.Eq( + BvExprs.ArithShiftRight( + cy.getRef(), Bv(new boolean[] {false, false, false, true})), + cx.getRef())); SolverStatus status = solver.check(); assertTrue(status.isSat()); diff --git a/subprojects/solver/solver/build.gradle.kts b/subprojects/solver/solver/build.gradle.kts index 2e9867ccf0..204af496cf 100644 --- a/subprojects/solver/solver/build.gradle.kts +++ b/subprojects/solver/solver/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/HornSolver.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/HornSolver.java index 93f96b0fed..63e18c9f5d 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/HornSolver.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/HornSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,9 @@ import hu.bme.mit.theta.core.Relation; import hu.bme.mit.theta.core.Rule; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Collection; -/** - * The HornSolver can provide proofs, and accept Relations - */ +/** The HornSolver can provide proofs, and accept Relations */ public interface HornSolver extends Solver { default void add(Relation relation) { @@ -35,9 +30,7 @@ default void add(Collection relations) { add(relations.stream().flatMap(it -> it.getRules().stream().map(Rule::toExpr)).toList()); } - /** - * Get the proof found in the solver. - */ + /** Get the proof found in the solver. */ default ProofNode getProof() { throw new UnsupportedOperationException("Cannot get proof."); } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Interpolant.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Interpolant.java index 4f76ee1e25..717c557ffc 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Interpolant.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Interpolant.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -32,5 +32,4 @@ public interface Interpolant { * @return Expression */ Expr eval(final ItpMarker marker); - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarker.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarker.java index c1cfcfa905..999dcb60ee 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarker.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,4 @@ */ package hu.bme.mit.theta.solver; -public interface ItpMarker { - -} +public interface ItpMarker {} diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarkerTree.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarkerTree.java index e6a83079a9..4062ff9677 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarkerTree.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpMarkerTree.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -45,14 +45,14 @@ public int getChildrenNumber() { } @SafeVarargs - public static ItpMarkerTree Tree(final T marker, - final ItpMarkerTree... subtrees) { + public static ItpMarkerTree Tree( + final T marker, final ItpMarkerTree... subtrees) { return new ItpMarkerTree<>(marker, Arrays.asList(subtrees)); } @SafeVarargs - public static ItpMarkerTree Subtree(final T marker, - final ItpMarkerTree... subtrees) { + public static ItpMarkerTree Subtree( + final T marker, final ItpMarkerTree... subtrees) { return Tree(marker, subtrees); } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpPattern.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpPattern.java index 16ad4d913a..be3e2f3cd2 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpPattern.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpPattern.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,23 +17,19 @@ import java.util.List; -/** - * Interface for an element of an interpolation pattern. - */ +/** Interface for an element of an interpolation pattern. */ public interface ItpPattern { /** * ItpPatter visitor function * * @param visitor The visitor - * @param The return type of the visitor + * @param The return type of the visitor * @return Returns the result of the visitor */ E visit(final ItpPatternVisitor visitor); - /** - * Interface for a binary interpolation pattern - */ + /** Interface for a binary interpolation pattern */ interface Binary extends ItpPattern { T getA(); @@ -46,9 +42,7 @@ default E visit(final ItpPatternVisitor visitor) { } } - /** - * Interface for a sequence interpolation pattern - */ + /** Interface for a sequence interpolation pattern */ interface Sequence extends ItpPattern { List getSequence(); @@ -59,9 +53,7 @@ default E visit(final ItpPatternVisitor visitor) { } } - /** - * Interface for a tree interpolation pattern - */ + /** Interface for a tree interpolation pattern */ interface Tree extends ItpPattern { ItpMarkerTree getRoot(); @@ -80,5 +72,4 @@ interface ItpPatternVisitor { E visitTreePattern(final Tree treePattern); } - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpSolver.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpSolver.java index 1f7723c977..eaecca649e 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpSolver.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ItpSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.solver; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Arrays; import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - /** * An extension of the {@link Solver} interface, which also supports interpolation. It can create * {@link ItpMarker}s, and expressions can be added to these markers. The markers can form different @@ -88,7 +87,7 @@ default ItpPattern createSeqPattern(final List markers) { /** * Add an expression to the solver and the given marker. * - * @param marker Marker + * @param marker Marker * @param assertion Expression */ void add(final ItpMarker marker, final Expr assertion); @@ -96,7 +95,7 @@ default ItpPattern createSeqPattern(final List markers) { /** * Add a collection of expressions to the solver and the given marker. * - * @param marker Marker + * @param marker Marker * @param assertions Expression */ default void add(final ItpMarker marker, final Iterable> assertions) { @@ -108,8 +107,8 @@ default void add(final ItpMarker marker, final Iterable } /** - * Get the interpolant for the currently added expressions. Should only be called if - * {@link #check()} was already called and the result is UNSAT. + * Get the interpolant for the currently added expressions. Should only be called if {@link + * #check()} was already called and the result is UNSAT. * * @param pattern Pattern * @return Interpolant @@ -117,5 +116,4 @@ default void add(final ItpMarker marker, final Iterable Interpolant getInterpolant(final ItpPattern pattern); Collection getMarkers(); - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ProofNode.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ProofNode.java index 847816ce07..d7bd434328 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ProofNode.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/ProofNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,23 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.AndExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.ArrayList; import java.util.List; import java.util.StringJoiner; import java.util.stream.Stream; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - public record ProofNode(int id, Expr expr, List children) { public AndExpr toExpr() { - return And(Stream.concat(Stream.of(expr), children.stream().flatMap(it -> it.toExpr().getOps().stream())).toList()); + return And( + Stream.concat( + Stream.of(expr), + children.stream().flatMap(it -> it.toExpr().getOps().stream())) + .toList()); } public int depth() { @@ -40,9 +42,7 @@ public String toString() { final var sj = new StringJoiner(", "); children.stream().map(ProofNode::id).forEach(it -> sj.add(it.toString())); StringBuilder sb = new StringBuilder(); - sb.append(id). - append(": "). - append(expr.toString().replaceAll("[\r\n]", " ")); + sb.append(id).append(": ").append(expr.toString().replaceAll("[\r\n]", " ")); if (!children.isEmpty()) { sb.append(" -> ").append(sj); @@ -67,9 +67,7 @@ public Builder addChild(ProofNode.Builder child) { return this; } - /** - * This will fail for non-acyclic proofs, but we don't care, we should never have those. - */ + /** This will fail for non-acyclic proofs, but we don't care, we should never have those. */ public ProofNode build() { return build(0); } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Solver.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Solver.java index 5d1f79487c..8f97d1d21e 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Solver.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Solver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,12 +20,12 @@ /** * Common interface for SMT solvers. - *

- * Use the {@link #add(Expr)} methods to add expressions to the solver. Then use {@link #check()} + * + *

Use the {@link #add(Expr)} methods to add expressions to the solver. Then use {@link #check()} * method to check their satisfiability. The result can be queried by {@link #getStatus()}. If the * expressions are satisfiable, a satisfying assignment can be obtained by {@link #getModel()}. - *

- * The solver can also support incremental solving by {@link #push()} and {@link #pop()}. + * + *

The solver can also support incremental solving by {@link #push()} and {@link #pop()}. */ public interface Solver extends SolverBase { diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverBase.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverBase.java index e10ef15783..f7a0b6dc55 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverBase.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverFactory.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverFactory.java index cdcddc3f21..0922354160 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverFactory.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -50,5 +50,4 @@ public interface SolverFactory { default HornSolver createHornSolver() { throw new UnsupportedOperationException(); } - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverManager.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverManager.java index 0be9ec89f5..7d75e8c5d6 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverManager.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -40,9 +40,7 @@ public static SolverFactory resolveSolverFactory(final String name) throws Excep throw new UnsupportedOperationException("Solver " + name + " not supported"); } - /** - * Closes all SolverManager instances registered - */ + /** Closes all SolverManager instances registered */ public static void closeAll() throws Exception { for (final var solverManager : solverManagers) { solverManager.close(); @@ -53,5 +51,4 @@ public static void closeAll() throws Exception { public abstract boolean managesSolver(final String name); public abstract SolverFactory getSolverFactory(final String name) throws Exception; - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverPool.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverPool.java index 972313a3cb..63d8c24b46 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverPool.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverPool.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,17 +16,14 @@ package hu.bme.mit.theta.solver; import com.google.common.base.Preconditions; -import hu.bme.mit.theta.solver.Solver; -import hu.bme.mit.theta.solver.SolverFactory; - import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class SolverPool implements AutoCloseable { - private final static int STARTING_SIZE = 10; - private final static int GROWING = 5; + private static final int STARTING_SIZE = 10; + private static final int GROWING = 5; private int created = 0; @@ -64,8 +61,9 @@ public Solver requestSolver() { } public void returnSolver(Solver solver) { - Preconditions.checkState(solver.getAssertions().isEmpty(), "Only empty solvers can be returned"); -// System.out.println("Returned solver"); + Preconditions.checkState( + solver.getAssertions().isEmpty(), "Only empty solvers can be returned"); + // System.out.println("Returned solver"); this.available.add(solver); } @@ -75,8 +73,8 @@ private void createNewSolvers() { this.available.add(solver); this.all.add(solver); } -// System.out.println(created + " solvers created"); -// System.out.println("Free size: " + Runtime.getRuntime().freeMemory()); + // System.out.println(created + " solvers created"); + // System.out.println("Free size: " + Runtime.getRuntime().freeMemory()); this.created = created + GROWING; } @@ -86,13 +84,13 @@ public int size() { @Override public void close() throws Exception { -// System.out.println(all.size() - available.size() + " solvers not returned"); + // System.out.println(all.size() - available.size() + " solvers not returned"); if (closingMode == ClosingMode.ALL) { for (Solver solver : all) solver.close(); -// System.out.println("Closed " + all.size() + " solvers"); + // System.out.println("Closed " + all.size() + " solvers"); } else { for (Solver solver : available) solver.close(); -// System.out.println("Closed " + available.size() + " solvers"); + // System.out.println("Closed " + available.size() + " solvers"); } this.available.clear(); this.all.clear(); diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverStatus.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverStatus.java index 4d2db8bfae..8f4c630df7 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverStatus.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/SolverStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,7 +16,8 @@ package hu.bme.mit.theta.solver; public enum SolverStatus { - SAT(true), UNSAT(false); + SAT(true), + UNSAT(false); private final boolean sat; @@ -31,5 +32,4 @@ public boolean isSat() { public boolean isUnsat() { return !sat; } - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Stack.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Stack.java index f518ca85c5..2642a29328 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Stack.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/Stack.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -34,5 +34,4 @@ default void pop() { Collection toCollection(); void clear(); - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UCSolver.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UCSolver.java index 3af3fe53a7..83b0ecbb39 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UCSolver.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UCSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,18 +17,18 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Collection; /** * Common interface for SMT solvers with unsat core capabilities. - *

- * Use the {@link #track(Expr)} method to add expressions to the solver. Then use {@link #check()} - * method to check their satisfiability. The result can be queried by {@link #getStatus()}. If the - * expressions are satisfiable, a satisfying assignment can be obtained by {@link #getModel()}. If - * the expressions are not satisfiable, use {@link #getUnsatCore()} to obtain the unsat core. - *

- * The solver can also support incremental solving by {@link #push()} and {@link #pop()}. + * + *

Use the {@link #track(Expr)} method to add expressions to the solver. Then use {@link + * #check()} method to check their satisfiability. The result can be queried by {@link + * #getStatus()}. If the expressions are satisfiable, a satisfying assignment can be obtained by + * {@link #getModel()}. If the expressions are not satisfiable, use {@link #getUnsatCore()} to + * obtain the unsat core. + * + *

The solver can also support incremental solving by {@link #push()} and {@link #pop()}. */ public interface UCSolver extends SolverBase { diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UnknownSolverStatusException.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UnknownSolverStatusException.java index 9a4589d8f4..c7ffb6f0e8 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UnknownSolverStatusException.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/UnknownSolverStatusException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ public final class UnknownSolverStatusException extends RuntimeException { private static final long serialVersionUID = -7472824180590849943L; - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/NullSolver.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/NullSolver.java index db2636a5d4..805974bc7d 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/NullSolver.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/NullSolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,16 @@ */ package hu.bme.mit.theta.solver.impl; -import java.util.Collection; - import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; +import java.util.Collection; public final class NullSolver implements Solver { - private NullSolver() { - } + private NullSolver() {} private static class LazyHolder { @@ -81,5 +79,4 @@ public Collection> getAssertions() { public void close() throws Exception { throw new UnsupportedOperationException(); } - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/StackImpl.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/StackImpl.java index e9bcadc692..a050b2059c 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/StackImpl.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/impl/StackImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkArgument; +import hu.bme.mit.theta.solver.Stack; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import hu.bme.mit.theta.solver.Stack; - public class StackImpl implements Stack { public final List items; diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/package-info.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/package-info.java index d334cc0d25..74c8a5b56a 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/package-info.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,8 +16,7 @@ /** * This package contains the generic interfaces for SMT solvers. Use a concrete implementation of * {@link hu.bme.mit.theta.solver.SolverFactory} to create a {@link hu.bme.mit.theta.solver.Solver} - * or an {@link hu.bme.mit.theta.solver.ItpSolver} for interpolation. See - * {@link hu.bme.mit.theta.solver.Solver} for more information about using solvers. + * or an {@link hu.bme.mit.theta.solver.ItpSolver} for interpolation. See {@link + * hu.bme.mit.theta.solver.Solver} for more information about using solvers. */ - -package hu.bme.mit.theta.solver; \ No newline at end of file +package hu.bme.mit.theta.solver; diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/SolverUtils.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/SolverUtils.java index af11bdef51..980c02668a 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/SolverUtils.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/SolverUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,25 +18,23 @@ import static com.google.common.base.Preconditions.checkNotNull; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Function; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverFactory; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.function.Function; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; public final class SolverUtils { - private SolverUtils() { - } + private SolverUtils() {} - public static boolean entails(final Solver solver, final Expr antecedent, - final Expr consequent) { + public static boolean entails( + final Solver solver, final Expr antecedent, final Expr consequent) { checkNotNull(solver); checkNotNull(antecedent); checkNotNull(consequent); @@ -47,9 +45,10 @@ public static boolean entails(final Solver solver, final Expr antecede } } - public static boolean entails(final Solver solver, - final Iterable> antecedents, - final Iterable> consequents) { + public static boolean entails( + final Solver solver, + final Iterable> antecedents, + final Iterable> consequents) { checkNotNull(solver); checkNotNull(antecedents); checkNotNull(consequents); @@ -64,8 +63,10 @@ public static Stream models(final SolverFactory factory, final Expr Not(m.toExpr())); } - public static Stream models(final SolverFactory factory, final Expr expr, - final Function> feedback) { + public static Stream models( + final SolverFactory factory, + final Expr expr, + final Function> feedback) { final Iterable iterable = () -> new ModelIterator(factory, expr, feedback); return StreamSupport.stream(iterable.spliterator(), false); } @@ -75,8 +76,10 @@ private static final class ModelIterator implements Iterator { private final Solver solver; private final Function> feedback; - private ModelIterator(final SolverFactory factory, final Expr expr, - final Function> feedback) { + private ModelIterator( + final SolverFactory factory, + final Expr expr, + final Function> feedback) { checkNotNull(expr); checkNotNull(factory); this.feedback = checkNotNull(feedback); @@ -100,5 +103,4 @@ public Valuation next() { return model; } } - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/WithPushPop.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/WithPushPop.java index ea0444bf20..88388826a3 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/WithPushPop.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/utils/WithPushPop.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,12 +16,9 @@ package hu.bme.mit.theta.solver.utils; import hu.bme.mit.theta.solver.SolverBase; - import java.io.Closeable; -/** - * A helper class for automatic push and pop for solvers using the try-with-resources statement. - */ +/** A helper class for automatic push and pop for solvers using the try-with-resources statement. */ public class WithPushPop implements Closeable { private final SolverBase solver; @@ -35,5 +32,4 @@ public WithPushPop(final SolverBase solver) { public void close() { solver.pop(); } - } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/ItpSolverValidatorWrapper.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/ItpSolverValidatorWrapper.java index 2ced0b7dd7..10298f693c 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/ItpSolverValidatorWrapper.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/ItpSolverValidatorWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.validator; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; @@ -26,11 +27,8 @@ import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.SolverManager; import hu.bme.mit.theta.solver.SolverStatus; - import java.util.Collection; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public class ItpSolverValidatorWrapper implements ItpSolver { private final ItpSolver solver; diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidationException.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidationException.java index 410da44ea1..5e5ea7a1c6 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidationException.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidationException.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.validator; public class SolverValidationException extends RuntimeException { diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapper.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapper.java index 185263bf2e..682f6b6b84 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapper.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.validator; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverManager; import hu.bme.mit.theta.solver.SolverStatus; - import java.util.Collection; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public class SolverValidatorWrapper implements Solver { private final Solver solver; @@ -46,7 +44,8 @@ public SolverStatus check() { final Valuation model = solver.getModel(); for (Expr assertion : solver.getAssertions()) { if (!assertion.eval(model).equals(True())) { - throw new SolverValidationException("Solver problem: " + assertion + " not True over {" + model + "}"); + throw new SolverValidationException( + "Solver problem: " + assertion + " not True over {" + model + "}"); } } } diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapperFactory.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapperFactory.java index 1ec2ac9168..873ff122ec 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapperFactory.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/SolverValidatorWrapperFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.validator; import hu.bme.mit.theta.solver.ItpSolver; diff --git a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/UCSolverValidatorWrapper.java b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/UCSolverValidatorWrapper.java index 9260c7da46..7fb63cd158 100644 --- a/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/UCSolverValidatorWrapper.java +++ b/subprojects/solver/solver/src/main/java/hu/bme/mit/theta/solver/validator/UCSolverValidatorWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.solver.validator; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.SolverManager; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.UCSolver; - import java.util.Collection; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public class UCSolverValidatorWrapper implements UCSolver { private final UCSolver solver; diff --git a/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/SolverStub.java b/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/SolverStub.java index e5188426d3..059afa235e 100644 --- a/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/SolverStub.java +++ b/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/SolverStub.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,10 @@ */ package hu.bme.mit.theta.solver; -import java.util.Collection; - import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; +import java.util.Collection; class SolverStub implements Solver { diff --git a/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/StackTest.java b/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/StackTest.java index 9c657c3770..0bb7b0ce24 100644 --- a/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/StackTest.java +++ b/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/StackTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,11 +17,10 @@ import static org.junit.Assert.assertEquals; +import hu.bme.mit.theta.solver.impl.StackImpl; import org.junit.Assert; import org.junit.Test; -import hu.bme.mit.theta.solver.impl.StackImpl; - public class StackTest { @Test @@ -30,56 +29,60 @@ public void testPushPop() { assertEquals(0, stack.toCollection().size()); stack.push(); assertEquals(0, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {}, stack.toCollection().toArray()); stack.add("A"); assertEquals(1, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A",}, stack.toCollection().toArray()); + Assert.assertArrayEquals( + new String[] { + "A", + }, + stack.toCollection().toArray()); stack.add("B"); assertEquals(2, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B"}, stack.toCollection().toArray()); stack.push(); assertEquals(2, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B"}, stack.toCollection().toArray()); stack.add("C"); assertEquals(3, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B", "C"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B", "C"}, stack.toCollection().toArray()); stack.add("D"); assertEquals(4, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B", "C", "D"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B", "C", "D"}, stack.toCollection().toArray()); stack.pop(); assertEquals(2, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B"}, stack.toCollection().toArray()); stack.pop(); assertEquals(0, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {}, stack.toCollection().toArray()); } @Test public void testPop2() { final Stack stack = new StackImpl<>(); assertEquals(0, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {}, stack.toCollection().toArray()); stack.push(); assertEquals(0, stack.toCollection().size()); stack.add("A"); assertEquals(1, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A"}, stack.toCollection().toArray()); stack.push(); assertEquals(1, stack.toCollection().size()); stack.add("B"); assertEquals(2, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B"}, stack.toCollection().toArray()); stack.push(); assertEquals(2, stack.toCollection().size()); stack.add("C"); assertEquals(3, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A", "B", "C"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A", "B", "C"}, stack.toCollection().toArray()); stack.pop(2); assertEquals(1, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{"A"}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {"A"}, stack.toCollection().toArray()); stack.pop(); assertEquals(0, stack.toCollection().size()); - Assert.assertArrayEquals(new String[]{}, stack.toCollection().toArray()); + Assert.assertArrayEquals(new String[] {}, stack.toCollection().toArray()); } @Test(expected = IllegalArgumentException.class) diff --git a/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/WithPushPopTest.java b/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/WithPushPopTest.java index 4ff1732906..04f8b90a7c 100644 --- a/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/WithPushPopTest.java +++ b/subprojects/solver/solver/src/test/java/hu/bme/mit/theta/solver/WithPushPopTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,10 @@ */ package hu.bme.mit.theta.solver; +import hu.bme.mit.theta.solver.utils.WithPushPop; import org.junit.Assert; import org.junit.Test; -import hu.bme.mit.theta.solver.utils.WithPushPop; - public class WithPushPopTest { @Test diff --git a/subprojects/sts/sts-analysis/build.gradle.kts b/subprojects/sts/sts-analysis/build.gradle.kts index fbb1cbfcc7..16ece1407e 100644 --- a/subprojects/sts/sts-analysis/build.gradle.kts +++ b/subprojects/sts/sts-analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsAction.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsAction.java index 693503c8c0..1edf068f3a 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsAction.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.sts.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; @@ -22,11 +24,7 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.sts.STS; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Represents an action for an STS, which is simply the transition relation. - */ +/** Represents an action for an STS, which is simply the transition relation. */ public final class StsAction implements ExprAction { private final Expr trans; diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsLts.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsLts.java index beed5998eb..954c6ccb61 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsLts.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,11 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.LTS; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.sts.STS; +import java.util.Collection; +import java.util.Collections; /** * An LTS implementation for the STS formalism. The STS has only one enabled Action for every State, @@ -51,5 +50,4 @@ public static LTS create(final STS sts) { public Collection getEnabledActionsFor(final State state) { return actions; } - } diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsTraceConcretizer.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsTraceConcretizer.java index 35fca1d643..940c5805f9 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsTraceConcretizer.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/StsTraceConcretizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -31,14 +31,17 @@ public final class StsTraceConcretizer { - private StsTraceConcretizer() { - } + private StsTraceConcretizer() {} public static Trace concretize( - final STS sts, final Trace trace, final SolverFactory solverFactory) { - final ExprTraceChecker checker = ExprTraceFwBinItpChecker.create( - sts.getInit(), - BoolExprs.Not(sts.getProp()), solverFactory.createItpSolver()); + final STS sts, + final Trace trace, + final SolverFactory solverFactory) { + final ExprTraceChecker checker = + ExprTraceFwBinItpChecker.create( + sts.getInit(), + BoolExprs.Not(sts.getProp()), + solverFactory.createItpSolver()); final ExprTraceStatus status = checker.check(trace); checkArgument(status.isFeasible(), "Infeasible trace."); final Trace valuations = status.asFeasible().getValuations(); diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfig.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfig.java index 43b2a80ecb..af0683b222 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfig.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -41,5 +41,4 @@ public static StsConfig, Trace> check() { return checker.check(initPrec); } - } diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfigBuilder.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfigBuilder.java index 7e946253e9..96627cdc7a 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfigBuilder.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/config/StsConfigBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsEmptyInitPrec.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsEmptyInitPrec.java index 73c27558c6..feda867bc4 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsEmptyInitPrec.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsEmptyInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,7 @@ import hu.bme.mit.theta.analysis.pred.PredPrec; import hu.bme.mit.theta.sts.STS; -/** - * An implementation for initial precision that returns empty initial precisions. - */ +/** An implementation for initial precision that returns empty initial precisions. */ public class StsEmptyInitPrec implements StsInitPrec { @Override @@ -33,5 +31,4 @@ public ExplPrec createExpl(final STS sts) { public PredPrec createPred(final STS sts) { return PredPrec.of(); } - } diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsInitPrec.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsInitPrec.java index 2c67931a9d..82a9c69eb1 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsInitPrec.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,18 +19,12 @@ import hu.bme.mit.theta.analysis.pred.PredPrec; import hu.bme.mit.theta.sts.STS; -/** - * Common interface for inferring initial precision for STSs. - */ +/** Common interface for inferring initial precision for STSs. */ public interface StsInitPrec { - /** - * Creates initial ExplPrec based on an STS. - */ + /** Creates initial ExplPrec based on an STS. */ ExplPrec createExpl(STS sts); - /** - * Creates initial PredPrec based on an STS. - */ + /** Creates initial PredPrec based on an STS. */ PredPrec createPred(STS sts); } diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsPropInitPrec.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsPropInitPrec.java index c38531cd57..179ef98916 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsPropInitPrec.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/initprec/StsPropInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -34,5 +34,4 @@ public ExplPrec createExpl(final STS sts) { public PredPrec createPred(final STS sts) { return PredPrec.of(ExprUtils.getAtoms(sts.getProp())); } - } diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/package-info.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/package-info.java index 1fdc479ad8..b175ac36b8 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/package-info.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,7 +15,7 @@ */ /** * This package contains the STS specific analysis modules that can be plugged into the analysis - * algorithms. There are also different implementations for obtaining an initial precision (see {@link hu.bme.mit.theta.sts.analysis.initprec.StsInitPrec}). + * algorithms. There are also different implementations for obtaining an initial precision (see + * {@link hu.bme.mit.theta.sts.analysis.initprec.StsInitPrec}). */ - -package hu.bme.mit.theta.sts.analysis; \ No newline at end of file +package hu.bme.mit.theta.sts.analysis; diff --git a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/utils/StsTraceVisualizer.java b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/utils/StsTraceVisualizer.java index c6e6537808..2aa305e735 100644 --- a/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/utils/StsTraceVisualizer.java +++ b/subprojects/sts/sts-analysis/src/main/java/hu/bme/mit/theta/sts/analysis/utils/StsTraceVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,21 @@ */ package hu.bme.mit.theta.sts.analysis.utils; -import java.util.LinkedHashSet; -import java.util.Optional; -import java.util.Set; - import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.common.table.TableWriter; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.sts.analysis.StsAction; +import java.util.LinkedHashSet; +import java.util.Optional; +import java.util.Set; public final class StsTraceVisualizer { - private StsTraceVisualizer() { - } + private StsTraceVisualizer() {} - public static void printTraceTable(final Trace trace, - final TableWriter writer) { + public static void printTraceTable( + final Trace trace, final TableWriter writer) { final Set> allVars = new LinkedHashSet<>(); for (final Valuation val : trace.getStates()) { allVars.addAll(val.getDecls()); @@ -50,5 +48,4 @@ public static void printTraceTable(final Trace trace, } writer.endTable(); } - } diff --git a/subprojects/sts/sts-analysis/src/main/kotlin/hu/bme/mit/theta/sts/analysis/StsToMonolithicExpr.kt b/subprojects/sts/sts-analysis/src/main/kotlin/hu/bme/mit/theta/sts/analysis/StsToMonolithicExpr.kt index 19c7bd5189..583999c55f 100644 --- a/subprojects/sts/sts-analysis/src/main/kotlin/hu/bme/mit/theta/sts/analysis/StsToMonolithicExpr.kt +++ b/subprojects/sts/sts-analysis/src/main/kotlin/hu/bme/mit/theta/sts/analysis/StsToMonolithicExpr.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.sts.analysis import hu.bme.mit.theta.analysis.algorithm.bounded.MonolithicExpr @@ -22,13 +21,13 @@ import hu.bme.mit.theta.core.model.Valuation import hu.bme.mit.theta.sts.STS fun STS.toMonolithicExpr(): MonolithicExpr { - return MonolithicExpr(this.init, this.trans, this.prop) + return MonolithicExpr(this.init, this.trans, this.prop) } fun STS.valToAction(val1: Valuation, val2: Valuation): StsAction { - return StsAction(this); + return StsAction(this) } fun STS.valToState(val1: Valuation): ExplState { - return ExplState.of(val1); + return ExplState.of(val1) } diff --git a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsExplTest.java b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsExplTest.java index f6609fdc97..57ad989887 100644 --- a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsExplTest.java +++ b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsExplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsMddCheckerTest.java b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsMddCheckerTest.java index 22075857dc..e005e47a88 100644 --- a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsMddCheckerTest.java +++ b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsMddCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsPredTest.java b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsPredTest.java index 5022d36401..aa428988e5 100644 --- a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsPredTest.java +++ b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsPredTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsTest.java b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsTest.java index 17032a3ba7..a1dbceff15 100644 --- a/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsTest.java +++ b/subprojects/sts/sts-analysis/src/test/java/hu/bme/mit/theta/sts/analysis/StsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.sts.analysis; +import static hu.bme.mit.theta.sts.analysis.config.StsConfigBuilder.Domain.*; +import static hu.bme.mit.theta.sts.analysis.config.StsConfigBuilder.Refinement.SEQ_ITP; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; @@ -27,18 +30,14 @@ import hu.bme.mit.theta.sts.analysis.config.StsConfigBuilder; import hu.bme.mit.theta.sts.dsl.StsDslManager; import hu.bme.mit.theta.sts.dsl.StsSpec; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collection; - -import static hu.bme.mit.theta.sts.analysis.config.StsConfigBuilder.Domain.*; -import static hu.bme.mit.theta.sts.analysis.config.StsConfigBuilder.Refinement.SEQ_ITP; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; @RunWith(value = Parameterized.class) public class StsTest { @@ -57,35 +56,23 @@ public class StsTest { @Parameterized.Parameters(name = "{index}: {0}, {1}, {2}, {3}") public static Collection data() { - return Arrays.asList(new Object[][]{ - {"src/test/resources/hw1_false.aag", PRED_CART, SEQ_ITP, false}, - - {"src/test/resources/hw2_true.aag", PRED_CART, SEQ_ITP, true}, - - {"src/test/resources/boolean1.system", PRED_CART, SEQ_ITP, false}, - - {"src/test/resources/boolean2.system", PRED_CART, SEQ_ITP, false}, - - {"src/test/resources/counter.system", PRED_CART, SEQ_ITP, true}, - - {"src/test/resources/counter_bad.system", PRED_CART, SEQ_ITP, false}, - - {"src/test/resources/counter_parametric.system", PRED_CART, SEQ_ITP, true}, - - {"src/test/resources/loop.system", EXPL, SEQ_ITP, true}, - - {"src/test/resources/loop_bad.system", EXPL, SEQ_ITP, false}, - - {"src/test/resources/multipleinitial.system", PRED_CART, SEQ_ITP, false}, - - {"src/test/resources/readerswriters.system", PRED_CART, SEQ_ITP, true}, - - {"src/test/resources/simple1.system", EXPL, SEQ_ITP, false}, - - {"src/test/resources/simple2.system", EXPL, SEQ_ITP, true}, - - {"src/test/resources/simple3.system", EXPL, SEQ_ITP, false}, - }); + return Arrays.asList( + new Object[][] { + {"src/test/resources/hw1_false.aag", PRED_CART, SEQ_ITP, false}, + {"src/test/resources/hw2_true.aag", PRED_CART, SEQ_ITP, true}, + {"src/test/resources/boolean1.system", PRED_CART, SEQ_ITP, false}, + {"src/test/resources/boolean2.system", PRED_CART, SEQ_ITP, false}, + {"src/test/resources/counter.system", PRED_CART, SEQ_ITP, true}, + {"src/test/resources/counter_bad.system", PRED_CART, SEQ_ITP, false}, + {"src/test/resources/counter_parametric.system", PRED_CART, SEQ_ITP, true}, + {"src/test/resources/loop.system", EXPL, SEQ_ITP, true}, + {"src/test/resources/loop_bad.system", EXPL, SEQ_ITP, false}, + {"src/test/resources/multipleinitial.system", PRED_CART, SEQ_ITP, false}, + {"src/test/resources/readerswriters.system", PRED_CART, SEQ_ITP, true}, + {"src/test/resources/simple1.system", EXPL, SEQ_ITP, false}, + {"src/test/resources/simple2.system", EXPL, SEQ_ITP, true}, + {"src/test/resources/simple3.system", EXPL, SEQ_ITP, false}, + }); } @Test @@ -100,9 +87,9 @@ public void test() throws IOException { } sts = Utils.singleElementOf(spec.getAllSts()); } - StsConfig config - = new StsConfigBuilder(domain, refinement, Z3LegacySolverFactory.getInstance()).build(sts); + StsConfig config = + new StsConfigBuilder(domain, refinement, Z3LegacySolverFactory.getInstance()) + .build(sts); Assert.assertEquals(isSafe, config.check().isSafe()); } - } diff --git a/subprojects/sts/sts-cli/build.gradle.kts b/subprojects/sts/sts-cli/build.gradle.kts index cb1eedf2e2..ded5f84c63 100644 --- a/subprojects/sts/sts-cli/build.gradle.kts +++ b/subprojects/sts/sts-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts-cli/src/main/java/hu/bme/mit/theta/sts/cli/StsCli.java b/subprojects/sts/sts-cli/src/main/java/hu/bme/mit/theta/sts/cli/StsCli.java index 884bfabdae..90c898bc99 100644 --- a/subprojects/sts/sts-cli/src/main/java/hu/bme/mit/theta/sts/cli/StsCli.java +++ b/subprojects/sts/sts-cli/src/main/java/hu/bme/mit/theta/sts/cli/StsCli.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts/build.gradle.kts b/subprojects/sts/sts/build.gradle.kts index 195f997dbe..16bef82fdb 100644 --- a/subprojects/sts/sts/build.gradle.kts +++ b/subprojects/sts/sts/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/STS.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/STS.java index 7b9864135d..02fc2d5311 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/STS.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/STS.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,19 +21,16 @@ import static hu.bme.mit.theta.core.utils.ExprUtils.getConjuncts; import static java.lang.String.format; -import java.util.Collection; -import java.util.Collections; - -import hu.bme.mit.theta.common.container.Containers; - -import java.util.Set; - import hu.bme.mit.theta.common.Utils; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.AndExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; /** * An immutable Symbolic Transition System (STS) implementation. An STS consists of an initial @@ -47,9 +44,7 @@ public final class STS { private final Expr trans; private final Expr prop; - /** - * Create a new STS from an initial expression, a transition relation and a property. - */ + /** Create a new STS from an initial expression, a transition relation and a property. */ public STS(final Expr init, final Expr trans, final Expr prop) { this.init = checkNotNull(init); this.trans = checkNotNull(trans); @@ -61,44 +56,37 @@ public STS(final Expr init, final Expr trans, final Expr> getVars() { return vars; } - /** - * Gets the initial expression. - */ + /** Gets the initial expression. */ public Expr getInit() { return init; } - /** - * Gets the transition relation expression. - */ + /** Gets the transition relation expression. */ public Expr getTrans() { return trans; } - /** - * Gets the property expression. - */ + /** Gets the property expression. */ public Expr getProp() { return prop; } - /** - * Creates a new builder instance. - */ + /** Creates a new builder instance. */ public static Builder builder() { return new Builder(); } @Override public String toString() { - return Utils.lispStringBuilder("system").aligned().addAll(vars).body() + return Utils.lispStringBuilder("system") + .aligned() + .addAll(vars) + .body() .addAll(getConjuncts(init).stream().map(e -> format("(init %s)", e))) .addAll(getConjuncts(trans).stream().map(e -> format("(trans %s)", e))) .add(format("(prop %s)", prop)) @@ -157,9 +145,7 @@ public Builder addTrans(final Expr expr) { return this; } - /** - * Set the property expression. Previously set property will be overridden. - */ + /** Set the property expression. Previously set property will be overridden. */ public Builder setProp(final Expr expr) { this.prop = checkNotNull(expr); return this; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/StsUtils.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/StsUtils.java index 37c6afa231..ae708555d3 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/StsUtils.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/StsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,13 +19,10 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; -/** - * Utilities related to the STS formalism. - */ +/** Utilities related to the STS formalism. */ public final class StsUtils { - private StsUtils() { - } + private StsUtils() {} /** * Transform STS into an equivalent new STS, without if-then-else constructs. diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerParser.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerParser.java index 4fb48eaafe..89123c8676 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerParser.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,13 +18,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.Integer.parseInt; -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - import hu.bme.mit.theta.sts.aiger.elements.AigerNode; import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; import hu.bme.mit.theta.sts.aiger.elements.AigerWire; @@ -33,14 +26,17 @@ import hu.bme.mit.theta.sts.aiger.elements.InputVar; import hu.bme.mit.theta.sts.aiger.elements.Latch; import hu.bme.mit.theta.sts.aiger.elements.OutputVar; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; -/** - * Parser for textual (.aag) AIGER files. - */ +/** Parser for textual (.aag) AIGER files. */ public final class AigerParser { - private AigerParser() { - } + private AigerParser() {} /** * Parse a textual AIGER file (*.aag) to our internal representation. @@ -50,8 +46,8 @@ private AigerParser() { * @throws IOException */ public static AigerSystem parse(final String fileName) throws IOException { - final BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(fileName))); + final BufferedReader br = + new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); try { int nNodes; @@ -138,10 +134,10 @@ public static AigerSystem parse(final String fileName) throws IOException { final AndGate andGate = andGates.get(i); final AigerNode source1 = nodes[andGateInputs1.get(i) / 2]; final AigerNode source2 = nodes[andGateInputs2.get(i) / 2]; - final AigerWire wire1 = new AigerWire(source1, andGate, - andGateInputs1.get(i) % 2 == 0); - final AigerWire wire2 = new AigerWire(source2, andGate, - andGateInputs2.get(i) % 2 == 0); + final AigerWire wire1 = + new AigerWire(source1, andGate, andGateInputs1.get(i) % 2 == 0); + final AigerWire wire2 = + new AigerWire(source2, andGate, andGateInputs2.get(i) % 2 == 0); andGate.setInWire1(wire1); andGate.setInWire2(wire2); source1.addOutWire(wire1); diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerToSts.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerToSts.java index 71ddf64666..3ec4db9014 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerToSts.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/AigerToSts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,9 +21,6 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; import hu.bme.mit.theta.common.container.Containers; - -import java.util.Map; - import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; @@ -38,14 +35,12 @@ import hu.bme.mit.theta.sts.aiger.elements.FalseConst; import hu.bme.mit.theta.sts.aiger.elements.InputVar; import hu.bme.mit.theta.sts.aiger.elements.Latch; +import java.util.Map; -/** - * A converter from out internal AIGER representation to STSs. - */ +/** A converter from out internal AIGER representation to STSs. */ public final class AigerToSts { - private AigerToSts() { - } + private AigerToSts() {} /** * Convert an AIGER system to an STS @@ -83,15 +78,17 @@ public static STS createSts(final AigerSystem aigerSys) { return builder.build(); } - private static void transformFalseConst(final Builder builder, - final Map> vars, - final FalseConst falseConst) { + private static void transformFalseConst( + final Builder builder, + final Map> vars, + final FalseConst falseConst) { builder.addInvar(Not(vars.get(falseConst).getRef())); } - private static void transformLatch(final Builder builder, - final Map> vars, - final Latch latch) { + private static void transformLatch( + final Builder builder, + final Map> vars, + final Latch latch) { builder.addInit(Not(vars.get(latch).getRef())); final AigerWire inWire = latch.getInWire(); final AigerNode source = inWire.getSource(); @@ -101,9 +98,10 @@ private static void transformLatch(final Builder builder, builder.addTrans(Iff(lhs, rhs)); } - private static void transformAndGate(final Builder builder, - final Map> vars, - final AndGate andGate) { + private static void transformAndGate( + final Builder builder, + final Map> vars, + final AndGate andGate) { final AigerWire inWire1 = andGate.getInWire1(); final AigerWire inWire2 = andGate.getInWire2(); final AigerNode source1 = inWire1.getSource(); @@ -115,5 +113,4 @@ private static void transformAndGate(final Builder builder, inWire2.isPonated() ? vars.get(source2).getRef() : Not(vars.get(source2).getRef()); builder.addInvar(Iff(lhs, And(rhs1, rhs2))); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerNode.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerNode.java index 0218bb8757..3e133c96ab 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerNode.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,7 @@ import java.util.Collection; -/** - * Base class for nodes in an {@link AigerSystem}. - */ +/** Base class for nodes in an {@link AigerSystem}. */ public abstract class AigerNode { private final String name; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerSystem.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerSystem.java index a970a52f04..37ecaaaf88 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerSystem.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,8 @@ /** * Represents an AIGER system, which is a collection of @link {@link AigerNode}s (connected with - *

- * {@link AigerWire}s) and an {@link OutputVar}. + * + *

{@link AigerWire}s) and an {@link OutputVar}. */ public class AigerSystem { @@ -39,5 +39,4 @@ public List getNodes() { public OutputVar getOutput() { return output; } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerWire.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerWire.java index c4af775325..f3db409c7b 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerWire.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AigerWire.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,9 +15,7 @@ */ package hu.bme.mit.theta.sts.aiger.elements; -/** - * Represents a wire between {@link AigerNode}s. - */ +/** Represents a wire between {@link AigerNode}s. */ public final class AigerWire { private AigerNode source; @@ -51,5 +49,4 @@ public void modifySource(final AigerNode node) { public void invert() { isPonated = !isPonated; } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AndGate.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AndGate.java index 36e4a80004..80498de08f 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AndGate.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/AndGate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,11 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Collection; -import com.google.common.collect.ImmutableList; - -/** - * Represents an and gate with exactly two inputs. - */ +/** Represents an and gate with exactly two inputs. */ public class AndGate extends AigerNode { private final Collection outWires; @@ -69,5 +66,4 @@ public void addOutWire(final AigerWire outWire) { checkArgument(outWire.getSource().equals(this)); outWires.add(outWire); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/FalseConst.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/FalseConst.java index 87e65f605d..6da02e1aa0 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/FalseConst.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/FalseConst.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,9 +21,7 @@ import java.util.Collection; import java.util.Collections; -/** - * Represents a constant false signal. - */ +/** Represents a constant false signal. */ public final class FalseConst extends AigerNode { private final Collection outWires; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/InputVar.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/InputVar.java index 6a793d2bfb..ec5d9f037d 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/InputVar.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/InputVar.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,9 +21,7 @@ import java.util.Collection; import java.util.Collections; -/** - * Represents an input variable. - */ +/** Represents an input variable. */ public final class InputVar extends AigerNode { private final Collection outWires; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/Latch.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/Latch.java index 3df49e8863..04d6191172 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/Latch.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/Latch.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,9 +21,7 @@ import java.util.Collection; import java.util.Collections; -/** - * Represents a latch (1 bit memory). - */ +/** Represents a latch (1 bit memory). */ public class Latch extends AigerNode { private final Collection outWires; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/OutputVar.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/OutputVar.java index 42b3f389de..617a9f5820 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/OutputVar.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/OutputVar.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,9 +20,7 @@ import java.util.Collection; import java.util.Collections; -/** - * Represents an output variable. - */ +/** Represents an output variable. */ public class OutputVar extends AigerNode { private AigerWire inWire; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/package-info.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/package-info.java index 58f480a3e6..27cc5a35e2 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/package-info.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/elements/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,5 +18,4 @@ * * @see hu.bme.mit.theta.sts.aiger.elements.AigerSystem */ - -package hu.bme.mit.theta.sts.aiger.elements; \ No newline at end of file +package hu.bme.mit.theta.sts.aiger.elements; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/package-info.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/package-info.java index 7a1a571bee..d2993ecdde 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/package-info.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ * @see hu.bme.mit.theta.sts.aiger.AigerToSts * @see hu.bme.mit.theta.sts.aiger.elements.AigerSystem */ - -package hu.bme.mit.theta.sts.aiger; \ No newline at end of file +package hu.bme.mit.theta.sts.aiger; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerCoi.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerCoi.java index b059d9281e..aa13df32f8 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerCoi.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerCoi.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,25 +15,19 @@ */ package hu.bme.mit.theta.sts.aiger.utils; -import java.util.ArrayDeque; - import hu.bme.mit.theta.common.container.Containers; - -import java.util.Iterator; -import java.util.Queue; -import java.util.Set; - import hu.bme.mit.theta.sts.aiger.elements.AigerNode; import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; import hu.bme.mit.theta.sts.aiger.elements.AigerWire; +import java.util.ArrayDeque; +import java.util.Iterator; +import java.util.Queue; +import java.util.Set; -/** - * Cone-of-influence (COI) reduction for AIGER systems. - */ +/** Cone-of-influence (COI) reduction for AIGER systems. */ public final class AigerCoi { - private AigerCoi() { - } + private AigerCoi() {} /** * Apply COI reduction to the system by removing nodes that are not backward reachable from the @@ -62,13 +56,13 @@ private static Set getReachableNodes(final AigerSystem system) { return reached; } - private static void pruneUnreachableNodes(final AigerSystem system, - final Set reachable) { + private static void pruneUnreachableNodes( + final AigerSystem system, final Set reachable) { system.getNodes().clear(); system.getNodes().addAll(reachable); for (final AigerNode node : system.getNodes()) { for (final Iterator iterator = node.getOutWires().iterator(); - iterator.hasNext(); ) { + iterator.hasNext(); ) { final AigerWire wire = iterator.next(); if (!reachable.contains(wire.getTarget())) { iterator.remove(); diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerConstProp.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerConstProp.java index cb98041dfb..f7a90fd913 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerConstProp.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerConstProp.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,27 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.sts.aiger.utils; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.sts.aiger.elements.AigerNode; import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; import hu.bme.mit.theta.sts.aiger.elements.AigerWire; import hu.bme.mit.theta.sts.aiger.elements.AndGate; import hu.bme.mit.theta.sts.aiger.elements.FalseConst; import hu.bme.mit.theta.sts.aiger.elements.Latch; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; -/** - * Constant propagation for AIGER systems. - */ +/** Constant propagation for AIGER systems. */ public final class AigerConstProp { - private AigerConstProp() { - } + private AigerConstProp() {} /** * Propagate constants in an AIGER system. The parameter is modified. It is assumed that the @@ -42,15 +37,13 @@ private AigerConstProp() { * @param system */ public static void apply(final AigerSystem system) { - final Optional falseOpt = system.getNodes().stream() - .filter(n -> n instanceof FalseConst) - .findFirst(); + final Optional falseOpt = + system.getNodes().stream().filter(n -> n instanceof FalseConst).findFirst(); if (!falseOpt.isPresent()) { return; } final FalseConst falseConst = (FalseConst) falseOpt.get(); - while (propagateAnd(system, falseConst) || propagateLatch(system, falseConst)) { - } + while (propagateAnd(system, falseConst) || propagateLatch(system, falseConst)) {} } /** @@ -59,8 +52,10 @@ public static void apply(final AigerSystem system) { * @return True, if any propagation occurred */ private static boolean propagateAnd(final AigerSystem system, final FalseConst falseConst) { - final Optional wireOpt = falseConst.getOutWires().stream() - .filter(w -> w.getTarget() instanceof AndGate).findFirst(); + final Optional wireOpt = + falseConst.getOutWires().stream() + .filter(w -> w.getTarget() instanceof AndGate) + .findFirst(); if (wireOpt.isPresent()) { final AigerWire wire = wireOpt.get(); final AndGate andGate = (AndGate) wire.getTarget(); @@ -93,8 +88,10 @@ private static boolean propagateAnd(final AigerSystem system, final FalseConst f * @return True, if any propagation occurred */ private static boolean propagateLatch(final AigerSystem system, final FalseConst falseConst) { - final Optional wireOpt = falseConst.getOutWires().stream() - .filter(w -> w.getTarget() instanceof Latch && w.isPonated()).findFirst(); + final Optional wireOpt = + falseConst.getOutWires().stream() + .filter(w -> w.getTarget() instanceof Latch && w.isPonated()) + .findFirst(); if (wireOpt.isPresent()) { final AigerWire wire = wireOpt.get(); final Latch latch = (Latch) wire.getTarget(); diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerVisualizer.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerVisualizer.java index c22a89ab65..f3d5cd8b01 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerVisualizer.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/AigerVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,9 +18,6 @@ import static java.lang.System.lineSeparator; import hu.bme.mit.theta.common.container.Containers; - -import java.util.Set; - import hu.bme.mit.theta.sts.aiger.elements.AigerNode; import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; import hu.bme.mit.theta.sts.aiger.elements.AigerWire; @@ -28,10 +25,9 @@ import hu.bme.mit.theta.sts.aiger.elements.FalseConst; import hu.bme.mit.theta.sts.aiger.elements.InputVar; import hu.bme.mit.theta.sts.aiger.elements.Latch; +import java.util.Set; -/** - * Visualizer for AIGER systems. - */ +/** Visualizer for AIGER systems. */ public final class AigerVisualizer { private static final String INPUTNODE = @@ -43,8 +39,7 @@ public final class AigerVisualizer { "\t%s [shape=ellipse,margin=0.02,width=0,height=0];" + lineSeparator(); private static final String INVHEAD = "odot"; - private AigerVisualizer() { - } + private AigerVisualizer() {} /** * Visualize an AIGER system in dot format. @@ -83,8 +78,9 @@ private static void appendWires(final AigerSystem system, final StringBuilder sb system.getNodes().forEach(n -> wires.addAll(n.getOutWires())); wires.addAll(system.getOutput().getInWires()); for (final AigerWire wire : wires) { - sb.append(String.format("\t%s -> %s", wire.getSource().getName(), - wire.getTarget().getName())); + sb.append( + String.format( + "\t%s -> %s", wire.getSource().getName(), wire.getTarget().getName())); if (!wire.isPonated()) { sb.append(" [arrowhead=" + INVHEAD + "]"); } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/package-info.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/package-info.java index 33a99cfd39..e4e6bb3209 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/package-info.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/aiger/utils/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,8 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * This package contains utilities for AIGER systems such as visualization and optimizations. - */ - -package hu.bme.mit.theta.sts.aiger.utils; \ No newline at end of file +/** This package contains utilities for AIGER systems such as visualization and optimizations. */ +package hu.bme.mit.theta.sts.aiger.utils; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/PropDeclSymbol.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/PropDeclSymbol.java index b803ee90b8..aa9bea9ca7 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/PropDeclSymbol.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/PropDeclSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -39,8 +39,8 @@ private PropDeclSymbol(final StsSpecSymbol scope, final PropDeclContext propDecl name = propDeclContext.name.getText(); } - public static PropDeclSymbol create(final StsSpecSymbol scope, - final PropDeclContext propDeclContext) { + public static PropDeclSymbol create( + final StsSpecSymbol scope, final PropDeclContext propDeclContext) { return new PropDeclSymbol(scope, propDeclContext); } @@ -54,8 +54,8 @@ public String getName() { //// public STS instantiate(final Substitution assignment) { - final StsDefScope stsDefScope = StsCreator.createSts(scope, assignment, - propDeclContext.system); + final StsDefScope stsDefScope = + StsCreator.createSts(scope, assignment, propDeclContext.system); final Expr prop = createBoolExpr(stsDefScope, assignment, propDeclContext.cond); final STS sts = stsDefScope.getSts(); @@ -66,5 +66,4 @@ public STS instantiate(final Substitution assignment) { builder.setProp(prop); return builder.build(); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsCreator.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsCreator.java index a68bc42d96..6ea5f05321 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsCreator.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,6 @@ import static hu.bme.mit.theta.sts.dsl.StsDslHelper.createExprList; import static hu.bme.mit.theta.sts.dsl.StsDslHelper.resolveSts; -import java.util.List; - import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.core.model.Substitution; import hu.bme.mit.theta.core.type.Expr; @@ -28,14 +26,14 @@ import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.DefStsContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RefStsContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.StsContext; +import java.util.List; final class StsCreator { - private StsCreator() { - } + private StsCreator() {} - public static StsDefScope createSts(final Scope scope, final Substitution assignment, - final StsContext stsContext) { + public static StsDefScope createSts( + final Scope scope, final Substitution assignment, final StsContext stsContext) { return stsContext.accept(new StsCreatorVisitor(scope, assignment)); } @@ -62,5 +60,4 @@ public StsDefScope visitRefSts(final RefStsContext ctx) { return symbol.instantiate(assignment, args); } } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDeclSymbol.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDeclSymbol.java index b5614acaab..e7e718b4ca 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDeclSymbol.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDeclSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.ScopedSymbol; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.common.dsl.SymbolTable; @@ -31,6 +28,8 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.utils.ExprUtils; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.StsDeclContext; +import java.util.List; +import java.util.Optional; final class StsDeclSymbol implements ScopedSymbol { @@ -52,8 +51,8 @@ private StsDeclSymbol(final StsSpecSymbol enclosingScope, final StsDeclContext s declareParams(); } - public static StsDeclSymbol create(final StsSpecSymbol enclosingScope, - final StsDeclContext tcfaDeclCtx) { + public static StsDeclSymbol create( + final StsSpecSymbol enclosingScope, final StsDeclContext tcfaDeclCtx) { return new StsDeclSymbol(enclosingScope, tcfaDeclCtx); } @@ -81,13 +80,13 @@ public Optional resolve(final String name) { //// - public StsDefScope instantiate(final Substitution assignment, - final List> args) { + public StsDefScope instantiate( + final Substitution assignment, final List> args) { final List> simplifiedArgs = ExprUtils.simplifyAll(args); final ParamBinding binding = ParamBinding.create(params, simplifiedArgs); final Substitution newAssignment = NestedSubstitution.create(assignment, binding); - final StsDefScope stsDefScope = StsCreator.createSts(this, newAssignment, - stsDeclContext.def); + final StsDefScope stsDefScope = + StsCreator.createSts(this, newAssignment, stsDeclContext.def); return stsDefScope; } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDefScope.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDefScope.java index eb1837117d..5b398ab3c1 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDefScope.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDefScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,8 +21,6 @@ import static hu.bme.mit.theta.sts.dsl.StsDslHelper.createConstDecl; import static hu.bme.mit.theta.sts.dsl.StsDslHelper.createVarDecl; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.common.dsl.SymbolTable; @@ -40,6 +38,7 @@ import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.InvarConstrContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.TransConstrContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.VarDeclContext; +import java.util.Optional; final class StsDefScope implements Scope { @@ -52,8 +51,10 @@ final class StsDefScope implements Scope { private final STS.Builder stsBuilder; private final STS sts; - private StsDefScope(final Scope enclosingScope, final Substitution assignment, - final DefStsContext defTcfaContext) { + private StsDefScope( + final Scope enclosingScope, + final Substitution assignment, + final DefStsContext defTcfaContext) { checkNotNull(assignment); this.enclosingScope = checkNotNull(enclosingScope); this.defStsContext = checkNotNull(defTcfaContext); @@ -63,8 +64,8 @@ private StsDefScope(final Scope enclosingScope, final Substitution assignment, declareVars(); // TODO Handle recursive constant definitions - final Substitution constAssignment = StsDslHelper.createConstDefs(this, assignment, - defTcfaContext.constDecls); + final Substitution constAssignment = + StsDslHelper.createConstDefs(this, assignment, defTcfaContext.constDecls); this.assignment = NestedSubstitution.create(assignment, constAssignment); stsBuilder = STS.builder(); @@ -79,8 +80,10 @@ private StsDefScope(final Scope enclosingScope, final Substitution assignment, sts = stsBuilder.build(); } - public static StsDefScope create(final Scope enclosingScope, final Substitution assignment, - final DefStsContext defTcfaContext) { + public static StsDefScope create( + final Scope enclosingScope, + final Substitution assignment, + final DefStsContext defTcfaContext) { return new StsDefScope(enclosingScope, assignment, defTcfaContext); } @@ -157,5 +160,4 @@ private void declareVar(final VarDeclContext varDeclContext) { final Symbol symbol = DeclSymbol.of(varDecl); symbolTable.add(symbol); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslHelper.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslHelper.java index 28950c9f05..37bc40dde7 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslHelper.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,14 +22,7 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static java.util.stream.Collectors.toList; -import java.util.Collections; - import hu.bme.mit.theta.common.container.Containers; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.decl.ConstDecl; @@ -50,11 +43,14 @@ import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.ExprListContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.TypeContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.VarDeclContext; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; final class StsDslHelper { - private StsDslHelper() { - } + private StsDslHelper() {} public static ParamDecl createParamDecl(final DeclContext declCtx) { final String name = declCtx.name.getText(); @@ -87,8 +83,10 @@ public static VarDecl createVarDecl(final VarDeclContext varDeclCtx) { return varDecl; } - public static Substitution createConstDefs(final Scope scope, final Substitution assignment, - final List constDeclCtxs) { + public static Substitution createConstDefs( + final Scope scope, + final Substitution assignment, + final List constDeclCtxs) { final Map, Expr> declToExpr = Containers.createMap(); for (final ConstDeclContext constDeclCtx : constDeclCtxs) { addDef(scope, assignment, declToExpr, constDeclCtx); @@ -96,9 +94,11 @@ public static Substitution createConstDefs(final Scope scope, final Substitution return BasicSubstitution.builder().putAll(declToExpr).build(); } - private static void addDef(final Scope scope, final Substitution assignment, - final Map, Expr> declToExpr, - final ConstDeclContext constDeclCtx) { + private static void addDef( + final Scope scope, + final Substitution assignment, + final Map, Expr> declToExpr, + final ConstDeclContext constDeclCtx) { final String name = constDeclCtx.ddecl.name.getText(); final DeclSymbol declSymbol = resolveDecl(scope, name); final Decl decl = declSymbol.getDecl(); @@ -112,36 +112,36 @@ public static Type createType(final TypeContext typeCtx) { return type; } - public static Expr createExpr(final Scope scope, final Substitution assignment, - final ExprContext exprCtx) { + public static Expr createExpr( + final Scope scope, final Substitution assignment, final ExprContext exprCtx) { final Expr expr = exprCtx.accept(new StsExprCreatorVisitor(scope, assignment)); assert expr != null; return expr; } - public static List> createExprList(final Scope scope, final Substitution assignment, - final ExprListContext exprListCtx) { + public static List> createExprList( + final Scope scope, final Substitution assignment, final ExprListContext exprListCtx) { if (exprListCtx == null || exprListCtx.exprs == null) { return Collections.emptyList(); } else { - final List> exprs = exprListCtx.exprs.stream() - .map(ctx -> createExpr(scope, assignment, ctx)) - .collect(toList()); + final List> exprs = + exprListCtx.exprs.stream() + .map(ctx -> createExpr(scope, assignment, ctx)) + .collect(toList()); return exprs; } } - public static Expr createBoolExpr(final Scope scope, final Substitution assignment, - final ExprContext exprCtx) { + public static Expr createBoolExpr( + final Scope scope, final Substitution assignment, final ExprContext exprCtx) { return TypeUtils.cast(createExpr(scope, assignment, exprCtx), Bool()); } - public static List> createBoolExprList(final Scope scope, - final Substitution assignment, - final ExprListContext exprListCtx) { + public static List> createBoolExprList( + final Scope scope, final Substitution assignment, final ExprListContext exprListCtx) { final List> exprs = createExprList(scope, assignment, exprListCtx); - final List> boolExprs = exprs.stream().map(e -> TypeUtils.cast(e, Bool())) - .collect(toList()); + final List> boolExprs = + exprs.stream().map(e -> TypeUtils.cast(e, Bool())).collect(toList()); return boolExprs; } @@ -168,5 +168,4 @@ public static StsDeclSymbol resolveSts(final Scope scope, final String name) { return stsSymbol; } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslManager.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslManager.java index 96b87ca62c..e2f5dfb327 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslManager.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsDslManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,37 +15,33 @@ */ package hu.bme.mit.theta.sts.dsl; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.sts.dsl.gen.StsDslLexer; +import hu.bme.mit.theta.sts.dsl.gen.StsDslParser; +import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.StsSpecContext; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; - import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.sts.dsl.gen.StsDslLexer; -import hu.bme.mit.theta.sts.dsl.gen.StsDslParser; -import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.StsSpecContext; - public final class StsDslManager { - private StsDslManager() { - } + private StsDslManager() {} public static StsSpec createStsSpec(final String inputString, final Expr... params) throws IOException { - final InputStream stream = new ByteArrayInputStream( - inputString.getBytes(StandardCharsets.UTF_8.name())); + final InputStream stream = + new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8.name())); return createStsSpec(stream, params); } - public static StsSpec createStsSpec(final InputStream inputStream, - final List> args) - throws IOException { + public static StsSpec createStsSpec( + final InputStream inputStream, final List> args) throws IOException { final CharStream input = CharStreams.fromStream(inputStream); final StsDslLexer lexer = new StsDslLexer(input); @@ -63,5 +59,4 @@ public static StsSpec createStsSpec(final InputStream inputStream, final Expr throws IOException { return createStsSpec(inputStream, Arrays.asList(params)); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsExprCreatorVisitor.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsExprCreatorVisitor.java index dc14b3c809..96feaa7dec 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsExprCreatorVisitor.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsExprCreatorVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -41,24 +41,14 @@ import static hu.bme.mit.theta.sts.dsl.StsDslHelper.createParamList; import static java.util.stream.Collectors.toList; -import java.math.BigInteger; -import java.util.Collection; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.stream.Stream; - -import hu.bme.mit.theta.core.dsl.ParseException; -import org.antlr.v4.runtime.Token; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.common.dsl.BasicScope; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.ParamDecl; import hu.bme.mit.theta.core.dsl.DeclSymbol; +import hu.bme.mit.theta.core.dsl.ParseException; import hu.bme.mit.theta.core.model.Substitution; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; @@ -70,9 +60,9 @@ import hu.bme.mit.theta.core.type.booltype.FalseExpr; import hu.bme.mit.theta.core.type.booltype.TrueExpr; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; -import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.inttype.IntModExpr; import hu.bme.mit.theta.core.type.inttype.IntRemExpr; +import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatLitExpr; import hu.bme.mit.theta.core.utils.TypeUtils; import hu.bme.mit.theta.sts.dsl.gen.StsDslBaseVisitor; @@ -102,6 +92,12 @@ import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RelationExprContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.TrueExprContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.XorExprContext; +import java.math.BigInteger; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; +import org.antlr.v4.runtime.Token; final class StsExprCreatorVisitor extends StsDslBaseVisitor> { @@ -134,13 +130,13 @@ public Expr visitFuncLitExpr(final FuncLitExprContext ctx) { final List> params = createParamList(ctx.paramDecls); checkArgument(params.size() == 1); - @SuppressWarnings("unchecked") final ParamDecl param = (ParamDecl) singleElementOf( - params); + @SuppressWarnings("unchecked") + final ParamDecl param = (ParamDecl) singleElementOf(params); push(params); - @SuppressWarnings("unchecked") final Expr result = (Expr) ctx.result.accept( - this); + @SuppressWarnings("unchecked") + final Expr result = (Expr) ctx.result.accept(this); pop(); @@ -219,8 +215,8 @@ public Expr visitExistsExpr(final ExistsExprContext ctx) { @Override public Expr visitOrExpr(final OrExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> TypeUtils.cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> TypeUtils.cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return Or(ops); } else { @@ -242,8 +238,8 @@ public Expr visitXorExpr(final XorExprContext ctx) { @Override public Expr visitAndExpr(final AndExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> TypeUtils.cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> TypeUtils.cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return And(ops); } else { @@ -322,8 +318,11 @@ public Expr visitAdditiveExpr(final AdditiveExprContext ctx) { } } - private Expr createAdditiveExpr(final Expr opsHead, final List> opsTail, - final List opers, final AdditiveExprContext ctx) { + private Expr createAdditiveExpr( + final Expr opsHead, + final List> opsTail, + final List opers, + final AdditiveExprContext ctx) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -341,11 +340,12 @@ private Expr createAdditiveExpr(final Expr opsHead, final List createAdditiveSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper, - final AdditiveExprContext ctx) { + private Expr createAdditiveSubExpr( + final Expr leftOp, + final Expr rightOp, + final Token oper, + final AdditiveExprContext ctx) { switch (oper.getType()) { - case StsDslParser.PLUS: return createAddExpr(leftOp, rightOp); @@ -360,8 +360,11 @@ private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightO private AddExpr createAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof AddExpr) { final AddExpr addLeftOp = (AddExpr) leftOp; - final List> ops = ImmutableList.>builder().addAll(addLeftOp.getOps()) - .add(rightOp).build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Add(ops); } else { return Add(leftOp, rightOp); @@ -387,12 +390,13 @@ public Expr visitMultiplicativeExpr(final MultiplicativeExprContext ctx) { } else { return visitChildren(ctx); } - } - private Expr createMutliplicativeExpr(final Expr opsHead, - final List> opsTail, - final List opers, final MultiplicativeExprContext ctx) { + private Expr createMutliplicativeExpr( + final Expr opsHead, + final List> opsTail, + final List opers, + final MultiplicativeExprContext ctx) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -410,11 +414,12 @@ private Expr createMutliplicativeExpr(final Expr opsHead, } } - private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper, - final MultiplicativeExprContext ctx) { + private Expr createMultiplicativeSubExpr( + final Expr leftOp, + final Expr rightOp, + final Token oper, + final MultiplicativeExprContext ctx) { switch (oper.getType()) { - case StsDslParser.MUL: return createMulExpr(leftOp, rightOp); @@ -435,8 +440,11 @@ private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof MulExpr) { final MulExpr addLeftOp = (MulExpr) leftOp; - final List> ops = ImmutableList.>builder().addAll(addLeftOp.getOps()) - .add(rightOp).build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Mul(ops); } else { return Mul(leftOp, rightOp); @@ -547,8 +555,8 @@ public Expr visitIdExpr(final IdExprContext ctx) { final Optional optSymbol = currentScope.resolve(ctx.id.getText()); if (optSymbol.isEmpty()) { - throw new ParseException(ctx, - "Identifier '" + ctx.id.getText() + "' cannot be resolved"); + throw new ParseException( + ctx, "Identifier '" + ctx.id.getText() + "' cannot be resolved"); } final Symbol symbol = optSymbol.get(); @@ -562,12 +570,10 @@ public Expr visitIdExpr(final IdExprContext ctx) { } else { return decl.getRef(); } - } @Override public Expr visitParenExpr(final ParenExprContext ctx) { return ctx.op.accept(this); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpec.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpec.java index b9e31125bc..090903f5d3 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpec.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,15 +19,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.stream.Collectors.toList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.model.Substitution; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.sts.STS; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Optional; public final class StsSpec { @@ -46,7 +45,8 @@ static StsSpec create(final StsSpecSymbol stsSpecSymbol, final Substitution assi //// public Collection getAllSts() { - return stsSpecSymbol.getPropDeclSymbols().stream().map(s -> s.instantiate(assignment)) + return stsSpecSymbol.getPropDeclSymbols().stream() + .map(s -> s.instantiate(assignment)) .collect(toList()); } @@ -88,5 +88,4 @@ private PropDeclSymbol resolvePropDeclSymbol(final String name) { final PropDeclSymbol propDeclSymbol = (PropDeclSymbol) symbol; return propDeclSymbol; } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpecSymbol.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpecSymbol.java index 3908ca09fd..8422c823b7 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpecSymbol.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsSpecSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,12 +19,6 @@ import static hu.bme.mit.theta.sts.dsl.StsDslHelper.createConstDecl; import static hu.bme.mit.theta.sts.dsl.StsDslHelper.createVarDecl; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.ScopedSymbol; import hu.bme.mit.theta.common.dsl.Symbol; @@ -43,6 +37,11 @@ import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.StsDeclContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.StsSpecContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.VarDeclContext; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; final class StsSpecSymbol implements ScopedSymbol { @@ -103,8 +102,8 @@ public StsSpec instantiate(final List> args) { final List> simplifiedArgs = ExprUtils.simplifyAll(args); final ParamBinding binding = ParamBinding.create(params, simplifiedArgs); // TODO Handle recursive constant definitions - final Substitution constAssignment = StsDslHelper.createConstDefs(this, binding, - stsSpecContext.constDecls); + final Substitution constAssignment = + StsDslHelper.createConstDefs(this, binding, stsSpecContext.constDecls); final Substitution assignment = NestedSubstitution.create(binding, constAssignment); final StsSpec stsSpec = StsSpec.create(this, assignment); return stsSpec; @@ -159,5 +158,4 @@ private void declareProp(final PropDeclContext propDeclContext) { propDeclSymbols.add(symbol); symbolTable.add(symbol); } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsTypeCreatorVisitor.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsTypeCreatorVisitor.java index 8ea995f69f..ee0ca11286 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsTypeCreatorVisitor.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsTypeCreatorVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,9 +23,6 @@ import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; import static java.util.stream.Collectors.toList; -import java.util.Collections; -import java.util.List; - import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.sts.dsl.gen.StsDslBaseVisitor; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.ArrayTypeContext; @@ -34,13 +31,14 @@ import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.IntTypeContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RatTypeContext; import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.TypeListContext; +import java.util.Collections; +import java.util.List; final class StsTypeCreatorVisitor extends StsDslBaseVisitor { private static final StsTypeCreatorVisitor INSTANCE = new StsTypeCreatorVisitor(); - StsTypeCreatorVisitor() { - } + StsTypeCreatorVisitor() {} public static StsTypeCreatorVisitor getInstance() { return INSTANCE; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/package-info.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/package-info.java index 48b3eba287..6dc3e8f6b0 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/package-info.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/dsl/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,4 @@ * * @see hu.bme.mit.theta.sts.dsl.StsDslManager */ - -package hu.bme.mit.theta.sts.dsl; \ No newline at end of file +package hu.bme.mit.theta.sts.dsl; diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsInterpreter.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsInterpreter.java index abce2966bb..ed6a0a8619 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsInterpreter.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsInterpreter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,12 +23,7 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Function; - import com.google.common.primitives.Ints; - import hu.bme.mit.theta.common.parser.SExpr; import hu.bme.mit.theta.common.parser.SExpr.SAtom; import hu.bme.mit.theta.common.parser.SExpr.SList; @@ -41,6 +36,9 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.sts.STS; import hu.bme.mit.theta.sts.STS.Builder; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Function; final class StsInterpreter { @@ -97,7 +95,8 @@ private Object evalList(final SList slist) { if (head.isAtom()) { final String symbol = head.asAtom().getAtom(); final Object object = env.eval(symbol); - @SuppressWarnings("unchecked") final Function, ?> interpretation = (Function, ?>) object; + @SuppressWarnings("unchecked") + final Function, ?> interpretation = (Function, ?>) object; final Object value = interpretation.apply(tail); return value; } else if (head.isList()) { @@ -184,5 +183,4 @@ public void apply(final STS.Builder builder, final Expr expr) { consumer.accept(builder, expr); } } - } diff --git a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsParser.java b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsParser.java index 7c71291383..e5d3f62f93 100644 --- a/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsParser.java +++ b/subprojects/sts/sts/src/main/java/hu/bme/mit/theta/sts/parser/StsParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,12 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.io.Reader; - import hu.bme.mit.theta.common.parser.LispLexer; import hu.bme.mit.theta.common.parser.LispParser; import hu.bme.mit.theta.common.parser.SExpr; import hu.bme.mit.theta.core.parser.Env; import hu.bme.mit.theta.sts.STS; +import java.io.Reader; public final class StsParser { @@ -43,5 +42,4 @@ public STS sts() { final STS sts = interpreter.sts(sexpr); return sts; } - } diff --git a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerCoiTest.java b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerCoiTest.java index 01f0b61d85..edeef4ae89 100644 --- a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerCoiTest.java +++ b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerCoiTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,11 @@ */ package hu.bme.mit.theta.sts.aiger; +import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; +import hu.bme.mit.theta.sts.aiger.utils.AigerCoi; import java.io.IOException; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,9 +27,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; -import hu.bme.mit.theta.sts.aiger.utils.AigerCoi; - @RunWith(Parameterized.class) public class AigerCoiTest { @@ -43,19 +41,14 @@ public class AigerCoiTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"coi1.aag", 8, 3}, - - {"coi2.aag", 5, 3}, - - {"simple.aag", 6, 5}, - - {"simple2.aag", 6, 5}, - - {"simple3.aag", 7, 6}, - - }); + return Arrays.asList( + new Object[][] { + {"coi1.aag", 8, 3}, + {"coi2.aag", 5, 3}, + {"simple.aag", 6, 5}, + {"simple2.aag", 6, 5}, + {"simple3.aag", 7, 6}, + }); } @Test @@ -65,5 +58,4 @@ public void test() throws IOException { AigerCoi.apply(system); Assert.assertEquals(sizeNew, system.getNodes().size()); } - } diff --git a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerConstPropTest.java b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerConstPropTest.java index 872e1a270e..2c8cbbf8e2 100644 --- a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerConstPropTest.java +++ b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/aiger/AigerConstPropTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,12 @@ */ package hu.bme.mit.theta.sts.aiger; +import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; +import hu.bme.mit.theta.sts.aiger.utils.AigerCoi; +import hu.bme.mit.theta.sts.aiger.utils.AigerConstProp; import java.io.IOException; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,10 +28,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.sts.aiger.elements.AigerSystem; -import hu.bme.mit.theta.sts.aiger.utils.AigerCoi; -import hu.bme.mit.theta.sts.aiger.utils.AigerConstProp; - @RunWith(Parameterized.class) public class AigerConstPropTest { @@ -44,23 +42,16 @@ public class AigerConstPropTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"coi1.aag", 8, 3}, - - {"coi2.aag", 5, 1}, - - {"simple.aag", 6, 5}, - - {"simple2.aag", 6, 5}, - - {"simple3.aag", 7, 6}, - - {"constprop1.aag", 6, 1}, - - {"constprop2.aag", 6, 4}, - - }); + return Arrays.asList( + new Object[][] { + {"coi1.aag", 8, 3}, + {"coi2.aag", 5, 1}, + {"simple.aag", 6, 5}, + {"simple2.aag", 6, 5}, + {"simple3.aag", 7, 6}, + {"constprop1.aag", 6, 1}, + {"constprop2.aag", 6, 4}, + }); } @Test @@ -71,5 +62,4 @@ public void test() throws IOException { AigerCoi.apply(system); Assert.assertEquals(sizeNew, system.getNodes().size()); } - } diff --git a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/dsl/StsDslTest.java b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/dsl/StsDslTest.java index 1fb5e4800f..f77bc1c3c4 100644 --- a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/dsl/StsDslTest.java +++ b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/dsl/StsDslTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,12 +15,12 @@ */ package hu.bme.mit.theta.sts.dsl; +import hu.bme.mit.theta.sts.STS; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,8 +28,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.sts.STS; - @RunWith(Parameterized.class) public class StsDslTest { @@ -44,13 +42,11 @@ public class StsDslTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"/readerswriters.system", "safe", 3}, - - {"/simple1.system", "safe", 2} - - }); + return Arrays.asList( + new Object[][] { + {"/readerswriters.system", "safe", 3}, + {"/simple1.system", "safe", 2} + }); } @Test @@ -60,5 +56,4 @@ public void test() throws FileNotFoundException, IOException { final STS sts = spec.createProp(propertyName); Assert.assertEquals(varCount, sts.getVars().size()); } - } diff --git a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/parser/StsParserTest.java b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/parser/StsParserTest.java index a04bfdf92d..d4771bd8f2 100644 --- a/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/parser/StsParserTest.java +++ b/subprojects/sts/sts/src/test/java/hu/bme/mit/theta/sts/parser/StsParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,13 @@ */ package hu.bme.mit.theta.sts.parser; +import hu.bme.mit.theta.sts.STS; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.util.Arrays; import java.util.Collection; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -31,8 +31,6 @@ import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.sts.STS; - @RunWith(Parameterized.class) public final class StsParserTest { @@ -47,13 +45,11 @@ public final class StsParserTest { @Parameters public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"src/test/resources/simple1.lisp.sts", 2}, - - {"src/test/resources/readerswriters.lisp.sts", 3}, - - }); + return Arrays.asList( + new Object[][] { + {"src/test/resources/simple1.lisp.sts", 2}, + {"src/test/resources/readerswriters.lisp.sts", 3}, + }); } @Before @@ -74,5 +70,4 @@ public void test() { System.out.println(sts); Assert.assertEquals(vars, sts.getVars().size()); } - } diff --git a/subprojects/xcfa/c2xcfa/build.gradle.kts b/subprojects/xcfa/c2xcfa/build.gradle.kts index 0f30c1a353..45494bff7f 100644 --- a/subprojects/xcfa/c2xcfa/build.gradle.kts +++ b/subprojects/xcfa/c2xcfa/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/CMetaData.kt b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/CMetaData.kt index 9e10ca93f7..412c157ebd 100644 --- a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/CMetaData.kt +++ b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/CMetaData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 1f4e49b62f..3b85d371de 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 8ca2968aae..b983a612b0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/XcfaStatistics.kt b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/XcfaStatistics.kt index 0c5708d8cd..70f2b0d045 100644 --- a/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/XcfaStatistics.kt +++ b/subprojects/xcfa/c2xcfa/src/main/java/hu/bme/mit/theta/c2xcfa/XcfaStatistics.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/c2xcfa/src/test/java/hu/bme/mit/theta/c2xcfa/TestFrontendXcfaBuilder.kt b/subprojects/xcfa/c2xcfa/src/test/java/hu/bme/mit/theta/c2xcfa/TestFrontendXcfaBuilder.kt index d9b2f19cff..6044db3667 100644 --- a/subprojects/xcfa/c2xcfa/src/test/java/hu/bme/mit/theta/c2xcfa/TestFrontendXcfaBuilder.kt +++ b/subprojects/xcfa/c2xcfa/src/test/java/hu/bme/mit/theta/c2xcfa/TestFrontendXcfaBuilder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,71 +13,69 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.c2xcfa import hu.bme.mit.theta.common.logging.NullLogger import hu.bme.mit.theta.frontend.ParseContext +import java.io.IOException import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized -import java.io.IOException @RunWith(Parameterized::class) class TestFrontendXcfaBuilder { - @Parameterized.Parameter(0) - lateinit var filepath: String + @Parameterized.Parameter(0) lateinit var filepath: String - companion object { + companion object { - @JvmStatic - @Parameterized.Parameters - fun data(): Collection> { - return listOf( - arrayOf("/00assignment.c"), - arrayOf("/01cast.c"), - arrayOf("/02types.c"), - arrayOf("/03bitwise.c"), - arrayOf("/04real.c"), - arrayOf("/05math.c"), - arrayOf("/06arrays.c"), - arrayOf("/07arrayinit.c"), - arrayOf("/08vararray.c"), - arrayOf("/09struct.c"), - arrayOf("/10ptr.c"), - arrayOf("/11ptrs.c"), - arrayOf("/12ptrtypes.c"), - arrayOf("/13typedef.c"), - arrayOf("/14ushort.c"), - arrayOf("/15addition.c"), - arrayOf("/16loop.c"), -// arrayOf("/17recursive.c"), - arrayOf("/18multithread.c"), - arrayOf("/19dportest.c"), - arrayOf("/20testinline.c"), - arrayOf("/21namecollision.c"), - arrayOf("/22nondet.c"), - arrayOf("/23exotic.c"), - ) - } + @JvmStatic + @Parameterized.Parameters + fun data(): Collection> { + return listOf( + arrayOf("/00assignment.c"), + arrayOf("/01cast.c"), + arrayOf("/02types.c"), + arrayOf("/03bitwise.c"), + arrayOf("/04real.c"), + arrayOf("/05math.c"), + arrayOf("/06arrays.c"), + arrayOf("/07arrayinit.c"), + arrayOf("/08vararray.c"), + arrayOf("/09struct.c"), + arrayOf("/10ptr.c"), + arrayOf("/11ptrs.c"), + arrayOf("/12ptrtypes.c"), + arrayOf("/13typedef.c"), + arrayOf("/14ushort.c"), + arrayOf("/15addition.c"), + arrayOf("/16loop.c"), + // arrayOf("/17recursive.c"), + arrayOf("/18multithread.c"), + arrayOf("/19dportest.c"), + arrayOf("/20testinline.c"), + arrayOf("/21namecollision.c"), + arrayOf("/22nondet.c"), + arrayOf("/23exotic.c"), + ) } + } - @Test - @Throws(IOException::class) - fun testReachability() { + @Test + @Throws(IOException::class) + fun testReachability() { - val stream = javaClass.getResourceAsStream(filepath) + val stream = javaClass.getResourceAsStream(filepath) - getXcfaFromC(stream!!, ParseContext(), false, false, NullLogger.getInstance()) - } + getXcfaFromC(stream!!, ParseContext(), false, false, NullLogger.getInstance()) + } - @Test - @Throws(IOException::class) - fun testOverflow() { + @Test + @Throws(IOException::class) + fun testOverflow() { - val stream = javaClass.getResourceAsStream(filepath) + val stream = javaClass.getResourceAsStream(filepath) - getXcfaFromC(stream!!, ParseContext(), false, true, NullLogger.getInstance()) - } -} \ No newline at end of file + getXcfaFromC(stream!!, ParseContext(), false, true, NullLogger.getInstance()) + } +} diff --git a/subprojects/xcfa/cat/build.gradle.kts b/subprojects/xcfa/cat/build.gradle.kts index 7b94486e26..2ae60d2088 100644 --- a/subprojects/xcfa/cat/build.gradle.kts +++ b/subprojects/xcfa/cat/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -35,4 +35,3 @@ tasks.named("compileKotlin") { tasks.named("compileTestKotlin") { dependsOn("generateTestGrammarSource") } - diff --git a/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatDslManager.java b/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatDslManager.java index c7dc9917b7..314c48abb1 100644 --- a/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatDslManager.java +++ b/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/CatDslManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,26 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.cat.dsl; import hu.bme.mit.theta.cat.dsl.gen.CatLexer; import hu.bme.mit.theta.cat.dsl.gen.CatParser; import hu.bme.mit.theta.graphsolver.patterns.constraints.GraphConstraint; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Collection; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; public class CatDslManager { public static Collection createMCM(final File file) throws IOException { final CatParser.McmContext context = setupCatAntlr(file); - final hu.bme.mit.theta.cat.dsl.CatVisitor visitor = new hu.bme.mit.theta.cat.dsl.CatVisitor(file); + final hu.bme.mit.theta.cat.dsl.CatVisitor visitor = + new hu.bme.mit.theta.cat.dsl.CatVisitor(file); context.accept(visitor); return visitor.getMcm(); } @@ -51,5 +50,4 @@ static CatParser.McmContext setupCatAntlr(File file) throws IOException { inputStream.close(); return parser.mcm(); } - } 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 a9205be7f3..0f606c20a3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/FileNameAntlrErrorListener.java b/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/FileNameAntlrErrorListener.java index d5ece6ac5b..3d8c487070 100644 --- a/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/FileNameAntlrErrorListener.java +++ b/subprojects/xcfa/cat/src/main/java/hu/bme/mit/theta/cat/dsl/FileNameAntlrErrorListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.cat.dsl; import org.antlr.v4.runtime.BaseErrorListener; @@ -28,7 +27,21 @@ class FileNameAntlrErrorListener extends BaseErrorListener { } @Override - public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { - System.err.println("Syntax error in " + filename + " at " + line + ":" + charPositionInLine + ": " + msg); + public void syntaxError( + Recognizer recognizer, + Object offendingSymbol, + int line, + int charPositionInLine, + String msg, + RecognitionException e) { + System.err.println( + "Syntax error in " + + filename + + " at " + + line + + ":" + + charPositionInLine + + ": " + + msg); } } diff --git a/subprojects/xcfa/cat/src/test/java/hu/bme/mit/theta/xcfa/cat/ParseTest.java b/subprojects/xcfa/cat/src/test/java/hu/bme/mit/theta/xcfa/cat/ParseTest.java index 9aafe1a1e3..6c0a1c7f4b 100644 --- a/subprojects/xcfa/cat/src/test/java/hu/bme/mit/theta/xcfa/cat/ParseTest.java +++ b/subprojects/xcfa/cat/src/test/java/hu/bme/mit/theta/xcfa/cat/ParseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,22 @@ */ package hu.bme.mit.theta.xcfa.cat; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.theta.cat.dsl.CatDslManager; import hu.bme.mit.theta.graphsolver.compilers.DefaultGraphPatternCompiler; import hu.bme.mit.theta.graphsolver.patterns.constraints.GraphConstraint; import hu.bme.mit.theta.graphsolver.patterns.patterns.BasicEventSet; import hu.bme.mit.theta.graphsolver.patterns.patterns.BasicRelation; import hu.bme.mit.theta.graphsolver.patterns.patterns.GraphPattern; +import java.io.File; +import java.io.IOException; +import java.util.*; import org.jetbrains.annotations.NotNull; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.io.File; -import java.io.IOException; -import java.util.*; - -import static org.junit.Assert.assertEquals; - @RunWith(Parameterized.class) public class ParseTest { @Parameterized.Parameter(0) @@ -45,39 +44,45 @@ public class ParseTest { @Parameterized.Parameters() public static Collection data() { - return Arrays.asList(new Object[][]{ - {"/syntax-test/simple.cat", 3, Set.of("po", "rf")}, - {"/syntax-test/function.cat", 2, Set.of("po", "rf")}, - {"/syntax-test/procedure.cat", 2, Set.of("po", "rf")}, - {"/syntax-test/include-test.cat", 5, Set.of("po", "rf")}, - {"/sc.cat", 2, Set.of("po", "rf", "co", "rmw", "ext", "id")}, - {"/aarch64.cat", 3, null}, - {"/ppc.cat", 5, null}, - {"/X86.cat", 3, null}, - {"/svcomp.cat", 1, null}, - }); + return Arrays.asList( + new Object[][] { + {"/syntax-test/simple.cat", 3, Set.of("po", "rf")}, + {"/syntax-test/function.cat", 2, Set.of("po", "rf")}, + {"/syntax-test/procedure.cat", 2, Set.of("po", "rf")}, + {"/syntax-test/include-test.cat", 5, Set.of("po", "rf")}, + {"/sc.cat", 2, Set.of("po", "rf", "co", "rmw", "ext", "id")}, + {"/aarch64.cat", 3, null}, + {"/ppc.cat", 5, null}, + {"/X86.cat", 3, null}, + {"/svcomp.cat", 1, null}, + }); } @Test public void test() throws IOException { try { - final Collection mcm = CatDslManager.createMCM(new File(getClass().getResource(filepath).getFile())); + final Collection mcm = + CatDslManager.createMCM(new File(getClass().getResource(filepath).getFile())); assertEquals(constraintNumber, mcm.size()); if (allowedPrimitives != null) { Map basicElements = new LinkedHashMap<>(); - mcm.forEach(c -> c.accept(new DefaultGraphPatternCompiler() { - @Override - public Void compile(@NotNull BasicEventSet pattern) { - basicElements.put(pattern.getName(), pattern); - return super.compile(pattern); - } + mcm.forEach( + c -> + c.accept( + new DefaultGraphPatternCompiler() { + @Override + public Void compile(@NotNull BasicEventSet pattern) { + basicElements.put(pattern.getName(), pattern); + return super.compile(pattern); + } - @Override - public Void compile(@NotNull BasicRelation pattern) { - basicElements.put(pattern.getPatternName(), pattern); - return super.compile(pattern); - } - })); + @Override + public Void compile(@NotNull BasicRelation pattern) { + basicElements.put( + pattern.getPatternName(), pattern); + return super.compile(pattern); + } + })); assertEquals(allowedPrimitives, basicElements.keySet()); } } catch (IOException e) { diff --git a/subprojects/xcfa/litmus2xcfa/build.gradle.kts b/subprojects/xcfa/litmus2xcfa/build.gradle.kts index 8911352db0..56b6950437 100644 --- a/subprojects/xcfa/litmus2xcfa/build.gradle.kts +++ b/subprojects/xcfa/litmus2xcfa/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,4 +27,4 @@ dependencies { testImplementation(project(":theta-solver")) testImplementation(project(":theta-solver-z3-legacy")) testImplementation(project(":theta-litmus2xcfa")) -} \ No newline at end of file +} diff --git a/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/LitmusInterpreter.java b/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/LitmusInterpreter.java index 5bd6447742..1d6bfecf72 100644 --- a/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/LitmusInterpreter.java +++ b/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/LitmusInterpreter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,22 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.frontend.litmus2xcfa; import hu.bme.mit.theta.frontend.litmus2xcfa.dsl.LitmusAArch64; import hu.bme.mit.theta.litmus2xcfa.dsl.gen.LitmusAArch64Lexer; import hu.bme.mit.theta.litmus2xcfa.dsl.gen.LitmusAArch64Parser; import hu.bme.mit.theta.xcfa.model.XCFA; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.Lexer; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.Lexer; public class LitmusInterpreter { diff --git a/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/dsl/LitmusAArch64.java b/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/dsl/LitmusAArch64.java index f143194257..b53e037098 100644 --- a/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/dsl/LitmusAArch64.java +++ b/subprojects/xcfa/litmus2xcfa/src/main/java/hu/bme/mit/theta/frontend/litmus2xcfa/dsl/LitmusAArch64.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/litmus2xcfa/src/test/java/hu/bme/mit/theta/fronted/litmus2xcfa/LitmusTest.java b/subprojects/xcfa/litmus2xcfa/src/test/java/hu/bme/mit/theta/fronted/litmus2xcfa/LitmusTest.java index 32186db3f9..4a39670121 100644 --- a/subprojects/xcfa/litmus2xcfa/src/test/java/hu/bme/mit/theta/fronted/litmus2xcfa/LitmusTest.java +++ b/subprojects/xcfa/litmus2xcfa/src/test/java/hu/bme/mit/theta/fronted/litmus2xcfa/LitmusTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/build.gradle.kts b/subprojects/xcfa/llvm2xcfa/build.gradle.kts index 8c7d738775..9e6801caf6 100644 --- a/subprojects/xcfa/llvm2xcfa/build.gradle.kts +++ b/subprojects/xcfa/llvm2xcfa/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/ArithmeticType.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/ArithmeticType.java index 1fd2bd8ace..a1a68390aa 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/ArithmeticType.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/ArithmeticType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa; public enum ArithmeticType { @@ -21,4 +20,4 @@ public enum ArithmeticType { // integer_modulo, bitvector, efficient -} \ No newline at end of file +} diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/LlvmIrProvider.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/LlvmIrProvider.java index 58467f5110..69638f99e0 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/LlvmIrProvider.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/LlvmIrProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Tuple3; import hu.bme.mit.theta.common.Tuple4; - import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -32,13 +30,19 @@ public class LlvmIrProvider implements SSAProvider { System.loadLibrary("theta-llvm"); } - private final Map, Integer> bbNamefuncIndexLut; // key: BasicBlock name, value: index of function in module + private final Map, Integer> + bbNamefuncIndexLut; // key: BasicBlock name, value: index of function in module public LlvmIrProvider(String irFilename) { this(irFilename, true, true, true, true); } - public LlvmIrProvider(String irFilename, Boolean inlining, Boolean cleanup, Boolean optimization, Boolean debugPrintIr) { + public LlvmIrProvider( + String irFilename, + Boolean inlining, + Boolean cleanup, + Boolean optimization, + Boolean debugPrintIr) { if (!inlining) { JniDisableInlining(); } @@ -65,7 +69,6 @@ public LlvmIrProvider(String irFilename, Boolean inlining, Boolean cleanup, Bool bbNamefuncIndexLut.put(Tuple2.of(functionName, JniGetBlockName(f, b)), f); } } - } private native void JniParseIr(String irFilename); @@ -91,14 +94,15 @@ public LlvmIrProvider(String irFilename, Boolean inlining, Boolean cleanup, Bool public Collection> getGlobalVariables() { int numOfGlobalVar = JniGetGlobalVariablesNum(); Tuple3 globalVar; - ArrayList> globalVarList = new ArrayList>(); + ArrayList> globalVarList = + new ArrayList>(); for (int i = 0; i < numOfGlobalVar; i++) { - globalVar = Tuple3.of( - JniGetGlobalVariableName(i), - JniGetGlobalVariableType(i), - JniGetGlobalVariableValue(i) - ); + globalVar = + Tuple3.of( + JniGetGlobalVariableName(i), + JniGetGlobalVariableType(i), + JniGetGlobalVariableValue(i)); globalVarList.add(globalVar); } return globalVarList; @@ -117,13 +121,16 @@ public Collection> getGlobalVariables() { private native String JniGetParameterName(int funcIndex, int paramIndex); @Override - public Collection, List>>> getFunctions() { + public Collection, List>>> + getFunctions() { int numOfFunctions = JniGetFunctionsNum(); - ArrayList, List>>> functions = new ArrayList<>(); + ArrayList, List>>> functions = + new ArrayList<>(); for (int f = 0; f < numOfFunctions; f++) { String functionName = JniGetFunctionName(f); - String retType = JniGetFunctionRetType(f); // TODO make this really optional? (->when void) + String retType = + JniGetFunctionRetType(f); // TODO make this really optional? (->when void) int numOfParams = JniGetNumOfFunctionParameters(f); ArrayList> parameters = new ArrayList<>(); @@ -170,19 +177,34 @@ public List getBlocks(String funcName) { private native String JniGetInstructionRetName(int functionIndex, int basicBlockIndex, int i); - private native int JniGetInstructionNumOfOperands(int functionIndex, int basicBlockIndex, int i); + private native int JniGetInstructionNumOfOperands( + int functionIndex, int basicBlockIndex, int i); - private native String JniGetInstructionOperandVarType(int functionIndex, int basicBlockIndex, int i, int o); + private native String JniGetInstructionOperandVarType( + int functionIndex, int basicBlockIndex, int i, int o); - private native String JniGetInstructionOperandVarName(int functionIndex, int basicBlockIndex, int i, int o); + private native String JniGetInstructionOperandVarName( + int functionIndex, int basicBlockIndex, int i, int o); @Override - public List>, List, String>>, Integer>> getInstructions(String funcName, String blockName) { + public List< + Tuple4< + String, + Optional>, + List, String>>, + Integer>> + getInstructions(String funcName, String blockName) { int functionIndex = bbNamefuncIndexLut.get(Tuple2.of(funcName, blockName)); int basicBlockIndex = JniGetBlockIndex(functionIndex, blockName); int numOfInstructions = JniGetNumOfInstructions(functionIndex, basicBlockIndex); - ArrayList>, List, String>>, Integer>> instructions = new ArrayList<>(); + ArrayList< + Tuple4< + String, + Optional>, + List, String>>, + Integer>> + instructions = new ArrayList<>(); for (int i = 0; i < numOfInstructions; i++) { int lineNumber = JniGetInstructionLineNumber(functionIndex, basicBlockIndex, i); String opcode = JniGetInstructionOpcode(functionIndex, basicBlockIndex, i); @@ -191,8 +213,10 @@ public List>, List, String>> instructionOperands = new ArrayList<>(); for (int o = 0; o < numOfOperands; o++) { - String varType = JniGetInstructionOperandVarType(functionIndex, basicBlockIndex, i, o); - String varName = JniGetInstructionOperandVarName(functionIndex, basicBlockIndex, i, o); + String varType = + JniGetInstructionOperandVarType(functionIndex, basicBlockIndex, i, o); + String varName = + JniGetInstructionOperandVarName(functionIndex, basicBlockIndex, i, o); if (varType.equals("constant")) { instructionOperands.add(Tuple2.of(Optional.empty(), varName)); } else { @@ -201,9 +225,15 @@ public List>, List>, List, String>>, Integer>> getInstructions(String funcName, String blockName); + List< + Tuple4< + String, + Optional>, + List, String>>, + Integer>> + getInstructions(String funcName, String blockName); // Analysis results /* diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/Utils.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/Utils.java index 13b3ab00f7..22c61a3691 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/Utils.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/XcfaUtils.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/XcfaUtils.java index c212c7a4c6..78e4c6142c 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/XcfaUtils.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/XcfaUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Tuple3; import hu.bme.mit.theta.common.Tuple4; @@ -28,15 +29,12 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; import hu.bme.mit.theta.xcfa.model.XCFA; import hu.bme.mit.theta.xcfa.passes.ProcedurePass; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; import java.util.Optional; -import static com.google.common.base.Preconditions.checkState; - @SuppressWarnings("unused") public class XcfaUtils { /* @@ -52,14 +50,16 @@ public static XCFA fromFile(File model, ArithmeticType arithmeticType) throws IO return createXCFA(new LlvmIrProvider(model.getAbsolutePath()), arithmeticType); } else if (model.getName().endsWith("c") || model.getName().endsWith("i")) { - return createXCFA(new LlvmIrProvider(model.getAbsolutePath(), true, true, true, true), arithmeticType); + return createXCFA( + new LlvmIrProvider(model.getAbsolutePath(), true, true, true, true), + arithmeticType); } else { String[] split = model.getName().split("\\."); if (split.length > 0) - throw new RuntimeException("File type " + split[split.length - 1] + " not supported."); + throw new RuntimeException( + "File type " + split[split.length - 1] + " not supported."); throw new RuntimeException("File does not have an extension."); - } } @@ -74,7 +74,8 @@ public static XCFA createXCFA(SSAProvider ssa, ArithmeticType arithmeticType) { * Creates an XCFA from the provided SSAProvider using its getter methods. * Runs the specified passes when a specific stage is complete. */ - public static XCFA createXCFA(SSAProvider ssa, List procedurePasses, ArithmeticType arithmeticType) { + public static XCFA createXCFA( + SSAProvider ssa, List procedurePasses, ArithmeticType arithmeticType) { if (ssa.hasStructs()) { throw new UnsupportedOperationException("Structs are not yet supported!"); } @@ -86,26 +87,39 @@ public static XCFA createXCFA(SSAProvider ssa, List procedurePass System.out.println("Using integer arithmetic!"); arithmeticType = ArithmeticType.integer; } - checkState(!ssa.shouldUseBitwiseArithmetics() || arithmeticType == ArithmeticType.bitvector, "There are statements in the source not mappable to integer arithmetic"); + checkState( + !ssa.shouldUseBitwiseArithmetics() || arithmeticType == ArithmeticType.bitvector, + "There are statements in the source not mappable to integer arithmetic"); Utils.arithmeticType = arithmeticType; BuiltState builtState = new BuiltState(); GlobalState globalState = new GlobalState(ssa, arithmeticType); - for (Tuple3, List>> function : ssa.getFunctions()) { + for (Tuple3, List>> function : + ssa.getFunctions()) { if (function.get1().equals("reach_error")) continue; FunctionState functionState = new FunctionState(globalState, function); for (String block : ssa.getBlocks(function.get1())) { BlockState blockState = new BlockState(functionState, block); - InstructionHandlerManager instructionHandlerManager = new InstructionHandlerManager(arithmeticType); - for (Tuple4>, List, String>>, Integer> instruction : ssa.getInstructions(function.get1(), block)) { + InstructionHandlerManager instructionHandlerManager = + new InstructionHandlerManager(arithmeticType); + for (Tuple4< + String, + Optional>, + List, String>>, + Integer> + instruction : ssa.getInstructions(function.get1(), block)) { try { - InstructionHandler instructionHandler = instructionHandlerManager.createInstructionHandlers(); - instructionHandler.handleInstruction(new Instruction(instruction), globalState, functionState, blockState); + InstructionHandler instructionHandler = + instructionHandlerManager.createInstructionHandlers(); + instructionHandler.handleInstruction( + new Instruction(instruction), + globalState, + functionState, + blockState); } catch (ReflectiveOperationException e) { e.printStackTrace(); } - } } @@ -116,45 +130,54 @@ public static XCFA createXCFA(SSAProvider ssa, List procedurePass } builtState.getProcedures().put(function.get1(), functionState.getProcedureBuilder()); - } return globalState.getBuilder().build(); } -// -// if(builtState.getProcedures().size() > 1) { -// System.err.println("Inlining failed."); -// System.exit(-80); -// } -// -// builtState.getProcedures().forEach((s, builder) -> { -// if(builder.getErrorLoc() == null) { -// System.err.println("Frontend failed"); -// System.exit(-80); -// } -// }); -// -// final XCFA.Builder builder = globalState.getBuilder(); -// -// return new XCFA(builder.getGlobalVars(), -// List.of( -// xcfa -> new XcfaProcess("proc", -// List.of(), -// Map.of(), -// builtState.getProcedures().entrySet().stream().map(e -> -// (Function) -// (XcfaProcess xcfaProc) -> new XcfaProcedure( -// e.getKey(), -// Map.of(), -// e.getValue().getLocalVars(), -// e.getValue().getLocs(), -// e.getValue().getRetType(), -// e.getValue().getInitLoc(), -// e.getValue().getErrorLoc(), -// e.getValue().getFinalLoc(), -// e.getValue().getEdges(), -// xcfaProc) -// ).collect(Collectors.toList()), -// xcfa)), -// "xcfa", -// true); + // + // if(builtState.getProcedures().size() > 1) { + // System.err.println("Inlining failed."); + // System.exit(-80); + // } + // + // builtState.getProcedures().forEach((s, builder) -> { + // if(builder.getErrorLoc() == null) { + // System.err.println("Frontend failed"); + // System.exit(-80); + // } + // }); + // + // final XCFA.Builder builder = globalState.getBuilder(); + // + // return new XCFA(builder.getGlobalVars(), + // List.of( + // xcfa -> new XcfaProcess("proc", + // List.of(), + // Map.of(), + // + // builtState.getProcedures().entrySet().stream().map(e -> + // (Function) + // (XcfaProcess xcfaProc) -> new + // XcfaProcedure( + // e.getKey(), + // Map.of(), + // + // e.getValue().getLocalVars(), + // + // e.getValue().getLocs(), + // + // e.getValue().getRetType(), + // + // e.getValue().getInitLoc(), + // + // e.getValue().getErrorLoc(), + // + // e.getValue().getFinalLoc(), + // + // e.getValue().getEdges(), + // xcfaProc) + // ).collect(Collectors.toList()), + // xcfa)), + // "xcfa", + // true); } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/BaseInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/BaseInstructionHandler.java index d54e05c6a1..37a8849bc4 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/BaseInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/BaseInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers; import hu.bme.mit.theta.llvm2xcfa.handlers.states.BlockState; @@ -30,7 +29,11 @@ public void setNext(InstructionHandler instructionHandler) { } @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { if (next != null) next.handleInstruction(instruction, globalState, functionState, blockState); } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/Instruction.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/Instruction.java index f1749f7216..a467278b88 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/Instruction.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/Instruction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,34 +13,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Tuple4; import hu.bme.mit.theta.llvm2xcfa.handlers.arguments.Argument; import hu.bme.mit.theta.llvm2xcfa.handlers.arguments.RegArgument; - import java.util.ArrayList; import java.util.List; import java.util.Optional; -import static com.google.common.base.Preconditions.checkState; - public class Instruction { private final String opName; private final Optional retVar; private final List arguments; private final Integer lineNumber; - public Instruction(Tuple4>, List, String>>, Integer> instr) { + public Instruction( + Tuple4< + String, + Optional>, + List, String>>, + Integer> + instr) { Argument arg = null; if (instr.get2().isPresent()) { arg = Argument.of(instr.get2().get().get1(), instr.get2().get().get2()); checkState(arg instanceof RegArgument, "Argument not instance of RegArgument!"); } this.opName = instr.get1(); - this.retVar = instr.get2().isPresent() ? Optional.ofNullable((RegArgument) arg) : Optional.empty(); + this.retVar = + instr.get2().isPresent() + ? Optional.ofNullable((RegArgument) arg) + : Optional.empty(); this.arguments = new ArrayList<>(); for (Tuple2, String> objects : instr.get3()) { this.arguments.add(Argument.of(objects.get1().orElse(""), objects.get2())); @@ -66,11 +73,16 @@ public Integer getLineNumber() { @Override public String toString() { - return "Instruction{" + - "opName='" + opName + '\'' + - ", retVar=" + retVar + - ", arguments=" + arguments + - ", lineNumber=" + lineNumber + - '}'; + return "Instruction{" + + "opName='" + + opName + + '\'' + + ", retVar=" + + retVar + + ", arguments=" + + arguments + + ", lineNumber=" + + lineNumber + + '}'; } } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandler.java index 1d4c399963..1cc2e22652 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers; import hu.bme.mit.theta.llvm2xcfa.handlers.states.BlockState; @@ -24,6 +23,9 @@ public interface InstructionHandler { void setNext(InstructionHandler instructionHandler); - void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState); - + void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState); } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandlerManager.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandlerManager.java index dcf1bf0381..614539ad65 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandlerManager.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/InstructionHandlerManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers; import hu.bme.mit.theta.llvm2xcfa.ArithmeticType; @@ -30,40 +29,39 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.concrete.UnaryInstructionHandler; import hu.bme.mit.theta.llvm2xcfa.handlers.concrete.VectorInstructionHandler; import hu.bme.mit.theta.llvm2xcfa.handlers.concrete.checks.PointerArithmeticCheck; - import java.util.List; public class InstructionHandlerManager { - private static final List> defaultInstructionHandlers = List.of( - PointerArithmeticCheck.class, - BuiltinFunctionHandler.class, - ArrayIntrinsicsHandler.class, - TerminatorInstructionHandler.class, - UnaryInstructionHandler.class, - BinaryInstructionHandler.class, - BitwiseInstructionHandler.class, - VectorInstructionHandler.class, - AggregateInstructionHandler.class, - MemoryInstructionHandler.class, - ConversionInstructionHandler.class, - OtherInstructionHandler.class - ); - private static final List> bitvectorInstructionHandlers = List.of( - PointerArithmeticCheck.class, - BitvectorInstructionHandler.class, - BuiltinFunctionHandler.class, - ArrayIntrinsicsHandler.class, - TerminatorInstructionHandler.class, - UnaryInstructionHandler.class, - BinaryInstructionHandler.class, - BitwiseInstructionHandler.class, - VectorInstructionHandler.class, - AggregateInstructionHandler.class, - MemoryInstructionHandler.class, - ConversionInstructionHandler.class, - OtherInstructionHandler.class - ); + private static final List> defaultInstructionHandlers = + List.of( + PointerArithmeticCheck.class, + BuiltinFunctionHandler.class, + ArrayIntrinsicsHandler.class, + TerminatorInstructionHandler.class, + UnaryInstructionHandler.class, + BinaryInstructionHandler.class, + BitwiseInstructionHandler.class, + VectorInstructionHandler.class, + AggregateInstructionHandler.class, + MemoryInstructionHandler.class, + ConversionInstructionHandler.class, + OtherInstructionHandler.class); + private static final List> bitvectorInstructionHandlers = + List.of( + PointerArithmeticCheck.class, + BitvectorInstructionHandler.class, + BuiltinFunctionHandler.class, + ArrayIntrinsicsHandler.class, + TerminatorInstructionHandler.class, + UnaryInstructionHandler.class, + BinaryInstructionHandler.class, + BitwiseInstructionHandler.class, + VectorInstructionHandler.class, + AggregateInstructionHandler.class, + MemoryInstructionHandler.class, + ConversionInstructionHandler.class, + OtherInstructionHandler.class); private final List> instructionHandlers; public InstructionHandlerManager(ArithmeticType arithmeticType) { @@ -74,7 +72,8 @@ public InstructionHandlerManager(ArithmeticType arithmeticType) { } } - public InstructionHandlerManager(List> instructionHandlers) { + public InstructionHandlerManager( + List> instructionHandlers) { this.instructionHandlers = instructionHandlers; } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/Argument.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/Argument.java index 4ff0c98451..d7684c9403 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/Argument.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/Argument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.arguments; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.Map; public abstract class Argument { diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/ConstantArgument.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/ConstantArgument.java index 7f79fcec95..5785773c0b 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/ConstantArgument.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/ConstantArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,17 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.arguments; +import static hu.bme.mit.theta.llvm2xcfa.Utils.createConstant; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.Type; - import java.util.Map; -import static hu.bme.mit.theta.llvm2xcfa.Utils.createConstant; - public class ConstantArgument extends Argument { private final LitExpr expr; diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LabelArgument.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LabelArgument.java index 4bc5986cc6..b1e95f0585 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LabelArgument.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LabelArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.arguments; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.Map; public class LabelArgument extends Argument { diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LocalArgument.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LocalArgument.java index e5912f7059..d7f84a38ad 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LocalArgument.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/LocalArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.arguments; public class LocalArgument extends RegArgument { diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/RegArgument.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/RegArgument.java index 0c938d99cd..a5145a182a 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/RegArgument.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/RegArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,16 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.arguments; +import static hu.bme.mit.theta.llvm2xcfa.Utils.createType; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.Map; -import static hu.bme.mit.theta.llvm2xcfa.Utils.createType; - public class RegArgument extends Argument { private final String name; private final Type type; diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/StringArgument.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/StringArgument.java index 121c6bd11d..06e987ef49 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/StringArgument.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/arguments/StringArgument.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.arguments; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; - import java.util.Map; public class StringArgument extends Argument { diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/AggregateInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/AggregateInstructionHandler.java index aedddbd4b6..41fcae19f9 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/AggregateInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/AggregateInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; import hu.bme.mit.theta.llvm2xcfa.handlers.BaseInstructionHandler; @@ -24,7 +23,11 @@ public class AggregateInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "extractvalue": extractvalue(instruction, globalState, functionState, blockState); @@ -36,14 +39,21 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void insertvalue(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void insertvalue( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void extractvalue(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void extractvalue( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ArrayIntrinsicsHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ArrayIntrinsicsHandler.java index 0d6cc6e5a6..38c9657fe9 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ArrayIntrinsicsHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ArrayIntrinsicsHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BinaryInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BinaryInstructionHandler.java index 4dfd5f4e57..74cfd9f537 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BinaryInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BinaryInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Div; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Rem; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Sub; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; + import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatExprs; import hu.bme.mit.theta.core.type.rattype.RatType; @@ -26,18 +34,13 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.FunctionState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Add; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Div; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mul; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Rem; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Sub; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; - public class BinaryInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "add": add(instruction, globalState, functionState, blockState); @@ -75,10 +78,13 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void frem(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void frem( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); @@ -87,10 +93,16 @@ private void frem(Instruction instruction, GlobalState globalState, FunctionStat checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); // TODO: semantics of FREM? throw new RuntimeException("Frem semantics is not yet implemented!"); - //foldExpression(instruction, functionState, blockState, null, RatExprs.Rem(cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), 0); + // foldExpression(instruction, functionState, blockState, null, + // RatExprs.Rem(cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), + // cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), 0); } - private void rem(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void rem( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); @@ -98,87 +110,190 @@ private void rem(Instruction instruction, GlobalState globalState, FunctionState checkState(op2.getType() == IntType.getInstance(), "Rem only supports integer types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Rem(cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + Rem( + cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), + cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), + 0); } - private void fdiv(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fdiv( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == RatType.getInstance(), "Fdiv only supports rational types!"); checkState(op2.getType() == RatType.getInstance(), "Fdiv only supports rational types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, RatExprs.Div(cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + RatExprs.Div( + cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), + cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), + 0); } - private void div(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void div( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == IntType.getInstance(), "Div only supports integer types!"); checkState(op2.getType() == IntType.getInstance(), "Div only supports integer types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Div(cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + Div( + cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), + cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), + 0); } - private void fmul(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fmul( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == RatType.getInstance(), "Fmul only supports rational types!"); checkState(op2.getType() == RatType.getInstance(), "Fmul only supports rational types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, RatExprs.Mul(cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + RatExprs.Mul( + cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), + cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), + 0); } - private void mul(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void mul( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == IntType.getInstance(), "Mul only supports integer types!"); checkState(op2.getType() == IntType.getInstance(), "Mul only supports integer types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Mul(cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + Mul( + cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), + cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), + 0); } - private void fsub(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fsub( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == RatType.getInstance(), "Fsub only supports rational types!"); checkState(op2.getType() == RatType.getInstance(), "Fsub only supports rational types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, RatExprs.Sub(cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + RatExprs.Sub( + cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), + cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), + 0); } - private void sub(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sub( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == IntType.getInstance(), "Sub only supports integer types!"); checkState(op2.getType() == IntType.getInstance(), "Sub only supports integer types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Sub(cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + Sub( + cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), + cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), + 0); } - private void fadd(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fadd( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == RatType.getInstance(), "Fadd only supports rational types!"); checkState(op2.getType() == RatType.getInstance(), "Fadd only supports rational types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, RatExprs.Add(cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + RatExprs.Add( + cast(op1.getExpr(functionState.getValues()), RatType.getInstance()), + cast(op2.getExpr(functionState.getValues()), RatType.getInstance())), + 0); } - private void add(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void add( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == IntType.getInstance(), "Rem only supports integer types!"); checkState(op2.getType() == IntType.getInstance(), "Rem only supports integer types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Add(cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + Add( + cast(op1.getExpr(functionState.getValues()), IntType.getInstance()), + cast(op2.getExpr(functionState.getValues()), IntType.getInstance())), + 0); } - } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitvectorInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitvectorInstructionHandler.java index 8022d5accf..a0fb096895 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitvectorInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitvectorInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; + 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.BvExprs; @@ -28,17 +31,16 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.BlockState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.FunctionState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; - import java.math.BigInteger; import java.util.List; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; - public class BitvectorInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "icmp": icmp(instruction, globalState, functionState, blockState); @@ -110,58 +112,124 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void trunc(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void trunc( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - BigInteger newSize = BigInteger.valueOf(((BvType) instruction.getRetVar().get().getType()).getSize()); + BigInteger newSize = + BigInteger.valueOf(((BvType) instruction.getRetVar().get().getType()).getSize()); BigInteger oldSize = BigInteger.valueOf(((BvType) op1.getType()).getSize()); - foldExpression(instruction, functionState, blockState, null, BvExprs.Extract(cast(op1.getExpr(functionState.getValues()), (BvType) op1.getType()), IntLitExpr.of(oldSize.subtract(newSize)), IntLitExpr.of(oldSize)), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Extract( + cast(op1.getExpr(functionState.getValues()), (BvType) op1.getType()), + IntLitExpr.of(oldSize.subtract(newSize)), + IntLitExpr.of(oldSize)), + 0); } - private void zext(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void zext( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - //TODO: bool exprs? - foldExpression(instruction, functionState, blockState, null, BvExprs.ZExt(cast(op1.getExpr(functionState.getValues()), (BvType) op1.getType()), (BvType) instruction.getRetVar().get().getType()), 0); + // TODO: bool exprs? + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.ZExt( + cast(op1.getExpr(functionState.getValues()), (BvType) op1.getType()), + (BvType) instruction.getRetVar().get().getType()), + 0); } - private void sext(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sext( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.SExt(cast(op1.getExpr(functionState.getValues()), (BvType) op1.getType()), (BvType) instruction.getRetVar().get().getType()), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SExt( + cast(op1.getExpr(functionState.getValues()), (BvType) op1.getType()), + (BvType) instruction.getRetVar().get().getType()), + 0); } - private void fptoui(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fptoui( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void fptosi(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fptosi( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void uitofp(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void uitofp( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void sitofp(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sitofp( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void bitcast(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void bitcast( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - BigInteger newSize = BigInteger.valueOf(((BvType) instruction.getRetVar().get().getType()).getSize()); + BigInteger newSize = + BigInteger.valueOf(((BvType) instruction.getRetVar().get().getType()).getSize()); BigInteger oldSize = BigInteger.valueOf(((BvType) op1.getType()).getSize()); if (newSize.subtract(oldSize).signum() == 1) { zext(instruction, globalState, functionState, blockState); @@ -169,202 +237,596 @@ private void bitcast(Instruction instruction, GlobalState globalState, FunctionS trunc(instruction, globalState, functionState, blockState); } if (functionState.getLocalVars().containsKey(op1.getName())) { - functionState.getLocalVars().put(instruction.getRetVar().get().getName(), functionState.getLocalVars().get(op1.getName())); + functionState + .getLocalVars() + .put( + instruction.getRetVar().get().getName(), + functionState.getLocalVars().get(op1.getName())); } } - - private void icmp(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void icmp( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); Argument op3 = instruction.getArguments().get(2); - checkState(op1 instanceof StringArgument, "Icmp has to have string argument as first operand!"); - checkState(op2.getType() instanceof BvType, "Bitvector Icmp only supports bitvector types!"); - checkState(op3.getType() instanceof BvType, "Bitvector Icmp only supports bitvector types!"); + checkState( + op1 instanceof StringArgument, + "Icmp has to have string argument as first operand!"); + checkState( + op2.getType() instanceof BvType, "Bitvector Icmp only supports bitvector types!"); + checkState( + op3.getType() instanceof BvType, "Bitvector Icmp only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); switch (op1.getName()) { case "eq": - foldExpression(instruction, functionState, blockState, null, BvExprs.Eq(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Eq( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "ne": - foldExpression(instruction, functionState, blockState, null, BvExprs.Neq(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Neq( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "ugt": - foldExpression(instruction, functionState, blockState, null, BvExprs.UGt(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.UGt( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "sgt": - foldExpression(instruction, functionState, blockState, null, BvExprs.SGt(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SGt( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "uge": - foldExpression(instruction, functionState, blockState, null, BvExprs.UGeq(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.UGeq( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "sge": - foldExpression(instruction, functionState, blockState, null, BvExprs.SGeq(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SGeq( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "ult": - foldExpression(instruction, functionState, blockState, null, BvExprs.ULt(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.ULt( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "slt": - foldExpression(instruction, functionState, blockState, null, BvExprs.SLt(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SLt( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "ule": - foldExpression(instruction, functionState, blockState, null, BvExprs.ULeq(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.ULeq( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; case "sle": - foldExpression(instruction, functionState, blockState, null, BvExprs.SLeq(cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op3.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SLeq( + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op3.getExpr(functionState.getValues()), + (BvType) op2.getType())), + 0); break; default: throw new IllegalStateException("Unexpected value: " + op1.getName()); } } - private void urem(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void urem( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.URem(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.URem( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void srem(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void srem( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.SRem(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SRem( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void udiv(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void udiv( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.UDiv(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.UDiv( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void sdiv(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sdiv( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.SDiv(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.SDiv( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void mul(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void mul( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.Mul(List.of(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()))), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Mul( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()))), + 0); } - private void sub(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sub( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.Sub(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Sub( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void add(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void add( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.Add(List.of(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()))), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Add( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()))), + 0); } - private void shl(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void shl( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.ShiftLeft(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); - + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.ShiftLeft( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void lshr(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void lshr( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.LogicShiftRight(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); - + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.LogicShiftRight( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void ashr(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void ashr( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.ArithShiftRight(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), 0); - + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.ArithShiftRight( + cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType())), + 0); } - private void and(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void and( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); if (op1.getType() instanceof BoolType && op2.getType() instanceof BoolType) { - foldExpression(instruction, functionState, blockState, null, BoolExprs.And(List.of(cast(op1.getExpr(functionState.getValues()), (BoolType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BoolType) op2.getType()))), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BoolExprs.And( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BoolType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BoolType) op2.getType()))), + 0); return; } - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - foldExpression(instruction, functionState, blockState, null, BvExprs.And(List.of(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()))), 0); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.And( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()))), + 0); } - private void or(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void or( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); if (op1.getType() instanceof BoolType && op2.getType() instanceof BoolType) { - foldExpression(instruction, functionState, blockState, null, BoolExprs.Or(List.of(cast(op1.getExpr(functionState.getValues()), (BoolType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BoolType) op2.getType()))), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BoolExprs.Or( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BoolType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BoolType) op2.getType()))), + 0); return; } - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, BvExprs.Or(List.of(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()))), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Or( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()))), + 0); } - private void xor(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void xor( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); if (op1.getType() instanceof BoolType && op2.getType() instanceof BoolType) { - foldExpression(instruction, functionState, blockState, null, BoolExprs.Xor(cast(op1.getExpr(functionState.getValues()), (BoolType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BoolType) op2.getType())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + BoolExprs.Xor( + cast(op1.getExpr(functionState.getValues()), (BoolType) op2.getType()), + cast(op2.getExpr(functionState.getValues()), (BoolType) op2.getType())), + 0); return; } - checkState(op1.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - checkState(op2.getType() instanceof BvType, "Bitvector instructions only supports bitvector types!"); - foldExpression(instruction, functionState, blockState, null, BvExprs.Xor(List.of(cast(op1.getExpr(functionState.getValues()), (BvType) op2.getType()), cast(op2.getExpr(functionState.getValues()), (BvType) op2.getType()))), 0); - + checkState( + op1.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + checkState( + op2.getType() instanceof BvType, + "Bitvector instructions only supports bitvector types!"); + foldExpression( + instruction, + functionState, + blockState, + null, + BvExprs.Xor( + List.of( + cast( + op1.getExpr(functionState.getValues()), + (BvType) op2.getType()), + cast( + op2.getExpr(functionState.getValues()), + (BvType) op2.getType()))), + 0); } } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitwiseInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitwiseInstructionHandler.java index a56c53c0d9..6de5a4ed66 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitwiseInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BitwiseInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Xor; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; + import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.llvm2xcfa.handlers.BaseInstructionHandler; import hu.bme.mit.theta.llvm2xcfa.handlers.Instruction; @@ -24,16 +30,13 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.FunctionState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Xor; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; - public class BitwiseInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "shl": shl(instruction, globalState, functionState, blockState); @@ -57,51 +60,95 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void shl(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void shl( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void lshr(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void lshr( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void ashr(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void ashr( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void and(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void and( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == BoolType.getInstance(), "And only supports boolean types!"); checkState(op2.getType() == BoolType.getInstance(), "And only supports boolean types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, And(cast(op1.getExpr(functionState.getValues()), BoolType.getInstance()), cast(op2.getExpr(functionState.getValues()), BoolType.getInstance())), 0); + foldExpression( + instruction, + functionState, + blockState, + null, + And( + cast(op1.getExpr(functionState.getValues()), BoolType.getInstance()), + cast(op2.getExpr(functionState.getValues()), BoolType.getInstance())), + 0); } - private void or(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void or( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == BoolType.getInstance(), "Or only supports boolean types!"); checkState(op2.getType() == BoolType.getInstance(), "Or only supports boolean types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Or(cast(op1.getExpr(functionState.getValues()), BoolType.getInstance()), cast(op2.getExpr(functionState.getValues()), BoolType.getInstance())), 0); - + foldExpression( + instruction, + functionState, + blockState, + null, + Or( + cast(op1.getExpr(functionState.getValues()), BoolType.getInstance()), + cast(op2.getExpr(functionState.getValues()), BoolType.getInstance())), + 0); } - private void xor(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void xor( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); Argument op2 = instruction.getArguments().get(1); checkState(op1.getType() == BoolType.getInstance(), "Xor only supports boolean types!"); checkState(op2.getType() == BoolType.getInstance(), "Xor only supports boolean types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, Xor(cast(op1.getExpr(functionState.getValues()), BoolType.getInstance()), cast(op2.getExpr(functionState.getValues()), BoolType.getInstance())), 0); - + foldExpression( + instruction, + functionState, + blockState, + null, + Xor( + cast(op1.getExpr(functionState.getValues()), BoolType.getInstance()), + cast(op2.getExpr(functionState.getValues()), BoolType.getInstance())), + 0); } - } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BuiltinFunctionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BuiltinFunctionHandler.java index a57d42b09b..fff410730a 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BuiltinFunctionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/BuiltinFunctionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; import hu.bme.mit.theta.llvm2xcfa.LlvmMetadata; @@ -25,24 +24,30 @@ import hu.bme.mit.theta.xcfa.model.NopLabel; import hu.bme.mit.theta.xcfa.model.XcfaEdge; import hu.bme.mit.theta.xcfa.model.XcfaLocation; - import java.util.Collection; import java.util.List; public class BuiltinFunctionHandler extends BaseInstructionHandler { - private final static Collection SVCOMP_ERROR_FUNCTIONS = List.of("__assert_fail", "__VERIFIER_error", "abort", "reach_error"); - private final static Collection SVCOMP_NEWTHREAD_FUNCTIONS = List.of("theta_pthread_create"); - private final static Collection SVCOMP_JOINTHREAD_FUNCTIONS = List.of("pthread_join"); - private final static Collection SVCOMP_ATOMIC_BEGIN = List.of("__VERIFIER_atomic_begin"); - private final static Collection SVCOMP_ATOMIC_END = List.of("__VERIFIER_atomic_end"); - private final static Collection ATOMIC_READ = List.of("atomic_load_explicit"); - private final static Collection ATOMIC_WRITE = List.of("atomic_store_explicit"); - + private static final Collection SVCOMP_ERROR_FUNCTIONS = + List.of("__assert_fail", "__VERIFIER_error", "abort", "reach_error"); + private static final Collection SVCOMP_NEWTHREAD_FUNCTIONS = + List.of("theta_pthread_create"); + private static final Collection SVCOMP_JOINTHREAD_FUNCTIONS = List.of("pthread_join"); + private static final Collection SVCOMP_ATOMIC_BEGIN = + List.of("__VERIFIER_atomic_begin"); + private static final Collection SVCOMP_ATOMIC_END = List.of("__VERIFIER_atomic_end"); + private static final Collection ATOMIC_READ = List.of("atomic_load_explicit"); + private static final Collection ATOMIC_WRITE = List.of("atomic_store_explicit"); @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { if (instruction.getOpName().equals("call")) { - String functionName = instruction.getArguments().get(instruction.getArguments().size() - 1).getName(); + String functionName = + instruction.getArguments().get(instruction.getArguments().size() - 1).getName(); if (SVCOMP_ERROR_FUNCTIONS.contains(functionName)) { error(instruction, globalState, functionState, blockState); return; @@ -51,10 +56,19 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); } - private void error(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void error( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { functionState.getProcedureBuilder().createErrorLoc(); XcfaLocation newLoc = functionState.getProcedureBuilder().getErrorLoc().get(); - XcfaEdge edge = new XcfaEdge(blockState.getLastLocation(), newLoc, NopLabel.INSTANCE, new LlvmMetadata(instruction.getLineNumber())); + XcfaEdge edge = + new XcfaEdge( + blockState.getLastLocation(), + newLoc, + NopLabel.INSTANCE, + new LlvmMetadata(instruction.getLineNumber())); functionState.getProcedureBuilder().addEdge(edge); blockState.setLastLocation(newLoc); } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ConversionInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ConversionInstructionHandler.java index ad6e3a5cec..56441bddfb 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ConversionInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/ConversionInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.type.anytype.Exprs.Ite; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; @@ -27,18 +32,15 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.BlockState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.FunctionState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; - import java.math.BigInteger; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.type.anytype.Exprs.Ite; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; - public class ConversionInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "trunc": trunc(instruction, globalState, functionState, blockState); @@ -78,70 +80,163 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void trunc(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void trunc( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); checkState(op.getType() == IntType.getInstance(), "Only integer values are allowed!"); checkState(instruction.getRetVar().isPresent(), "Load must load into a variable"); - foldExpression(instruction, functionState, blockState, op.getName(), functionState.getValues().get(op.getName()), 0); + foldExpression( + instruction, + functionState, + blockState, + op.getName(), + functionState.getValues().get(op.getName()), + 0); } - private void zext(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void zext( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); - checkState(op.getType() == IntType.getInstance() || op.getType() == BoolType.getInstance(), "Only integer/boolean values are allowed!"); + checkState( + op.getType() == IntType.getInstance() || op.getType() == BoolType.getInstance(), + "Only integer/boolean values are allowed!"); checkState(instruction.getRetVar().isPresent(), "Load must load into a variable"); - foldExpression(instruction, functionState, blockState, op.getName(), op.getType() == BoolType.getInstance() ? Ite(cast(functionState.getValues().get(op.getName()), BoolType.getInstance()), IntLitExpr.of(BigInteger.ONE), IntLitExpr.of(BigInteger.ZERO)) : functionState.getValues().get(op.getName()), 0); + foldExpression( + instruction, + functionState, + blockState, + op.getName(), + op.getType() == BoolType.getInstance() + ? Ite( + cast( + functionState.getValues().get(op.getName()), + BoolType.getInstance()), + IntLitExpr.of(BigInteger.ONE), + IntLitExpr.of(BigInteger.ZERO)) + : functionState.getValues().get(op.getName()), + 0); } - private void sext(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sext( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); - checkState(op.getType() == IntType.getInstance() || op.getType() == BoolType.getInstance(), "Only integer/boolean values are allowed!"); + checkState( + op.getType() == IntType.getInstance() || op.getType() == BoolType.getInstance(), + "Only integer/boolean values are allowed!"); checkState(instruction.getRetVar().isPresent(), "Load must load into a variable"); - foldExpression(instruction, functionState, blockState, op.getName(), op.getType() == BoolType.getInstance() ? Ite(cast(functionState.getValues().get(op.getName()), BoolType.getInstance()), IntLitExpr.of(BigInteger.ONE), IntLitExpr.of(BigInteger.ZERO)) : functionState.getValues().get(op.getName()), 0); + foldExpression( + instruction, + functionState, + blockState, + op.getName(), + op.getType() == BoolType.getInstance() + ? Ite( + cast( + functionState.getValues().get(op.getName()), + BoolType.getInstance()), + IntLitExpr.of(BigInteger.ONE), + IntLitExpr.of(BigInteger.ZERO)) + : functionState.getValues().get(op.getName()), + 0); } - private void fptrunc(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fptrunc( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); checkState(op.getType() == RatType.getInstance(), "Only rational values are allowed!"); checkState(instruction.getRetVar().isPresent(), "Load must load into a variable"); - foldExpression(instruction, functionState, blockState, op.getName(), functionState.getValues().get(op.getName()), 0); + foldExpression( + instruction, + functionState, + blockState, + op.getName(), + functionState.getValues().get(op.getName()), + 0); } - private void fpext(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fpext( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); checkState(op.getType() == RatType.getInstance(), "Only rational values are allowed!"); checkState(instruction.getRetVar().isPresent(), "Load must load into a variable"); - foldExpression(instruction, functionState, blockState, op.getName(), functionState.getValues().get(op.getName()), 0); + foldExpression( + instruction, + functionState, + blockState, + op.getName(), + functionState.getValues().get(op.getName()), + 0); } - private void fptoui(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fptoui( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); checkState(op.getType() == RatType.getInstance(), "Only rational values are allowed!"); checkState(instruction.getRetVar().isPresent(), "Fptoui must load into a variable"); Expr expr = cast(functionState.getValues().get(op.getName()), Rat()); -// foldExpression(instruction, functionState, blockState, op.getName(), , 0); + // foldExpression(instruction, functionState, blockState, op.getName(), , 0); throw new RuntimeException("Not yet implemented!"); } - private void fptosi(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fptosi( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void uitofp(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void uitofp( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void sitofp(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sitofp( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void bitcast(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void bitcast( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op = instruction.getArguments().get(0); checkState(instruction.getRetVar().isPresent(), "Load must load into a variable"); - foldExpression(instruction, functionState, blockState, op.getName(), functionState.getValues().get(op.getName()), 0); + foldExpression( + instruction, + functionState, + blockState, + op.getName(), + functionState.getValues().get(op.getName()), + 0); } } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/MemoryInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/MemoryInstructionHandler.java index cf6132e31a..c0849193d6 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/MemoryInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/MemoryInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/OtherInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/OtherInstructionHandler.java index 1109a27361..5be933fb08 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/OtherInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/OtherInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/TerminatorInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/TerminatorInstructionHandler.java index f2ee090799..2f2afe4673 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/TerminatorInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/TerminatorInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.stmt.Stmts.Assign; +import static hu.bme.mit.theta.core.stmt.Stmts.Assume; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Tuple4; import hu.bme.mit.theta.core.decl.VarDecl; @@ -32,26 +37,22 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.BlockState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.FunctionState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; -import hu.bme.mit.theta.xcfa.model.EmptyMetaData; import hu.bme.mit.theta.xcfa.model.NopLabel; import hu.bme.mit.theta.xcfa.model.SequenceLabel; import hu.bme.mit.theta.xcfa.model.StmtLabel; import hu.bme.mit.theta.xcfa.model.XcfaEdge; import hu.bme.mit.theta.xcfa.model.XcfaLocation; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.stmt.Stmts.Assign; -import static hu.bme.mit.theta.core.stmt.Stmts.Assume; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public class TerminatorInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "ret": ret(instruction, globalState, functionState, blockState); @@ -76,18 +77,30 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void unreachable(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void unreachable( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { functionState.getProcedureBuilder().createErrorLoc(); XcfaLocation errLoc = functionState.getProcedureBuilder().getErrorLoc().get(); - XcfaEdge edge = new XcfaEdge(blockState.getLastLocation(), errLoc, NopLabel.INSTANCE, new LlvmMetadata(instruction.getLineNumber())); + XcfaEdge edge = + new XcfaEdge( + blockState.getLastLocation(), + errLoc, + NopLabel.INSTANCE, + new LlvmMetadata(instruction.getLineNumber())); functionState.getProcedureBuilder().addEdge(edge); blockState.setLastLocation(errLoc); } - private void ret(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void ret( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { List stmts = new ArrayList<>(); VarDecl retVar = functionState.getReturnVar(); switch (instruction.getArguments().size()) { @@ -96,28 +109,73 @@ private void ret(Instruction instruction, GlobalState globalState, FunctionState break; case 1: checkState(retVar != null, "Returning a value from void function!"); - Stmt assignStmt = Assign(cast(retVar, retVar.getType()), cast(instruction.getArguments().get(0).getExpr(functionState.getValues()), retVar.getType())); + Stmt assignStmt = + Assign( + cast(retVar, retVar.getType()), + cast( + instruction + .getArguments() + .get(0) + .getExpr(functionState.getValues()), + retVar.getType())); stmts.add(assignStmt); break; default: - throw new IllegalStateException("Unexpected value: " + instruction.getArguments().size()); + throw new IllegalStateException( + "Unexpected value: " + instruction.getArguments().size()); } - XcfaEdge edge = new XcfaEdge(blockState.getLastLocation(), functionState.getProcedureBuilder().getFinalLoc().orElseThrow(), new SequenceLabel(stmts.stream().map(stmt -> new StmtLabel(stmt)).toList()), new LlvmMetadata(instruction.getLineNumber())); + XcfaEdge edge = + new XcfaEdge( + blockState.getLastLocation(), + functionState.getProcedureBuilder().getFinalLoc().orElseThrow(), + new SequenceLabel(stmts.stream().map(stmt -> new StmtLabel(stmt)).toList()), + new LlvmMetadata(instruction.getLineNumber())); functionState.getProcedureBuilder().addEdge(edge); blockState.setLastLocation(functionState.getProcedureBuilder().getFinalLoc().orElseThrow()); } - private void br(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void br( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getArguments().size()) { case 1: - XcfaLocation loc = functionState.getLocations().get(instruction.getArguments().get(0).getName()); + XcfaLocation loc = + functionState + .getLocations() + .get(instruction.getArguments().get(0).getName()); Tuple2 key = Tuple2.of(blockState.getName(), loc.getName()); - List stmts = functionState.getInterBlockEdges().getOrDefault(key, Tuple4.of(blockState.getLastLocation(), loc, new ArrayList<>(), -1)).get3(); - functionState.getInterBlockEdges().put(key, Tuple4.of(blockState.getLastLocation(), loc, stmts, instruction.getLineNumber())); + List stmts = + functionState + .getInterBlockEdges() + .getOrDefault( + key, + Tuple4.of( + blockState.getLastLocation(), + loc, + new ArrayList<>(), + -1)) + .get3(); + functionState + .getInterBlockEdges() + .put( + key, + Tuple4.of( + blockState.getLastLocation(), + loc, + stmts, + instruction.getLineNumber())); break; case 3: - XcfaLocation loc1 = functionState.getLocations().get(instruction.getArguments().get(1).getName()); - XcfaLocation loc2 = functionState.getLocations().get(instruction.getArguments().get(2).getName()); + XcfaLocation loc1 = + functionState + .getLocations() + .get(instruction.getArguments().get(1).getName()); + XcfaLocation loc2 = + functionState + .getLocations() + .get(instruction.getArguments().get(2).getName()); Expr lhs = instruction.getArguments().get(0).getExpr(functionState.getValues()); boolean lhsType = lhs.getType() == BoolType.getInstance(); @@ -125,41 +183,113 @@ private void br(Instruction instruction, GlobalState globalState, FunctionState AssumeStmt assume1 = Assume(cast(lhs, BoolType.getInstance())); AssumeStmt assume2 = Assume(BoolExprs.Not(cast(lhs, BoolType.getInstance()))); key = Tuple2.of(blockState.getName(), loc1.getName()); - stmts = functionState.getInterBlockEdges().getOrDefault(key, Tuple4.of(blockState.getLastLocation(), loc1, new ArrayList<>(), -1)).get3(); + stmts = + functionState + .getInterBlockEdges() + .getOrDefault( + key, + Tuple4.of( + blockState.getLastLocation(), + loc1, + new ArrayList<>(), + -1)) + .get3(); stmts.add(assume1); - functionState.getInterBlockEdges().put(key, Tuple4.of(blockState.getLastLocation(), loc1, stmts, instruction.getLineNumber())); + functionState + .getInterBlockEdges() + .put( + key, + Tuple4.of( + blockState.getLastLocation(), + loc1, + stmts, + instruction.getLineNumber())); key = Tuple2.of(blockState.getName(), loc2.getName()); - stmts = functionState.getInterBlockEdges().getOrDefault(key, Tuple4.of(blockState.getLastLocation(), loc1, new ArrayList<>(), -1)).get3(); + stmts = + functionState + .getInterBlockEdges() + .getOrDefault( + key, + Tuple4.of( + blockState.getLastLocation(), + loc1, + new ArrayList<>(), + -1)) + .get3(); stmts.add(assume2); - functionState.getInterBlockEdges().put(key, Tuple4.of(blockState.getLastLocation(), loc2, stmts, instruction.getLineNumber())); + functionState + .getInterBlockEdges() + .put( + key, + Tuple4.of( + blockState.getLastLocation(), + loc2, + stmts, + instruction.getLineNumber())); break; default: - throw new IllegalStateException("Unexpected value: " + instruction.getArguments().size()); + throw new IllegalStateException( + "Unexpected value: " + instruction.getArguments().size()); } blockState.setLastLocation(functionState.getProcedureBuilder().getFinalLoc().get()); } - private void sw(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void sw( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Expr varExpr = instruction.getArguments().get(0).getExpr(functionState.getValues()); Expr defaultBranch = null; for (int i = 0; i < (instruction.getArguments().size() / 2) - 1; ++i) { - XcfaLocation loc = functionState.getLocations().get(instruction.getArguments().get(2 + 2 * i + 1).getName()); - Expr constExpr = instruction.getArguments().get(2 + 2 * i).getExpr(functionState.getValues()); - checkState(varExpr.getType().equals(constExpr.getType()), "variable and constant should be of the same type!"); - EqExpr eq = AbstractExprs.Eq(cast(varExpr, constExpr.getType()), cast(constExpr, constExpr.getType())); + XcfaLocation loc = + functionState + .getLocations() + .get(instruction.getArguments().get(2 + 2 * i + 1).getName()); + Expr constExpr = + instruction.getArguments().get(2 + 2 * i).getExpr(functionState.getValues()); + checkState( + varExpr.getType().equals(constExpr.getType()), + "variable and constant should be of the same type!"); + EqExpr eq = + AbstractExprs.Eq( + cast(varExpr, constExpr.getType()), + cast(constExpr, constExpr.getType())); if (defaultBranch == null) defaultBranch = eq; else defaultBranch = Or(defaultBranch, eq); AssumeStmt assume = Assume(eq); Tuple2 key = Tuple2.of(blockState.getName(), loc.getName()); - List stmts = functionState.getInterBlockEdges().getOrDefault(key, Tuple4.of(blockState.getLastLocation(), loc, new ArrayList<>(), -1)).get3(); + List stmts = + functionState + .getInterBlockEdges() + .getOrDefault( + key, + Tuple4.of( + blockState.getLastLocation(), + loc, + new ArrayList<>(), + -1)) + .get3(); stmts.add(assume); - functionState.getInterBlockEdges().put(key, Tuple4.of(blockState.getLastLocation(), loc, stmts, instruction.getLineNumber())); + functionState + .getInterBlockEdges() + .put( + key, + Tuple4.of( + blockState.getLastLocation(), + loc, + stmts, + instruction.getLineNumber())); } - XcfaLocation loc = functionState.getLocations().get(instruction.getArguments().get(1).getName()); - XcfaEdge edge = new XcfaEdge(blockState.getLastLocation(), loc, new StmtLabel(Assume(BoolExprs.Not(defaultBranch))), new LlvmMetadata(instruction.getLineNumber())); + XcfaLocation loc = + functionState.getLocations().get(instruction.getArguments().get(1).getName()); + XcfaEdge edge = + new XcfaEdge( + blockState.getLastLocation(), + loc, + new StmtLabel(Assume(BoolExprs.Not(defaultBranch))), + new LlvmMetadata(instruction.getLineNumber())); functionState.getProcedureBuilder().addEdge(edge); blockState.setLastLocation(functionState.getProcedureBuilder().getFinalLoc().get()); } - - } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/UnaryInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/UnaryInstructionHandler.java index 9e51e68a39..bf79460e7d 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/UnaryInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/UnaryInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; +import static com.google.common.base.Preconditions.checkState; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; + import hu.bme.mit.theta.core.type.rattype.RatExprs; import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.llvm2xcfa.handlers.BaseInstructionHandler; @@ -25,13 +28,13 @@ import hu.bme.mit.theta.llvm2xcfa.handlers.states.FunctionState; import hu.bme.mit.theta.llvm2xcfa.handlers.states.GlobalState; -import static com.google.common.base.Preconditions.checkState; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.llvm2xcfa.Utils.foldExpression; - public class UnaryInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "fneg": fneg(instruction, globalState, functionState, blockState); @@ -40,15 +43,23 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void fneg(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void fneg( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { Argument op1 = instruction.getArguments().get(0); checkState(op1.getType() == RatType.getInstance(), "Fneg only supports rational types!"); checkState(instruction.getRetVar().isPresent(), "Instruction must have return variable"); - foldExpression(instruction, functionState, blockState, null, RatExprs.Neg(cast(op1.getExpr(functionState.getValues()), RatType.getInstance())), 0); - + foldExpression( + instruction, + functionState, + blockState, + null, + RatExprs.Neg(cast(op1.getExpr(functionState.getValues()), RatType.getInstance())), + 0); } } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/VectorInstructionHandler.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/VectorInstructionHandler.java index 80ae2ec890..9c54f75d17 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/VectorInstructionHandler.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/VectorInstructionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete; import hu.bme.mit.theta.llvm2xcfa.handlers.BaseInstructionHandler; @@ -24,7 +23,11 @@ public class VectorInstructionHandler extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "extractelement": extractelement(instruction, globalState, functionState, blockState); @@ -38,15 +41,22 @@ public void handleInstruction(Instruction instruction, GlobalState globalState, super.handleInstruction(instruction, globalState, functionState, blockState); break; } - } - private void insertelement(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void insertelement( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } - private void extractelement(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + private void extractelement( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { throw new RuntimeException("Not yet implemented!"); } } diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/checks/PointerArithmeticCheck.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/checks/PointerArithmeticCheck.java index 23006cbfc0..dc1cc98b5b 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/checks/PointerArithmeticCheck.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/concrete/checks/PointerArithmeticCheck.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.concrete.checks; import hu.bme.mit.theta.llvm2xcfa.handlers.BaseInstructionHandler; @@ -24,12 +23,17 @@ public class PointerArithmeticCheck extends BaseInstructionHandler { @Override - public void handleInstruction(Instruction instruction, GlobalState globalState, FunctionState functionState, BlockState blockState) { + public void handleInstruction( + Instruction instruction, + GlobalState globalState, + FunctionState functionState, + BlockState blockState) { switch (instruction.getOpName()) { case "getelementptr": case "ptrtoint": case "inttoptr": - throw new UnsupportedOperationException("Pointer arithmetic or structs are not yet supported!"); + throw new UnsupportedOperationException( + "Pointer arithmetic or structs are not yet supported!"); default: super.handleInstruction(instruction, globalState, functionState, blockState); break; diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BlockState.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BlockState.java index f3bf0e3da4..77fa5715c3 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BlockState.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BlockState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.states; import hu.bme.mit.theta.xcfa.model.XcfaLocation; diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BuiltState.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BuiltState.java index e5db89d24c..2a5812a346 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BuiltState.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/BuiltState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,17 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.states; +import static com.google.common.base.Preconditions.checkState; + import hu.bme.mit.theta.xcfa.model.XCFA; import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder; - import java.util.HashMap; import java.util.Map; -import static com.google.common.base.Preconditions.checkState; - public class BuiltState { private XCFA xcfa; private Map procedures; diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/FunctionState.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/FunctionState.java index 691cee8555..fdaa0cd61d 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/FunctionState.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/FunctionState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/GlobalState.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/GlobalState.java index 96286d2dd6..1d035b967a 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/GlobalState.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/states/GlobalState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.states; +import static hu.bme.mit.theta.llvm2xcfa.Utils.createConstant; +import static hu.bme.mit.theta.llvm2xcfa.Utils.createVariable; + import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.Tuple3; import hu.bme.mit.theta.core.decl.VarDecl; @@ -23,16 +25,12 @@ import hu.bme.mit.theta.llvm2xcfa.SSAProvider; import hu.bme.mit.theta.xcfa.model.XcfaBuilder; import hu.bme.mit.theta.xcfa.model.XcfaGlobalVar; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import static hu.bme.mit.theta.llvm2xcfa.Utils.createConstant; -import static hu.bme.mit.theta.llvm2xcfa.Utils.createVariable; - public class GlobalState { private final XcfaBuilder builder; private final Map> globalVars; @@ -52,14 +50,15 @@ public GlobalState(SSAProvider ssa, ArithmeticType arithmeticType) { for (Tuple3 globalVariable : ssa.getGlobalVariables()) { VarDecl variable = createVariable(globalVariable.get1(), globalVariable.get2()); globalVars.put(globalVariable.get1(), variable); - builder.addVar(new XcfaGlobalVar(variable, createConstant(variable.getType(), globalVariable.get3()))); + builder.addVar( + new XcfaGlobalVar( + variable, createConstant(variable.getType(), globalVariable.get3()))); } procedures.addAll(ssa.getFunctions()); } - public void finalizeGlobalState(BuiltState builtState) { - } + public void finalizeGlobalState(BuiltState builtState) {} public Map> getGlobalVars() { return globalVars; diff --git a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/utils/PlaceholderAssignmentStmt.java b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/utils/PlaceholderAssignmentStmt.java index d7fc66b6ed..c50c8e255a 100644 --- a/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/utils/PlaceholderAssignmentStmt.java +++ b/subprojects/xcfa/llvm2xcfa/src/main/java/hu/bme/mit/theta/llvm2xcfa/handlers/utils/PlaceholderAssignmentStmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa.handlers.utils; +import static hu.bme.mit.theta.core.stmt.Stmts.Assign; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.stmt.AssignStmt; import hu.bme.mit.theta.core.stmt.Stmt; @@ -23,12 +25,8 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.llvm2xcfa.handlers.arguments.Argument; - import java.util.Map; -import static hu.bme.mit.theta.core.stmt.Stmts.Assign; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public class PlaceholderAssignmentStmt implements Stmt { private final VarDecl lhs; private final Argument rhsKey; @@ -38,7 +36,8 @@ private PlaceholderAssignmentStmt(VarDecl lhs, Argument rhsKey) { this.rhsKey = rhsKey; } - public static PlaceholderAssignmentStmt of(VarDecl lhs, Argument rhsKey) { + public static PlaceholderAssignmentStmt of( + VarDecl lhs, Argument rhsKey) { return new PlaceholderAssignmentStmt(lhs, rhsKey); } diff --git a/subprojects/xcfa/llvm2xcfa/src/test/java/hu/bme/mit/theta/llvm2xcfa/TestLlvm2Xcfa.kt b/subprojects/xcfa/llvm2xcfa/src/test/java/hu/bme/mit/theta/llvm2xcfa/TestLlvm2Xcfa.kt index 3e21beeab5..fd2f106c3d 100644 --- a/subprojects/xcfa/llvm2xcfa/src/test/java/hu/bme/mit/theta/llvm2xcfa/TestLlvm2Xcfa.kt +++ b/subprojects/xcfa/llvm2xcfa/src/test/java/hu/bme/mit/theta/llvm2xcfa/TestLlvm2Xcfa.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,85 +13,85 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.llvm2xcfa import hu.bme.mit.theta.common.OsHelper import hu.bme.mit.theta.llvm2xcfa.XcfaUtils.fromFile +import java.io.File import org.junit.jupiter.api.Assumptions import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.MethodSource -import java.io.File class TestLlvm2Xcfa { - companion object { - - @JvmStatic - fun data(): Collection> { - return listOf( - arrayOf("/c/every_inst.c"), - arrayOf("/c/example_addition.c"), - arrayOf("/c/example_binbitwiseop.c"), - arrayOf("/c/example_branch.c"), - arrayOf("/c/example_decl.c"), - arrayOf("/c/example_func_param.c"), - arrayOf("/c/example_global_scanf.c"), - arrayOf("/c/example_struct.c"), - arrayOf("/c/example_void_func.c"), - arrayOf("/c/test_locks_14-2.c"), + companion object { - arrayOf("/c/dekker.i"), - arrayOf("/c/00assignment.c"), -// arrayOf("/c/01cast.c"), - arrayOf("/c/02types.c"), - arrayOf("/c/03bitwise.c"), -// arrayOf("/c/04real.c"), -// arrayOf("/c/05math.c"), - arrayOf("/c/06arrays.c"), - arrayOf("/c/07arrayinit.c"), - arrayOf("/c/08vararray.c"), -// arrayOf("/c/09struct.c"), - arrayOf("/c/10ptr.c"), - arrayOf("/c/11ptrs.c"), - arrayOf("/c/12ptrtypes.c"), - arrayOf("/c/13typedef.c"), - arrayOf("/c/14ushort.c"), - arrayOf("/c/15addition.c"), - arrayOf("/c/16loop.c"), -// arrayOf("/c/17recursive.c"), - arrayOf("/c/18multithread.c"), - arrayOf("/c/19dportest.c"), - arrayOf("/c/20testinline.c"), - arrayOf("/c/21namecollision.c"), -// arrayOf("/c/22nondet.c"), - arrayOf("/c/23overflow.c"), - ) - } + @JvmStatic + fun data(): Collection> { + return listOf( + arrayOf("/c/every_inst.c"), + arrayOf("/c/example_addition.c"), + arrayOf("/c/example_binbitwiseop.c"), + arrayOf("/c/example_branch.c"), + arrayOf("/c/example_decl.c"), + arrayOf("/c/example_func_param.c"), + arrayOf("/c/example_global_scanf.c"), + arrayOf("/c/example_struct.c"), + arrayOf("/c/example_void_func.c"), + arrayOf("/c/test_locks_14-2.c"), + arrayOf("/c/dekker.i"), + arrayOf("/c/00assignment.c"), + // arrayOf("/c/01cast.c"), + arrayOf("/c/02types.c"), + arrayOf("/c/03bitwise.c"), + // arrayOf("/c/04real.c"), + // arrayOf("/c/05math.c"), + arrayOf("/c/06arrays.c"), + arrayOf("/c/07arrayinit.c"), + arrayOf("/c/08vararray.c"), + // arrayOf("/c/09struct.c"), + arrayOf("/c/10ptr.c"), + arrayOf("/c/11ptrs.c"), + arrayOf("/c/12ptrtypes.c"), + arrayOf("/c/13typedef.c"), + arrayOf("/c/14ushort.c"), + arrayOf("/c/15addition.c"), + arrayOf("/c/16loop.c"), + // arrayOf("/c/17recursive.c"), + arrayOf("/c/18multithread.c"), + arrayOf("/c/19dportest.c"), + arrayOf("/c/20testinline.c"), + arrayOf("/c/21namecollision.c"), + // arrayOf("/c/22nondet.c"), + arrayOf("/c/23overflow.c"), + ) + } - @BeforeAll - @JvmStatic - fun testOS() { - Assumptions.assumeTrue(OsHelper.getOs() == OsHelper.OperatingSystem.LINUX) // only linux can handle llvm - } + @BeforeAll + @JvmStatic + fun testOS() { + Assumptions.assumeTrue( + OsHelper.getOs() == OsHelper.OperatingSystem.LINUX + ) // only linux can handle llvm } + } - @ParameterizedTest - @MethodSource("data") - fun testEfficient(filepath: String) { - val fileName = javaClass.getResource(filepath)!!.file - println("Parsing using LLVM: $filepath") + @ParameterizedTest + @MethodSource("data") + fun testEfficient(filepath: String) { + val fileName = javaClass.getResource(filepath)!!.file + println("Parsing using LLVM: $filepath") - fromFile(File(fileName), ArithmeticType.efficient) - } + fromFile(File(fileName), ArithmeticType.efficient) + } - @ParameterizedTest - @MethodSource("data") - fun testBitvector(filepath: String) { - val fileName = javaClass.getResource(filepath)!!.file - println("Parsing using LLVM: $filepath") + @ParameterizedTest + @MethodSource("data") + fun testBitvector(filepath: String) { + val fileName = javaClass.getResource(filepath)!!.file + println("Parsing using LLVM: $filepath") - fromFile(File(fileName), ArithmeticType.bitvector) - } -} \ No newline at end of file + fromFile(File(fileName), ArithmeticType.bitvector) + } +} diff --git a/subprojects/xcfa/xcfa-analysis/build.gradle.kts b/subprojects/xcfa/xcfa-analysis/build.gradle.kts index 39e7ef2c12..864ceb5421 100644 --- a/subprojects/xcfa/xcfa-analysis/build.gradle.kts +++ b/subprojects/xcfa/xcfa-analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 621731ead9..da6fd14425 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 e93dbb1ff1..8753eb3041 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaActionAdapter.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaActionAdapter.kt index d5eb56d3e0..3dc1bcf7cf 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaActionAdapter.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaActionAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis import com.google.gson.Gson @@ -26,33 +25,34 @@ import hu.bme.mit.theta.xcfa.model.XcfaEdge class XcfaActionAdapter(val gsonSupplier: () -> Gson) : TypeAdapter() { - private lateinit var gson: Gson - override fun write(writer: JsonWriter, value: XcfaAction) { - initGson() - writer.beginObject() - writer.name("pid").value(value.pid) - writer.name("edge") - gson.toJson(gson.toJsonTree(value.edge), writer) - writer.endObject() - } + private lateinit var gson: Gson - override fun read(reader: JsonReader): XcfaAction { - initGson() - var pid: Int? = null - lateinit var edge: XcfaEdge - lateinit var state: XcfaState> - reader.beginObject() - while (reader.peek() != JsonToken.END_OBJECT) { - when (reader.nextName()) { - "pid" -> pid = reader.nextInt() - "edge" -> edge = gson.fromJson(reader, XcfaEdge::class.java) - } - } - reader.endObject() - return XcfaAction(pid!!, edge) - } + override fun write(writer: JsonWriter, value: XcfaAction) { + initGson() + writer.beginObject() + writer.name("pid").value(value.pid) + writer.name("edge") + gson.toJson(gson.toJsonTree(value.edge), writer) + writer.endObject() + } - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() + override fun read(reader: JsonReader): XcfaAction { + initGson() + var pid: Int? = null + lateinit var edge: XcfaEdge + lateinit var state: XcfaState> + reader.beginObject() + while (reader.peek() != JsonToken.END_OBJECT) { + when (reader.nextName()) { + "pid" -> pid = reader.nextInt() + "edge" -> edge = gson.fromJson(reader, XcfaEdge::class.java) + } } -} \ No newline at end of file + reader.endObject() + return XcfaAction(pid!!, edge) + } + + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} 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 1b41de5b1d..026d11059e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaArgAbstractor.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaArgAbstractor.kt index bc2d2b816c..00c890127e 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaArgAbstractor.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaArgAbstractor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrec.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrec.kt index e9389ad7f3..7c5ea91210 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrec.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/XcfaPrec.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,23 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis import hu.bme.mit.theta.analysis.Prec import hu.bme.mit.theta.core.decl.VarDecl -data class XcfaPrec

(val p: P, val noPop: MutableList> = mutableListOf()) : Prec { +data class XcfaPrec

(val p: P, val noPop: MutableList> = mutableListOf()) : + Prec { - override fun getUsedVars(): Collection> { - return p.usedVars - } + override fun getUsedVars(): Collection> { + return p.usedVars + } - fun refine(runningPrec: P): XcfaPrec

{ - return if (this.p == runningPrec) { - this - } else { - XcfaPrec(runningPrec) - } + fun refine(runningPrec: P): XcfaPrec

{ + return if (this.p == runningPrec) { + this + } else { + XcfaPrec(runningPrec) } -} \ No newline at end of file + } +} 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 4d85422207..467f01d8ce 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 4ca545dd9b..ec2fe464fe 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 41b35eccc3..a21045c5aa 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 bcfff87c7d..d7105f6cca 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 a890e95edc..13bafa97b2 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoi.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoi.kt index 54b9e7f658..8fe5710bea 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoi.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoi.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis.coi import hu.bme.mit.theta.analysis.LTS @@ -39,154 +38,178 @@ import kotlin.math.min lateinit var ConeOfInfluence: XcfaCoi internal typealias S = XcfaState> + internal typealias A = XcfaAction internal var XcfaAction.transFuncVersion: XcfaAction? by nullableExtension() abstract class XcfaCoi(protected val xcfa: XCFA) { - var coreLts: LTS = getXcfaLts() - lateinit var coreTransFunc: TransFunc> - - protected var lastPrec: Prec? = null - protected var XcfaLocation.scc: Int by extension() - protected val directObservers: MutableMap> = mutableMapOf() + var coreLts: LTS = getXcfaLts() + lateinit var coreTransFunc: TransFunc> - abstract val lts: LTS + protected var lastPrec: Prec? = null + protected var XcfaLocation.scc: Int by extension() + protected val directObservers: MutableMap> = mutableMapOf() - val transFunc = TransFunc> { state, action, prec -> - coreTransFunc.getSuccStates(state, action.transFuncVersion ?: action, prec) - } + abstract val lts: LTS - init { - xcfa.procedures.forEach { tarjan(it.initLoc) } + val transFunc = + TransFunc> { state, action, prec -> + coreTransFunc.getSuccStates(state, action.transFuncVersion ?: action, prec) } - private fun tarjan(initLoc: XcfaLocation) { - var sccCnt = 0 - var discCnt = 0 - val disc = mutableMapOf() - val lowest = mutableMapOf() - val visited = mutableSetOf() - val stack = Stack() - val toVisit = Stack() - toVisit.push(initLoc) - - while (toVisit.isNotEmpty()) { - val visiting = toVisit.peek() - if (visiting !in visited) { - disc[visiting] = discCnt++ - lowest[visiting] = disc[visiting]!! - stack.push(visiting) - visited.add(visiting) - } - - for (edge in visiting.outgoingEdges) { - if (edge.target in stack) { - lowest[visiting] = min(lowest[visiting]!!, lowest[edge.target]!!) - } else if (edge.target !in visited) { - toVisit.push(edge.target) - break - } - } - - if (toVisit.peek() != visiting) continue - - if (lowest[visiting] == disc[visiting]) { - val scc = sccCnt++ - while (stack.peek() != visiting) { - stack.pop().scc = scc - } - stack.pop().scc = scc // visiting - } - - toVisit.pop() + init { + xcfa.procedures.forEach { tarjan(it.initLoc) } + } + + private fun tarjan(initLoc: XcfaLocation) { + var sccCnt = 0 + var discCnt = 0 + val disc = mutableMapOf() + val lowest = mutableMapOf() + val visited = mutableSetOf() + val stack = Stack() + val toVisit = Stack() + toVisit.push(initLoc) + + while (toVisit.isNotEmpty()) { + val visiting = toVisit.peek() + if (visiting !in visited) { + disc[visiting] = discCnt++ + lowest[visiting] = disc[visiting]!! + stack.push(visiting) + visited.add(visiting) + } + + for (edge in visiting.outgoingEdges) { + if (edge.target in stack) { + lowest[visiting] = min(lowest[visiting]!!, lowest[edge.target]!!) + } else if (edge.target !in visited) { + toVisit.push(edge.target) + break } - } + } - protected fun findDirectObservers(edge: XcfaEdge, prec: Prec) { - val precVars = prec.usedVars - val writtenVars = edge.collectVarsWithAccessType() - .filter { it.value.isWritten && it.key in precVars } // TODO deref it.key in prec? - if (writtenVars.isEmpty()) return - val writtenMemLocs = writtenVars.pointsTo(xcfa) - - val toVisit = edge.target.outgoingEdges.toMutableList() - val visited = mutableSetOf() - while (toVisit.isNotEmpty()) { - val visiting = toVisit.removeFirst() - visited.add(visiting) - val currentVars = visiting.collectVarsWithAccessType() - addEdgeIfObserved(edge, visiting, writtenVars, writtenMemLocs, precVars, directObservers, currentVars) - - if (writtenMemLocs.size <= 1) { - val currentWrites = currentVars.filter { it.value.isWritten }.map { it.key } - if (writtenVars.all { it.key in currentWrites }) { - val currentMemWrites = currentWrites.pointsTo(xcfa) - if (currentMemWrites.size <= 1 && writtenMemLocs.all { it in currentMemWrites }) { - continue - } - } - } + if (toVisit.peek() != visiting) continue - toVisit.addAll(visiting.target.outgoingEdges.filter { it !in visited }) + if (lowest[visiting] == disc[visiting]) { + val scc = sccCnt++ + while (stack.peek() != visiting) { + stack.pop().scc = scc } - } + stack.pop().scc = scc // visiting + } - protected open fun addEdgeIfObserved( - source: XcfaEdge, target: XcfaEdge, observableVars: VarAccessMap, - writtenMemLocs: Set>, precVars: Collection>, - relation: MutableMap>, vars: VarAccessMap = target.collectVarsWithAccessType() - ) { - var relevantAction = vars.any { it.value.isWritten && it.key in precVars } - if (!relevantAction) { - val assumeVars = target.label.collectAssumesVars() - relevantAction = assumeVars.any { it in precVars } + toVisit.pop() + } + } + + protected fun findDirectObservers(edge: XcfaEdge, prec: Prec) { + val precVars = prec.usedVars + val writtenVars = + edge.collectVarsWithAccessType().filter { + it.value.isWritten && it.key in precVars + } // TODO deref it.key in prec? + if (writtenVars.isEmpty()) return + val writtenMemLocs = writtenVars.pointsTo(xcfa) + + val toVisit = edge.target.outgoingEdges.toMutableList() + val visited = mutableSetOf() + while (toVisit.isNotEmpty()) { + val visiting = toVisit.removeFirst() + visited.add(visiting) + val currentVars = visiting.collectVarsWithAccessType() + addEdgeIfObserved( + edge, + visiting, + writtenVars, + writtenMemLocs, + precVars, + directObservers, + currentVars, + ) + + if (writtenMemLocs.size <= 1) { + val currentWrites = currentVars.filter { it.value.isWritten }.map { it.key } + if (writtenVars.all { it.key in currentWrites }) { + val currentMemWrites = currentWrites.pointsTo(xcfa) + if (currentMemWrites.size <= 1 && writtenMemLocs.all { it in currentMemWrites }) { + continue + } } + } - val readVars = vars.filter { it.value.isRead } - if (relevantAction && (readVars.any { it.key in observableVars } || - readVars.pointsTo(xcfa).any { it in writtenMemLocs })) { - addToRelation(source, target, relation) - } + toVisit.addAll(visiting.target.outgoingEdges.filter { it !in visited }) + } + } + + protected open fun addEdgeIfObserved( + source: XcfaEdge, + target: XcfaEdge, + observableVars: VarAccessMap, + writtenMemLocs: Set>, + precVars: Collection>, + relation: MutableMap>, + vars: VarAccessMap = target.collectVarsWithAccessType(), + ) { + var relevantAction = vars.any { it.value.isWritten && it.key in precVars } + if (!relevantAction) { + val assumeVars = target.label.collectAssumesVars() + relevantAction = assumeVars.any { it in precVars } } - protected abstract fun addToRelation( - source: XcfaEdge, target: XcfaEdge, - relation: MutableMap> - ) - - protected fun isRealObserver(edge: XcfaEdge) = edge.label.collectAssumesVars().isNotEmpty() - - protected fun replace(action: A, prec: Prec): XcfaAction { - val replacedLabel = action.label.replace(prec) - action.transFuncVersion = action.withLabel(replacedLabel.run { - if (this !is SequenceLabel) SequenceLabel(listOf(this)) else this - }) - return action + val readVars = vars.filter { it.value.isRead } + if ( + relevantAction && + (readVars.any { it.key in observableVars } || + readVars.pointsTo(xcfa).any { it in writtenMemLocs }) + ) { + addToRelation(source, target, relation) } + } + + protected abstract fun addToRelation( + source: XcfaEdge, + target: XcfaEdge, + relation: MutableMap>, + ) + + protected fun isRealObserver(edge: XcfaEdge) = edge.label.collectAssumesVars().isNotEmpty() + + protected fun replace(action: A, prec: Prec): XcfaAction { + val replacedLabel = action.label.replace(prec) + action.transFuncVersion = + action.withLabel( + replacedLabel.run { if (this !is SequenceLabel) SequenceLabel(listOf(this)) else this } + ) + return action + } + + private fun XcfaLabel.replace(prec: Prec): XcfaLabel = + when (this) { + is SequenceLabel -> SequenceLabel(labels.map { it.replace(prec) }, metadata) + is NondetLabel -> NondetLabel(labels.map { it.replace(prec) }.toSet(), metadata) + is StmtLabel -> { + when (val stmt = this.stmt) { + is AssignStmt<*> -> + if (stmt.varDecl in prec.usedVars) { + StmtLabel(HavocStmt.of(stmt.varDecl), metadata = this.metadata) + } else { + NopLabel + } - private fun XcfaLabel.replace(prec: Prec): XcfaLabel = when (this) { - is SequenceLabel -> SequenceLabel(labels.map { it.replace(prec) }, metadata) - is NondetLabel -> NondetLabel(labels.map { it.replace(prec) }.toSet(), metadata) - is StmtLabel -> { - when (val stmt = this.stmt) { - is AssignStmt<*> -> if (stmt.varDecl in prec.usedVars) { - StmtLabel(HavocStmt.of(stmt.varDecl), metadata = this.metadata) - } else { - NopLabel - } - - is HavocStmt<*> -> if (stmt.varDecl in prec.usedVars) { - this - } else { - NopLabel - } - - else -> this + is HavocStmt<*> -> + if (stmt.varDecl in prec.usedVars) { + this + } else { + NopLabel } + + else -> this } + } - else -> this + else -> this } -} \ No newline at end of file +} 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 fa3ba5800a..6634a3bc53 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiSingleThread.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiSingleThread.kt index 9759e5fd60..dbea686f3e 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiSingleThread.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/coi/XcfaCoiSingleThread.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis.coi import hu.bme.mit.theta.analysis.LTS @@ -24,59 +23,68 @@ import hu.bme.mit.theta.xcfa.model.XcfaLocation class XcfaCoiSingleThread(xcfa: XCFA) : XcfaCoi(xcfa) { - private var observed: Set> = setOf() + private var observed: Set> = setOf() - override val lts = object : LTS { - override fun getEnabledActionsFor(state: S): Collection { - val enabled = coreLts.getEnabledActionsFor(state) - return lastPrec?.let { replaceIrrelevantActions(enabled, it) } ?: enabled - } + override val lts = + object : LTS { + override fun getEnabledActionsFor(state: S): Collection { + val enabled = coreLts.getEnabledActionsFor(state) + return lastPrec?.let { replaceIrrelevantActions(enabled, it) } ?: enabled + } - override fun

getEnabledActionsFor(state: S, explored: Collection, prec: P): Collection { - if (lastPrec != prec) reinitialize(prec) - val enabled = coreLts.getEnabledActionsFor(state, explored, prec) - return replaceIrrelevantActions(enabled, prec) - } + override fun

getEnabledActionsFor( + state: S, + explored: Collection, + prec: P, + ): Collection { + if (lastPrec != prec) reinitialize(prec) + val enabled = coreLts.getEnabledActionsFor(state, explored, prec) + return replaceIrrelevantActions(enabled, prec) + } - private fun replaceIrrelevantActions(enabled: Collection, prec: Prec): Collection = - enabled.map { action -> - if (Pair(action.source, action.target) !in observed) { - replace(action, prec) - } else { - action.transFuncVersion = null - action - } - } + private fun replaceIrrelevantActions(enabled: Collection, prec: Prec): Collection = + enabled.map { action -> + if (Pair(action.source, action.target) !in observed) { + replace(action, prec) + } else { + action.transFuncVersion = null + action + } + } } - fun reinitialize(prec: Prec) { - lastPrec = prec - directObservers.clear() - val realObservers = mutableSetOf() - xcfa.procedures.forEach { procedure -> - procedure.edges.forEach { edge -> - findDirectObservers(edge, prec) - if (isRealObserver(edge)) { - realObservers.add(edge) - } - } + fun reinitialize(prec: Prec) { + lastPrec = prec + directObservers.clear() + val realObservers = mutableSetOf() + xcfa.procedures.forEach { procedure -> + procedure.edges.forEach { edge -> + findDirectObservers(edge, prec) + if (isRealObserver(edge)) { + realObservers.add(edge) } - collectedObservedEdges(realObservers) + } } + collectedObservedEdges(realObservers) + } - override fun addToRelation(source: XcfaEdge, target: XcfaEdge, relation: MutableMap>) { - relation[target] = relation.getOrDefault(target, setOf()) + source - } + override fun addToRelation( + source: XcfaEdge, + target: XcfaEdge, + relation: MutableMap>, + ) { + relation[target] = relation.getOrDefault(target, setOf()) + source + } - private fun collectedObservedEdges(realObservers: Set) { - val toVisit = realObservers.toMutableList() - val visited = mutableSetOf() - while (toVisit.isNotEmpty()) { - val visiting = toVisit.removeFirst() - visited.add(visiting) - val toAdd = directObservers[visiting] ?: emptySet() - toVisit.addAll(toAdd.filter { it !in visited }) - } - observed = visited.map { it.source to it.target }.toSet() + private fun collectedObservedEdges(realObservers: Set) { + val toVisit = realObservers.toMutableList() + val visited = mutableSetOf() + while (toVisit.isNotEmpty()) { + val visiting = toVisit.removeFirst() + visited.add(visiting) + val toAdd = directObservers[visiting] ?: emptySet() + toVisit.addAll(toAdd.filter { it !in visited }) } -} \ No newline at end of file + observed = visited.map { it.source to it.target }.toSet() + } +} diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaExactPo.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaExactPo.kt index 8b6811ce7e..18c0ad1617 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaExactPo.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaExactPo.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 f5438976cd..766dd24318 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcCorrectnessValidator.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcCorrectnessValidator.kt index 1bdfc2bb49..81802c6611 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcCorrectnessValidator.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcCorrectnessValidator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcPreConflictFinder.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcPreConflictFinder.kt index ea7a73252c..f5f6d56204 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcPreConflictFinder.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcPreConflictFinder.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcReasonParser.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcReasonParser.kt index 9c335af7ff..5693e56231 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcReasonParser.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcReasonParser.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 50396818a3..c415ed0d63 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTypes.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTypes.kt index 1547960467..7ad7da307f 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTypes.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/oc/XcfaOcTypes.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/AtomicNodePruner.java b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/AtomicNodePruner.java index 5561064a5d..91d84bf5e6 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/AtomicNodePruner.java +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/AtomicNodePruner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis.por; import hu.bme.mit.theta.analysis.algorithm.arg.ARG; @@ -24,13 +23,15 @@ import hu.bme.mit.theta.xcfa.analysis.XcfaState; /** - * Prunes the given node from the given ARG if the action of its incoming edge is not part of an atomic block. - * Otherwise, the closest ancestor of the node is pruned for whom the above condition holds. + * Prunes the given node from the given ARG if the action of its incoming edge is not part of an + * atomic block. Otherwise, the closest ancestor of the node is pruned for whom the above condition + * holds. * * @param {@link XcfaState} * @param {@link XcfaAction} */ -public class AtomicNodePruner, A extends XcfaAction> implements NodePruner { +public class AtomicNodePruner, A extends XcfaAction> + implements NodePruner { @Override public void prune(final ARG arg, ArgNode node) { while (node.getState().getMutexes().containsKey("")) { // TODO: needs further checks? diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/ExtensionProperty.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/ExtensionProperty.kt index da5424bd55..87924af23d 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/ExtensionProperty.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/ExtensionProperty.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,24 +20,29 @@ import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty fun extension() = ExtensionProperty() + fun nullableExtension() = NullableExtensionProperty() class ExtensionProperty : ReadWriteProperty { - private val map = IdentityHashMap() - override fun getValue(thisRef: R, property: KProperty<*>) = checkNotNull(map[thisRef]) - override fun setValue(thisRef: R, property: KProperty<*>, value: T) { - map[thisRef] = value - } + private val map = IdentityHashMap() + + override fun getValue(thisRef: R, property: KProperty<*>) = checkNotNull(map[thisRef]) + + override fun setValue(thisRef: R, property: KProperty<*>, value: T) { + map[thisRef] = value + } } open class NullableExtensionProperty : ReadWriteProperty { - protected val map = IdentityHashMap() - override fun getValue(thisRef: R, property: KProperty<*>) = map[thisRef] - override fun setValue(thisRef: R, property: KProperty<*>, value: T?) { - map[thisRef] = value - } + protected val map = IdentityHashMap() + + override fun getValue(thisRef: R, property: KProperty<*>) = map[thisRef] + + override fun setValue(thisRef: R, property: KProperty<*>, value: T?) { + map[thisRef] = value + } - fun clear() = map.clear() + fun clear() = map.clear() } diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporCoiLts.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporCoiLts.kt index 4843b1118b..3f977acf69 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporCoiLts.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporCoiLts.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis.por import hu.bme.mit.theta.analysis.LTS @@ -27,14 +26,15 @@ import hu.bme.mit.theta.xcfa.model.XCFA import hu.bme.mit.theta.xcfa.model.XcfaEdge class XcfaAasporCoiLts( - xcfa: XCFA, - ignoredVarRegistry: MutableMap, MutableSet>, - coiLTS: LTS>, XcfaAction> + xcfa: XCFA, + ignoredVarRegistry: MutableMap, MutableSet>, + coiLTS: LTS>, XcfaAction>, ) : XcfaAasporLts(xcfa, ignoredVarRegistry) { - init { - simpleXcfaLts = coiLTS - } + init { + simpleXcfaLts = coiLTS + } - override fun getEdge(action: XcfaAction): XcfaEdge = super.getEdge(action.transFuncVersion ?: action) -} \ No newline at end of file + override fun getEdge(action: XcfaAction): XcfaEdge = + super.getEdge(action.transFuncVersion ?: action) +} diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporLts.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporLts.kt index d395d58d30..20050b272a 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporLts.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaAasporLts.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 5ee85c07d3..c967006131 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporCoiLts.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporCoiLts.kt index 5cc7bb8fb1..9b140912ff 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporCoiLts.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporCoiLts.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.analysis.por import hu.bme.mit.theta.analysis.LTS @@ -26,20 +25,24 @@ import hu.bme.mit.theta.xcfa.analysis.coi.transFuncVersion import hu.bme.mit.theta.xcfa.model.XCFA import hu.bme.mit.theta.xcfa.model.XcfaEdge -class XcfaSporCoiLts( - xcfa: XCFA, - coiLTS: LTS>, XcfaAction> -) : XcfaSporLts(xcfa) { +class XcfaSporCoiLts(xcfa: XCFA, coiLTS: LTS>, XcfaAction>) : + XcfaSporLts(xcfa) { - init { - simpleXcfaLts = coiLTS - } + init { + simpleXcfaLts = coiLTS + } - override fun

getEnabledActionsFor( - state: XcfaState>, exploredActions: Collection, prec: P - ): Set { - return getEnabledActionsFor(state, simpleXcfaLts.getEnabledActionsFor(state, exploredActions, prec)) - } + override fun

getEnabledActionsFor( + state: XcfaState>, + exploredActions: Collection, + prec: P, + ): Set { + return getEnabledActionsFor( + state, + simpleXcfaLts.getEnabledActionsFor(state, exploredActions, prec), + ) + } - override fun getEdge(action: XcfaAction): XcfaEdge = super.getEdge(action.transFuncVersion ?: action) -} \ No newline at end of file + override fun getEdge(action: XcfaAction): XcfaEdge = + super.getEdge(action.transFuncVersion ?: action) +} diff --git a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporLts.kt b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporLts.kt index 82ebfb0545..49bf538422 100644 --- a/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporLts.kt +++ b/subprojects/xcfa/xcfa-analysis/src/main/java/hu/bme/mit/theta/xcfa/analysis/por/XcfaSporLts.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 04a679d9e3..b70a35b617 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 cf094ab486..9e737e3f61 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 3b144ffeb6..191d12f4a7 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/build.gradle.kts b/subprojects/xcfa/xcfa-cli/build.gradle.kts index 63d27c1109..9d2aab32dd 100644 --- a/subprojects/xcfa/xcfa-cli/build.gradle.kts +++ b/subprojects/xcfa/xcfa-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 686cc42c92..7f22d796ab 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/XcfaCli.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/XcfaCli.kt index 29d44360d2..2a9fe3532c 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/XcfaCli.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/XcfaCli.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 1f928b4ab3..a0b6f37165 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 c8768cb67c..37bd0904c8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 c6bc1153fe..5b8174bded 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToHornChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToHornChecker.kt index 2e73009d5f..c0ff402891 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToHornChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToHornChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToMddChecker.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToMddChecker.kt index e21d10abf2..9beaa258e2 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToMddChecker.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/checkers/ConfigToMddChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 f71aab960e..45ceba0085 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 a74be8870b..f7df87b8c3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 8ca637dd16..84299b9a5b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 1ecf5e665a..3df731fee0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.cli.params import com.microsoft.z3.Z3Exception @@ -25,81 +24,77 @@ import hu.bme.mit.theta.solver.smtlib.solver.SmtLibSolverException import hu.bme.mit.theta.solver.validator.SolverValidationException import kotlin.system.exitProcess - enum class ExitCodes(val code: Int) { - GENERIC_ERROR(1), - OUT_OF_MEMORY(200), - TIMEOUT(201), - SERVER_ERROR(202), - PORTFOLIO_ERROR(203), - - UNSUPPORTED_ELEMENT(209), - FRONTEND_FAILED(210), - INVALID_PARAM(211), - - VERIFICATION_STUCK(220), - SOLVER_ERROR(221), + GENERIC_ERROR(1), + OUT_OF_MEMORY(200), + TIMEOUT(201), + SERVER_ERROR(202), + PORTFOLIO_ERROR(203), + UNSUPPORTED_ELEMENT(209), + FRONTEND_FAILED(210), + INVALID_PARAM(211), + VERIFICATION_STUCK(220), + SOLVER_ERROR(221), } data class ErrorCodeException(val code: Int) : Exception() private fun exitProcess(debug: Boolean, e: Throwable, code: Int): Nothing { - if (debug) { - throw ErrorCodeException(code) - } else exitProcess(code) + if (debug) { + throw ErrorCodeException(code) + } else exitProcess(code) } private fun Throwable.printCauseAndTrace(stacktrace: Boolean) { - if (stacktrace) printStackTrace() - val location = stackTrace.first { it.className.startsWith("hu.bme.mit.theta") }.toString() - System.err.println("Process failed! ($location, $this)") + if (stacktrace) printStackTrace() + val location = stackTrace.first { it.className.startsWith("hu.bme.mit.theta") }.toString() + System.err.println("Process failed! ($location, $this)") } fun exitOnError(stacktrace: Boolean, throwDontExit: Boolean, body: () -> T): T { - try { - return body() - } 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) - } catch (e: JavaSMTSolverException) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) - } catch (e: SolverValidationException) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code); - } catch (e: Z3Exception) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code); - } catch (e: ClassCastException) { - e.printCauseAndTrace(stacktrace) - if (e.message?.contains("com.microsoft.z3") == true) - exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code); - else - exitProcess(throwDontExit, e, ExitCodes.GENERIC_ERROR.code); - } catch (e: NotSolvableException) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.VERIFICATION_STUCK.code); - } catch (e: OutOfMemoryError) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.OUT_OF_MEMORY.code); - } catch (e: UnknownSolverStatusException) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code); - } catch (e: RuntimeException) { - e.printCauseAndTrace(stacktrace) - if (e.message?.contains("Solver problem") == true || e.message?.contains("Z3") == true) { - exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code); - } else { - exitProcess(throwDontExit, e, ExitCodes.SERVER_ERROR.code); - } - } catch (e: Exception) { - e.printCauseAndTrace(stacktrace) - exitProcess(throwDontExit, e, ExitCodes.GENERIC_ERROR.code); + try { + return body() + } 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) + } catch (e: JavaSMTSolverException) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) + } catch (e: SolverValidationException) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) + } catch (e: Z3Exception) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) + } catch (e: ClassCastException) { + e.printCauseAndTrace(stacktrace) + if (e.message?.contains("com.microsoft.z3") == true) + exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) + else exitProcess(throwDontExit, e, ExitCodes.GENERIC_ERROR.code) + } catch (e: NotSolvableException) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.VERIFICATION_STUCK.code) + } catch (e: OutOfMemoryError) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.OUT_OF_MEMORY.code) + } catch (e: UnknownSolverStatusException) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) + } catch (e: RuntimeException) { + e.printCauseAndTrace(stacktrace) + if (e.message?.contains("Solver problem") == true || e.message?.contains("Z3") == true) { + exitProcess(throwDontExit, e, ExitCodes.SOLVER_ERROR.code) + } else { + exitProcess(throwDontExit, e, ExitCodes.SERVER_ERROR.code) } -} \ No newline at end of file + } catch (e: Exception) { + e.printCauseAndTrace(stacktrace) + exitProcess(throwDontExit, e, ExitCodes.GENERIC_ERROR.code) + } +} 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 c2d46bd504..17cfaa21f3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/TypeAdapters.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/TypeAdapters.kt index 997935e0e0..6375695274 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/TypeAdapters.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/TypeAdapters.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.cli.params import com.google.gson.Gson @@ -23,142 +22,143 @@ import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter import hu.bme.mit.theta.xcfa.passes.LbePass -class SpecFrontendConfigTypeAdapter(val gsonSupplier: () -> Gson) : TypeAdapter>() { - - private lateinit var gson: Gson - - override fun write(writer: JsonWriter, value: FrontendConfig<*>) { - initGson() - writer.beginObject() - - writer.name("lbeLevel").value(value.lbeLevel.name) - writer.name("loopUnroll").value(value.loopUnroll) - writer.name("inputType").value(value.inputType.name) - writer.name("specConfig") - if (value.specConfig != null) { - writer.beginObject() - writer.name("type").value(value.specConfig?.javaClass?.typeName) - writer.name("value") - gson.toJson(gson.toJsonTree(value.specConfig), writer) - writer.endObject() - } else { - writer.nullValue() - } - - writer.endObject() +class SpecFrontendConfigTypeAdapter(val gsonSupplier: () -> Gson) : + TypeAdapter>() { + + private lateinit var gson: Gson + + override fun write(writer: JsonWriter, value: FrontendConfig<*>) { + initGson() + writer.beginObject() + + writer.name("lbeLevel").value(value.lbeLevel.name) + writer.name("loopUnroll").value(value.loopUnroll) + writer.name("inputType").value(value.inputType.name) + writer.name("specConfig") + if (value.specConfig != null) { + writer.beginObject() + writer.name("type").value(value.specConfig?.javaClass?.typeName) + writer.name("value") + gson.toJson(gson.toJsonTree(value.specConfig), writer) + writer.endObject() + } else { + writer.nullValue() } - override fun read(reader: JsonReader): FrontendConfig<*> { - initGson() - - // Prepare variables to hold deserialized data - val instance = FrontendConfig() - - reader.beginObject() - while (reader.hasNext()) { - when (reader.nextName()) { - "lbeLevel" -> instance.lbeLevel = LbePass.LbeLevel.valueOf(reader.nextString()) - "loopUnroll" -> instance.loopUnroll = reader.nextInt() - "inputType" -> instance.inputType = InputType.valueOf(reader.nextString()) - "specConfig" -> instance.specConfig = readSpecConfig(reader) - else -> reader.skipValue() - } - } - reader.endObject() + writer.endObject() + } - return instance - } + override fun read(reader: JsonReader): FrontendConfig<*> { + initGson() - private fun readSpecConfig(reader: JsonReader): SpecFrontendConfig? = - if (reader.peek() == JsonToken.NULL) { - null - } else { - lateinit var specConfig: SpecFrontendConfig - reader.beginObject() - lateinit var clazz: Class<*> - while (reader.hasNext()) { - when (reader.nextName()) { - "type" -> clazz = Class.forName(reader.nextString()) - "value" -> specConfig = gson.fromJson(reader, clazz) - else -> reader.skipValue() - } - } - reader.endObject() - specConfig - } + // Prepare variables to hold deserialized data + val instance = FrontendConfig() - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() + reader.beginObject() + while (reader.hasNext()) { + when (reader.nextName()) { + "lbeLevel" -> instance.lbeLevel = LbePass.LbeLevel.valueOf(reader.nextString()) + "loopUnroll" -> instance.loopUnroll = reader.nextInt() + "inputType" -> instance.inputType = InputType.valueOf(reader.nextString()) + "specConfig" -> instance.specConfig = readSpecConfig(reader) + else -> reader.skipValue() + } + } + reader.endObject() + + return instance + } + + private fun readSpecConfig(reader: JsonReader): SpecFrontendConfig? = + if (reader.peek() == JsonToken.NULL) { + null + } else { + lateinit var specConfig: SpecFrontendConfig + reader.beginObject() + lateinit var clazz: Class<*> + while (reader.hasNext()) { + when (reader.nextName()) { + "type" -> clazz = Class.forName(reader.nextString()) + "value" -> specConfig = gson.fromJson(reader, clazz) + else -> reader.skipValue() + } + } + reader.endObject() + specConfig } + + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } } class SpecBackendConfigTypeAdapter(val gsonSupplier: () -> Gson) : TypeAdapter>() { - private lateinit var gson: Gson - - override fun write(writer: JsonWriter, value: BackendConfig<*>) { - initGson() - writer.beginObject() - - writer.name("backend").value(value.backend.name) - writer.name("solverHome").value(value.solverHome) - writer.name("timeoutMs").value(value.timeoutMs) - writer.name("inProcess").value(value.inProcess) - writer.name("specConfig") - if (value.specConfig != null) { - writer.beginObject() - writer.name("type").value(value.specConfig?.javaClass?.typeName) - writer.name("value") - gson.toJson(gson.toJsonTree(value.specConfig), writer) - writer.endObject() - } else { - writer.nullValue() - } - - writer.endObject() + private lateinit var gson: Gson + + override fun write(writer: JsonWriter, value: BackendConfig<*>) { + initGson() + writer.beginObject() + + writer.name("backend").value(value.backend.name) + writer.name("solverHome").value(value.solverHome) + writer.name("timeoutMs").value(value.timeoutMs) + writer.name("inProcess").value(value.inProcess) + writer.name("specConfig") + if (value.specConfig != null) { + writer.beginObject() + writer.name("type").value(value.specConfig?.javaClass?.typeName) + writer.name("value") + gson.toJson(gson.toJsonTree(value.specConfig), writer) + writer.endObject() + } else { + writer.nullValue() } - override fun read(reader: JsonReader): BackendConfig<*> { - initGson() - - // Prepare variables to hold deserialized data - val instance = BackendConfig() - - reader.beginObject() - while (reader.hasNext()) { - when (reader.nextName()) { - "backend" -> instance.backend = Backend.valueOf(reader.nextString()) - "solverHome" -> instance.solverHome = reader.nextString() - "timeoutMs" -> instance.timeoutMs = reader.nextLong() - "inProcess" -> instance.inProcess = reader.nextBoolean() - "specConfig" -> instance.specConfig = readSpecConfig(reader) - else -> reader.skipValue() - } - } - reader.endObject() - - return instance + writer.endObject() + } + + override fun read(reader: JsonReader): BackendConfig<*> { + initGson() + + // Prepare variables to hold deserialized data + val instance = BackendConfig() + + reader.beginObject() + while (reader.hasNext()) { + when (reader.nextName()) { + "backend" -> instance.backend = Backend.valueOf(reader.nextString()) + "solverHome" -> instance.solverHome = reader.nextString() + "timeoutMs" -> instance.timeoutMs = reader.nextLong() + "inProcess" -> instance.inProcess = reader.nextBoolean() + "specConfig" -> instance.specConfig = readSpecConfig(reader) + else -> reader.skipValue() + } } - - private fun readSpecConfig(reader: JsonReader): SpecBackendConfig? = - if (reader.peek() == JsonToken.NULL) { - null - } else { - lateinit var specConfig: SpecBackendConfig - reader.beginObject() - lateinit var clazz: Class<*> - while (reader.hasNext()) { - when (reader.nextName()) { - "type" -> clazz = Class.forName(reader.nextString()) - "value" -> specConfig = gson.fromJson(reader, clazz) - else -> reader.skipValue() - } - } - reader.endObject() - specConfig + reader.endObject() + + return instance + } + + private fun readSpecConfig(reader: JsonReader): SpecBackendConfig? = + if (reader.peek() == JsonToken.NULL) { + null + } else { + lateinit var specConfig: SpecBackendConfig + reader.beginObject() + lateinit var clazz: Class<*> + while (reader.hasNext()) { + when (reader.nextName()) { + "type" -> clazz = Class.forName(reader.nextString()) + "value" -> specConfig = gson.fromJson(reader, clazz) + else -> reader.skipValue() } - - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() + } + reader.endObject() + specConfig } -} \ No newline at end of file + + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/Validators.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/Validators.kt index d46c5f7620..48a69c9435 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/Validators.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/params/Validators.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,13 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.cli.params import com.beust.jcommander.ParameterException fun rule(name: String, test: () -> Boolean) { - if (test()) { - throw ParameterException("Validation failed for rule $name") - } + if (test()) { + throw ParameterException("Validation failed for rule $name") + } } 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 1675afa4a6..c7e67f4d49 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded24.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded24.kt index fdc4ae8995..c42adccf59 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded24.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded24.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded25.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded25.kt index 95f9cced5c..0a827468d9 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded25.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/bounded25.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 2e54ec3fe8..cddce09754 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 7547273b57..dee3ff2e48 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex25.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex25.kt index 738b0da018..eb2b7bd0d5 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex25.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/complex25.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn25.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn25.kt index 749a43d6da..728ce4541e 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn25.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/portfolio/horn25.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 b8b33c9c21..85103b2377 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/CachingFileSerializer.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/CachingFileSerializer.kt index 9c3414c90f..b8fc31e6fb 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/CachingFileSerializer.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/CachingFileSerializer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,30 +13,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.cli.utils import java.io.File object CachingFileSerializer { - private val cache: MutableMap, File> = LinkedHashMap() + private val cache: MutableMap, File> = LinkedHashMap() - /** - * key: unique id for serialization groups - * obj: object to serialize - * func: generator function if a cache miss occurs - */ - fun serialize(key: String, obj: Any, func: (Any) -> String): File = - if (cache.containsKey(Pair(key, obj))) { - cache[Pair(key, obj)]!! - } else { - val str = func(obj) - val pattern = key.split(".") - val file = File.createTempFile(pattern.subList(0, pattern.size - 1).joinToString("."), "." + pattern.last()) - file.deleteOnExit() - file.writeText(str) - cache[Pair(key, obj)] = file - file - } -} \ No newline at end of file + /** + * key: unique id for serialization groups obj: object to serialize func: generator function if a + * cache miss occurs + */ + fun serialize(key: String, obj: Any, func: (Any) -> String): File = + if (cache.containsKey(Pair(key, obj))) { + cache[Pair(key, obj)]!! + } else { + val str = func(obj) + val pattern = key.split(".") + val file = + File.createTempFile( + pattern.subList(0, pattern.size - 1).joinToString("."), + "." + pattern.last(), + ) + file.deleteOnExit() + file.writeText(str) + cache[Pair(key, obj)] = file + file + } +} diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GraphmlWitnessWriter.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GraphmlWitnessWriter.kt index cf7a650b0b..7a3b77918a 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GraphmlWitnessWriter.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/GraphmlWitnessWriter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 d38d2c3b64..fc33389e6f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 29d77fda52..fbcae3f4c7 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/SolverRegistration.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/SolverRegistration.kt index ed9ea1f99f..5d93ce8636 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/SolverRegistration.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/SolverRegistration.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.cli.utils import hu.bme.mit.theta.common.OsHelper @@ -26,25 +25,26 @@ import hu.bme.mit.theta.solver.validator.SolverValidatorWrapperFactory import hu.bme.mit.theta.solver.z3legacy.Z3SolverManager import java.nio.file.Path -fun getSolver(name: String, validate: Boolean): SolverFactory = if (validate) { +fun getSolver(name: String, validate: Boolean): SolverFactory = + if (validate) { SolverValidatorWrapperFactory.create(name) -} else { + } else { SolverManager.resolveSolverFactory(name) -} + } fun registerAllSolverManagers(home: String, logger: Logger) { - SolverManager.closeAll() - // register solver managers - SolverManager.registerSolverManager(Z3SolverManager.create()) - logger.write(Logger.Level.INFO, "Registered Legacy-Z3 SolverManager\n") - SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3.Z3SolverManager.create()) - logger.write(Logger.Level.INFO, "Registered Z3 SolverManager\n") - SolverManager.registerSolverManager(JavaSMTSolverManager.create()) - logger.write(Logger.Level.INFO, "Registered JavaSMT SolverManager\n") - if (OsHelper.getOs() == OsHelper.OperatingSystem.LINUX) { - val homePath = Path.of(home) - val smtLibSolverManager: SmtLibSolverManager = SmtLibSolverManager.create(homePath, logger) - SolverManager.registerSolverManager(smtLibSolverManager) - logger.write(Logger.Level.INFO, "Registered SMT-LIB SolverManager\n") - } -} \ No newline at end of file + SolverManager.closeAll() + // register solver managers + SolverManager.registerSolverManager(Z3SolverManager.create()) + logger.write(Logger.Level.INFO, "Registered Legacy-Z3 SolverManager\n") + SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3.Z3SolverManager.create()) + logger.write(Logger.Level.INFO, "Registered Z3 SolverManager\n") + SolverManager.registerSolverManager(JavaSMTSolverManager.create()) + logger.write(Logger.Level.INFO, "Registered JavaSMT SolverManager\n") + if (OsHelper.getOs() == OsHelper.OperatingSystem.LINUX) { + val homePath = Path.of(home) + val smtLibSolverManager: SmtLibSolverManager = SmtLibSolverManager.create(homePath, logger) + SolverManager.registerSolverManager(smtLibSolverManager) + logger.write(Logger.Level.INFO, "Registered SMT-LIB SolverManager\n") + } +} diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/WitnessWriter.java b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/WitnessWriter.java index 29b7b01e34..65da4ac4d2 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/WitnessWriter.java +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/WitnessWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.cli.utils; import hu.bme.mit.theta.common.visualization.Edge; import hu.bme.mit.theta.common.visualization.Graph; import hu.bme.mit.theta.common.visualization.Node; import hu.bme.mit.theta.common.visualization.writer.AbstractGraphWriter; - import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -43,24 +41,25 @@ public final class WitnessWriter extends AbstractGraphWriter { private final String programHash; private final boolean isViolationWitness; - private final String toolName = "theta"; // TODO maybe we should add the version number to this field as well + private final String toolName = + "theta"; // TODO maybe we should add the version number to this field as well private final String sourceCodeLang = "C"; private final String architecture; // TODO add 64bit option later private final String specification; private final String programFile; - public static WitnessWriter createViolationWitnessWriter(String programFile, - String specification, boolean is64bit) { + public static WitnessWriter createViolationWitnessWriter( + String programFile, String specification, boolean is64bit) { return new WitnessWriter(programFile, specification, true, is64bit); } - public static WitnessWriter createCorrectnessWitnessWriter(String programFile, - String specification, boolean is64bit) { + public static WitnessWriter createCorrectnessWitnessWriter( + String programFile, String specification, boolean is64bit) { return new WitnessWriter(programFile, specification, false, is64bit); } - private WitnessWriter(String programFile, String specification, boolean isViolationWitness, - boolean is64bit) { + private WitnessWriter( + String programFile, String specification, boolean isViolationWitness, boolean is64bit) { programHash = createTaskHash(programFile); this.isViolationWitness = isViolationWitness; this.specification = specification; @@ -92,11 +91,13 @@ public String writeString(Graph graph) { return sb.toString(); } - // TODO should this be a bit more flexible or should we add keys we don't use for now, but we might use in the future? + // TODO should this be a bit more flexible or should we add keys we don't use for now, but we + // might use in the future? private void printKeys(StringBuilder sb) { sb.append("").append(System.lineSeparator()); sb.append( - "") + "") .append(System.lineSeparator()); appendKeyLine(sb, "sourcecodelang", "string", "graph", "sourcecodelang"); @@ -122,7 +123,6 @@ private void printKeys(StringBuilder sb) { } else { appendKeyWithDefaultValue(sb, "invariant", "string", "node", "invariant", "true"); } - } private void printGraphKeyValues(StringBuilder sb) { @@ -139,20 +139,26 @@ private void printGraphKeyValues(StringBuilder sb) { appendDataNode(sb, "architecture", architecture); TimeZone tz = TimeZone.getTimeZone("UTC"); - DateFormat df = new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss'Z'"); // Quoted "Z" to indicate UTC, no timezone offset + DateFormat df = + new SimpleDateFormat( + "yyyy-MM-dd'T'HH:mm:ss'Z'"); // Quoted "Z" to indicate UTC, no timezone + // offset df.setTimeZone(tz); String ISOdate = df.format(new Date()); appendDataNode(sb, "creationtime", ISOdate); } private void appendDataNode(StringBuilder sb, String key, String value) { - sb.append("").append(value).append("") + sb.append("") + .append(value) + .append("") .append(System.lineSeparator()); } - private void appendKeyLine(StringBuilder sb, String attrName, String attrType, - String forElement, String id) { + private void appendKeyLine( + StringBuilder sb, String attrName, String attrType, String forElement, String id) { sb.append("") + sb.append("") .append(System.lineSeparator()); } else { - sb.append("") + sb.append("") .append(System.lineSeparator()); sb.append(node.getAttributes().getLabel()).append(System.lineSeparator()); // TODO tabs? sb.append("").append(System.lineSeparator()); @@ -200,7 +215,9 @@ private void printNode(final Node node, final StringBuilder sb) { private void printEdges(final Node node, final StringBuilder sb) { for (final Edge edge : node.getOutEdges()) { sb.append("") + sb.append("\" target=\"") + .append(edge.getTarget().getId()) + .append("\">") .append(System.lineSeparator()); sb.append(edge.getAttributes().getLabel()).append(System.lineSeparator()); // TODO tabs? sb.append("").append(System.lineSeparator()); @@ -215,9 +232,8 @@ public static String createTaskHash(String programFile) { e.printStackTrace(); } try (InputStream is = Files.newInputStream(Paths.get(programFile)); - DigestInputStream dis = new DigestInputStream(is, md)) { - while (dis.read() != -1) { - } + DigestInputStream dis = new DigestInputStream(is, md)) { + while (dis.read() != -1) {} } catch (IOException e) { e.printStackTrace(); } diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaDistToErrComparator.java b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaDistToErrComparator.java index a7d2f3adc7..b730eca5bd 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaDistToErrComparator.java +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/XcfaDistToErrComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.xcfa.cli.utils; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -26,20 +29,13 @@ import hu.bme.mit.theta.xcfa.model.XcfaEdge; import hu.bme.mit.theta.xcfa.model.XcfaLocation; import hu.bme.mit.theta.xcfa.model.XcfaProcedure; -import kotlin.Pair; - import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import kotlin.Pair; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * A comparator for ArgNodes that is based on the distance from the error - * location. - */ +/** A comparator for ArgNodes that is based on the distance from the error location. */ public class XcfaDistToErrComparator implements ArgNodeComparator { private Map distancesToError; private final int errorWeight; @@ -55,7 +51,7 @@ public XcfaDistToErrComparator(final XCFA xcfa, final int errorWeight, final int this.xcfa = xcfa; Pair>> initProc = checkNotNull(xcfa.getInitProcedures().get(0)); Optional errorLocOpt = initProc.component1().getErrorLoc(); -// checkState(errorLocOpt.isPresent()); + // checkState(errorLocOpt.isPresent()); this.errLoc = errorLocOpt.orElse(null); this.errorWeight = errorWeight; this.depthWeight = depthWeight; @@ -63,8 +59,9 @@ public XcfaDistToErrComparator(final XCFA xcfa, final int errorWeight, final int } @Override - public int compare(final ArgNode n1, - final ArgNode n2) { + public int compare( + final ArgNode n1, + final ArgNode n2) { final int dist1 = getWeightedDistance(n1); final int dist2 = getWeightedDistance(n2); @@ -73,12 +70,16 @@ public int compare(final ArgNode n1, private int getWeightedDistance(final ArgNode node) { final var localState = node.getState(); - checkArgument(localState instanceof XcfaState && ((XcfaState) localState).getProcesses().size() <= 1, "XcfaState expected with a single process."); + checkArgument( + localState instanceof XcfaState + && ((XcfaState) localState).getProcesses().size() <= 1, + "XcfaState expected with a single process."); if (((XcfaState) localState).getProcesses().size() == 0) { return Integer.MAX_VALUE; } final XcfaState state = (XcfaState) localState; - final int distanceToError = getDistanceToError(state.getProcesses().get(0).component1().peek()); + final int distanceToError = + getDistanceToError(state.getProcesses().get(0).component1().peek()); if (distanceToError == Integer.MAX_VALUE) { return distanceToError; } @@ -94,7 +95,8 @@ private int getDistanceToError(final XcfaLocation loc) { return distancesToError.getOrDefault(loc, Integer.MAX_VALUE); } - static Map calculateDistancesToError(final XCFA cfa, final XcfaLocation errLoc) { + static Map calculateDistancesToError( + final XCFA cfa, final XcfaLocation errLoc) { List queue = new LinkedList<>(); final Map distancesToError = Containers.createMap(); queue.add(errLoc); 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 a14da06c84..91d862cd1a 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/YmlWitnessWriter.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/YmlWitnessWriter.kt index e0d79da9eb..76bf91be37 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/YmlWitnessWriter.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/utils/YmlWitnessWriter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/CommonWitness.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/CommonWitness.kt index e5f6748d54..7e3561773f 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/CommonWitness.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/CommonWitness.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/GraphmlWitness.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/GraphmlWitness.kt index 5d774f1d36..4c4b9a70f4 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/GraphmlWitness.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/GraphmlWitness.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 eb224355de..f461cd0f47 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/XcfaTraceConcretizer.java b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/XcfaTraceConcretizer.java index 6bcc2f9eff..cfe463f51e 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/XcfaTraceConcretizer.java +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/XcfaTraceConcretizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/YamlWitness.kt b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/YamlWitness.kt index e99e41771b..7b1a8d3968 100644 --- a/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/YamlWitness.kt +++ b/subprojects/xcfa/xcfa-cli/src/main/java/hu/bme/mit/theta/xcfa/cli/witnesses/YamlWitness.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 75d179405f..3bdf8794ad 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 a21bf274a3..13a5110c99 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliProofTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliProofTest.kt index 27c51fa5cf..be42971eed 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliProofTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/XcfaCliProofTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 1bd6dcf752..cec5083ba6 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 89c11bb249..354050fea6 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 c6b7f12a21..f4d5f4f144 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/YamlParseTest.kt b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/YamlParseTest.kt index 43cc33b88a..9bdf311be9 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/YamlParseTest.kt +++ b/subprojects/xcfa/xcfa-cli/src/test/java/hu/bme/mit/theta/xcfa/cli/YamlParseTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/async.xcfa.kts b/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/async.xcfa.kts index bb057e8e06..debc5213bd 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/async.xcfa.kts +++ b/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/async.xcfa.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,36 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import hu.bme.mit.theta.core.type.inttype.IntExprs.Int import hu.bme.mit.theta.xcfa.model.ParamDirection import hu.bme.mit.theta.xcfa.model.procedure import hu.bme.mit.theta.xcfa.model.xcfa xcfa("example") { - val proc1 = procedure("proc1") { - val a = "a" type Int() direction ParamDirection.IN - val b = "b" type Int() direction ParamDirection.OUT + val proc1 = + procedure("proc1") { + val a = "a" type Int() direction ParamDirection.IN + val b = "b" type Int() direction ParamDirection.OUT - (init to final) { - b assign a.ref - } + (init to final) { b assign a.ref } } - val main = procedure("main") { - val tmp = "tmp" type Int() - val thr1 = "thr1" type Int() - (init to "L1") { - thr1.start(proc1, "1", tmp.ref) - } - ("L1" to final) { - thr1.join() - assume("(= tmp 1)") - } - ("L1" to err) { - thr1.join() - assume("(/= tmp 1)") - } + val main = + procedure("main") { + val tmp = "tmp" type Int() + val thr1 = "thr1" type Int() + (init to "L1") { thr1.start(proc1, "1", tmp.ref) } + ("L1" to final) { + thr1.join() + assume("(= tmp 1)") + } + ("L1" to err) { + thr1.join() + assume("(/= tmp 1)") + } } - main.start() -} \ No newline at end of file + main.start() +} diff --git a/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/sync.xcfa.kts b/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/sync.xcfa.kts index 0b351a520c..a2eb9e6ffb 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/sync.xcfa.kts +++ b/subprojects/xcfa/xcfa-cli/src/test/resources/dsl/sync.xcfa.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,33 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import hu.bme.mit.theta.core.type.inttype.IntExprs.Int import hu.bme.mit.theta.xcfa.model.ParamDirection import hu.bme.mit.theta.xcfa.model.procedure import hu.bme.mit.theta.xcfa.model.xcfa xcfa("example") { - val proc1 = procedure("proc1") { - val a = "a" type Int() direction ParamDirection.IN - val b = "b" type Int() direction ParamDirection.OUT + val proc1 = + procedure("proc1") { + val a = "a" type Int() direction ParamDirection.IN + val b = "b" type Int() direction ParamDirection.OUT - (init to final) { - b assign a.ref - } + (init to final) { b assign a.ref } } - val main = procedure("main") { - val tmp = "tmp" type Int() - (init to "L1") { - proc1("1", tmp.ref) - } - ("L1" to final) { - assume("(= tmp 1)") - } - ("L1" to err) { - assume("(/= tmp 1)") - } + val main = + procedure("main") { + val tmp = "tmp" type Int() + (init to "L1") { proc1("1", tmp.ref) } + ("L1" to final) { assume("(= tmp 1)") } + ("L1" to err) { assume("(/= tmp 1)") } } - main.start() -} \ No newline at end of file + main.start() +} diff --git a/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts b/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts index 5014004377..97998a735c 100644 --- a/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts +++ b/subprojects/xcfa/xcfa-cli/src/test/resources/simple.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/build.gradle.kts b/subprojects/xcfa/xcfa/build.gradle.kts index 49c1ff536f..d3c22d587a 100644 --- a/subprojects/xcfa/xcfa/build.gradle.kts +++ b/subprojects/xcfa/xcfa/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 ab6378d3f6..2008a20f79 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaScope.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaScope.kt index 772c9bf41a..eb6239be7e 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaScope.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/XcfaScope.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa import hu.bme.mit.theta.common.dsl.MutableScope @@ -23,31 +22,28 @@ import hu.bme.mit.theta.common.dsl.SymbolTable import java.util.* class XcfaScope( - private val symbolTable: SymbolTable = SymbolTable(), - private val enclosingScope: Scope? = null, + private val symbolTable: SymbolTable = SymbolTable(), + private val enclosingScope: Scope? = null, ) : MutableScope { - override fun enclosingScope(): Optional { - return Optional.ofNullable(enclosingScope) - } + override fun enclosingScope(): Optional { + return Optional.ofNullable(enclosingScope) + } - override fun resolve(name: String?): Optional { - val resolved = symbolTable[name] - return if (resolved.isEmpty) - enclosingScope?.resolve(name) ?: Optional.empty() - else - resolved - } + override fun resolve(name: String?): Optional { + val resolved = symbolTable[name] + return if (resolved.isEmpty) enclosingScope?.resolve(name) ?: Optional.empty() else resolved + } - override fun add(symbol: Symbol) { - symbolTable.add(symbol) - } + override fun add(symbol: Symbol) { + symbolTable.add(symbol) + } - override fun addAll(symbols: Iterable) { - symbolTable.addAll(symbols) - } + override fun addAll(symbols: Iterable) { + symbolTable.addAll(symbols) + } - override fun toString(): String { - return "Scope{\nenclosingScope: ${enclosingScope}\nsymbolTable: $symbolTable }" - } -} \ No newline at end of file + override fun toString(): String { + return "Scope{\nenclosingScope: ${enclosingScope}\nsymbolTable: $symbolTable }" + } +} 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 c22f3ce765..2582fb4a20 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/FrontendMetadataAdapter.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/FrontendMetadataAdapter.kt index 79ef9be079..67f5a75f03 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/FrontendMetadataAdapter.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/FrontendMetadataAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.gson import com.google.gson.Gson @@ -25,106 +24,105 @@ import hu.bme.mit.theta.frontend.FrontendMetadata class FrontendMetadataAdapter(val gsonSupplier: () -> Gson) : TypeAdapter() { - private lateinit var gson: Gson - override fun write(writer: JsonWriter, value: FrontendMetadata) { - initGson() - writer.beginArray() - - for ((owner, tup) in value.lookupKeyValue.entries) { - writer.beginObject() - writer.name("owner").value(owner) - writer.name("values").beginArray() - for ((key, _val) in tup.entries) { - writer.beginObject() - if (_val is String) { - writer.name(key).value(_val) - } - if (_val is Boolean) { - writer.name(key).value(_val) - } - writer.endObject() - } - writer.endArray() - writer.endObject() - } + private lateinit var gson: Gson - writer.endArray() - } + override fun write(writer: JsonWriter, value: FrontendMetadata) { + initGson() + writer.beginArray() - override fun read(reader: JsonReader): FrontendMetadata { - initGson() + for ((owner, tup) in value.lookupKeyValue.entries) { + writer.beginObject() + writer.name("owner").value(owner) + writer.name("values").beginArray() + for ((key, _val) in tup.entries) { + writer.beginObject() + if (_val is String) { + writer.name(key).value(_val) + } + if (_val is Boolean) { + writer.name(key).value(_val) + } + writer.endObject() + } + writer.endArray() + writer.endObject() + } - val lookupKeyValue = mutableMapOf>() + writer.endArray() + } - reader.beginArray() - while (reader.hasNext()) { - reader.beginObject() + override fun read(reader: JsonReader): FrontendMetadata { + initGson() - var owner: Int? = null - var values: Map? = null + val lookupKeyValue = mutableMapOf>() - while (reader.hasNext()) { - when (reader.nextName()) { - "owner" -> { - owner = reader.nextInt() - } + reader.beginArray() + while (reader.hasNext()) { + reader.beginObject() - "values" -> { - values = readValuesArray(reader) - } + var owner: Int? = null + var values: Map? = null - else -> { - reader.skipValue() - } - } - } + while (reader.hasNext()) { + when (reader.nextName()) { + "owner" -> { + owner = reader.nextInt() + } - reader.endObject() + "values" -> { + values = readValuesArray(reader) + } - if (owner != null && values != null) { - lookupKeyValue[owner] = values - } + else -> { + reader.skipValue() + } } - reader.endArray() - - return FrontendMetadata(lookupKeyValue) - } + } - private fun readValuesArray(reader: JsonReader): Map { - val values = mutableMapOf() + reader.endObject() - reader.beginArray() - while (reader.peek() != JsonToken.END_ARRAY) { - reader.beginObject() - if (reader.hasNext()) { - val key = reader.nextName() - val value = readValue(reader) - if (value != null) { - values[key] = value - } - } - - reader.endObject() - - } - reader.endArray() - - return values + if (owner != null && values != null) { + lookupKeyValue[owner] = values + } } - - private fun readValue(reader: JsonReader): Any? { - return when { - reader.peek() == JsonToken.STRING -> reader.nextString() - reader.peek() == JsonToken.BOOLEAN -> reader.nextBoolean() - else -> { - reader.skipValue() - null - } + reader.endArray() + + return FrontendMetadata(lookupKeyValue) + } + + private fun readValuesArray(reader: JsonReader): Map { + val values = mutableMapOf() + + reader.beginArray() + while (reader.peek() != JsonToken.END_ARRAY) { + reader.beginObject() + if (reader.hasNext()) { + val key = reader.nextName() + val value = readValue(reader) + if (value != null) { + values[key] = value } - } + } - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() + reader.endObject() + } + reader.endArray() + + return values + } + + private fun readValue(reader: JsonReader): Any? { + return when { + reader.peek() == JsonToken.STRING -> reader.nextString() + reader.peek() == JsonToken.BOOLEAN -> reader.nextBoolean() + else -> { + reader.skipValue() + null + } } + } -} \ No newline at end of file + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/MetaDataAdapter.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/MetaDataAdapter.kt index 3b7e6e00d9..59bc3291e3 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/MetaDataAdapter.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/MetaDataAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.gson import com.google.gson.GsonBuilder @@ -24,24 +23,23 @@ import hu.bme.mit.theta.xcfa.model.MetaData class MetaDataAdapter : TypeAdapter() { - private val gson = GsonBuilder().create() - - override fun write(writer: JsonWriter, value: MetaData) { - writer.beginObject() - writer.name("type").value(value.javaClass.name) - writer.name("content") - gson.toJson(gson.toJsonTree(value), writer) - writer.endObject() - } + private val gson = GsonBuilder().create() - override fun read(reader: JsonReader): MetaData { - reader.beginObject() - check(reader.nextName() == "type") - val typeName = reader.nextString() - check(reader.nextName() == "content") - val content: MetaData = gson.fromJson(reader, Class.forName(typeName)) - reader.endObject() - return content - } + override fun write(writer: JsonWriter, value: MetaData) { + writer.beginObject() + writer.name("type").value(value.javaClass.name) + writer.name("content") + gson.toJson(gson.toJsonTree(value), writer) + writer.endObject() + } -} \ No newline at end of file + override fun read(reader: JsonReader): MetaData { + reader.beginObject() + check(reader.nextName() == "type") + val typeName = reader.nextString() + check(reader.nextName() == "content") + val content: MetaData = gson.fromJson(reader, Class.forName(typeName)) + reader.endObject() + return content + } +} diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/ParseContextAdapter.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/ParseContextAdapter.kt index acb6150152..54de61cc97 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/ParseContextAdapter.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/ParseContextAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.gson import com.google.gson.Gson @@ -29,86 +28,93 @@ import hu.bme.mit.theta.frontend.transformation.grammar.preprocess.ArithmeticTra class ParseContextAdapter(val gsonSupplier: () -> Gson) : TypeAdapter() { - private lateinit var gson: Gson - override fun write(writer: JsonWriter, value: ParseContext) { - initGson() - writer.beginObject() + private lateinit var gson: Gson + + override fun write(writer: JsonWriter, value: ParseContext) { + initGson() + writer.beginObject() - writer.name("arithmeticTraits") - writer.beginArray() - for (arithmeticTrait in value.arithmeticTraits) { - writer.value(arithmeticTrait.name) + writer.name("arithmeticTraits") + writer.beginArray() + for (arithmeticTrait in value.arithmeticTraits) { + writer.value(arithmeticTrait.name) + } + writer.endArray() + writer.name("architecture").value(value.architecture.name) + writer.name("arithmetic").value(value.arithmetic.name) + writer.name("multiThreading").value(value.multiThreading) + + writer.name("cStmtCounter") + gson.toJson(gson.toJsonTree(value.cStmtCounter), writer) + + writer.name("metadata") + gson.toJson(gson.toJsonTree(value.metadata), writer) + + writer.endObject() + } + + override fun read(reader: JsonReader): ParseContext { + initGson() + + var metadata: FrontendMetadata? = null + var cStmtCounter: CStmtCounter? = null + var arithmeticTraits: MutableSet = mutableSetOf() + var architecture: ArchitectureConfig.ArchitectureType? = null + var multiThreading: Boolean? = null + var arithmetic: ArchitectureConfig.ArithmeticType? = null + + reader.beginObject() + while (reader.hasNext()) { + when (reader.nextName()) { + "metadata" -> { + metadata = gson.fromJson(reader, FrontendMetadata::class.java) } - writer.endArray() - writer.name("architecture").value(value.architecture.name) - writer.name("arithmetic").value(value.arithmetic.name) - writer.name("multiThreading").value(value.multiThreading) - writer.name("cStmtCounter") - gson.toJson(gson.toJsonTree(value.cStmtCounter), writer) + "cStmtCounter" -> { + cStmtCounter = gson.fromJson(reader, CStmtCounter::class.java) + } - writer.name("metadata") - gson.toJson(gson.toJsonTree(value.metadata), writer) + "bitwiseOption" -> { + reader.beginArray() + while (reader.peek() != JsonToken.END_ARRAY) { + val optionName = reader.nextString() + arithmeticTraits.add(ArithmeticTrait.valueOf(optionName)) + } + reader.endArray() + } - writer.endObject() - } + "architecture" -> { + val architectureName = reader.nextString() + architecture = ArchitectureConfig.ArchitectureType.valueOf(architectureName) + } - override fun read(reader: JsonReader): ParseContext { - initGson() - - var metadata: FrontendMetadata? = null - var cStmtCounter: CStmtCounter? = null - var arithmeticTraits: MutableSet = mutableSetOf() - var architecture: ArchitectureConfig.ArchitectureType? = null - var multiThreading: Boolean? = null - var arithmetic: ArchitectureConfig.ArithmeticType? = null - - reader.beginObject() - while (reader.hasNext()) { - when (reader.nextName()) { - "metadata" -> { - metadata = gson.fromJson(reader, FrontendMetadata::class.java) - } - - "cStmtCounter" -> { - cStmtCounter = gson.fromJson(reader, CStmtCounter::class.java) - } - - "bitwiseOption" -> { - reader.beginArray() - while (reader.peek() != JsonToken.END_ARRAY) { - val optionName = reader.nextString() - arithmeticTraits.add(ArithmeticTrait.valueOf(optionName)) - } - reader.endArray() - } - - "architecture" -> { - val architectureName = reader.nextString() - architecture = ArchitectureConfig.ArchitectureType.valueOf(architectureName) - } - - "multiThreading" -> { - multiThreading = reader.nextBoolean() - } - - "arithmetic" -> { - val arithmeticName = reader.nextString() - arithmetic = ArchitectureConfig.ArithmeticType.valueOf(arithmeticName) - } - - else -> { - reader.skipValue() - } - } + "multiThreading" -> { + multiThreading = reader.nextBoolean() } - reader.endObject() - return ParseContext(metadata, cStmtCounter, arithmeticTraits, architecture, multiThreading, arithmetic) - } + "arithmetic" -> { + val arithmeticName = reader.nextString() + arithmetic = ArchitectureConfig.ArithmeticType.valueOf(arithmeticName) + } - private fun initGson() { - if (!this::gson.isInitialized) gson = gsonSupplier() + else -> { + reader.skipValue() + } + } } - -} \ No newline at end of file + reader.endObject() + + return ParseContext( + metadata, + cStmtCounter, + arithmeticTraits, + architecture, + multiThreading, + arithmetic, + ) + } + + private fun initGson() { + if (!this::gson.isInitialized) gson = gsonSupplier() + } +} 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 8c0d48b54b..176257c133 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 a9ef886081..c9f91847b0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLocationAdapter.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLocationAdapter.kt index 0358151fce..b6227b6dbb 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLocationAdapter.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/gson/XcfaLocationAdapter.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Builders.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Builders.kt index 4cce1aa289..9ce19925a1 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Builders.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/Builders.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 90e05c8a19..c05e3ee07d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/MetaData.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/MetaData.kt index 0b097d5027..ff755872de 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/MetaData.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/MetaData.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/PtrSize.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/PtrSize.kt index 54f24c12cb..5b605dcc3b 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/PtrSize.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/PtrSize.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 695b17e69b..5aa6058b66 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XCFA.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XCFA.kt index 03126156ed..b35b1f8f9c 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XCFA.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XCFA.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaFurtherOptimizer.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaFurtherOptimizer.kt index 77652f6a59..063788b696 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaFurtherOptimizer.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaFurtherOptimizer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 4e6a2251e0..8f6d29cb47 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 83fd73602b..b3ea969c06 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 991f5bd343..ad24392e74 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 0952ecb986..2b0d2c3e70 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CallGraphPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CallGraphPass.kt index 0cf31ccb50..a31f8552a6 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CallGraphPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/CallGraphPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.passes import hu.bme.mit.theta.xcfa.getFlatLabels @@ -22,23 +21,28 @@ import hu.bme.mit.theta.xcfa.model.StartLabel import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder /** - * Mark procedure builders with reachability info. - * Marks the called ProcedureBuilders `reachable-from-`. + * Mark procedure builders with reachability info. Marks the called ProcedureBuilders + * `reachable-from-`. */ class CallGraphPass : ProcedurePass { - override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { - val calledProcedures = LinkedHashSet() - builder.getEdges().map { it.getFlatLabels().filter { it is InvokeLabel || it is StartLabel } }.flatten() - .forEach { - when (it) { - is InvokeLabel -> calledProcedures.add(it.name) - is StartLabel -> calledProcedures.add(it.name) - else -> error("Will never be here (due to filter above)") - } - } - builder.parent.getProcedures().filter { calledProcedures.contains(it.name) } - .forEach { it.metaData["reachable-from-${builder.name}"] = Unit } - return builder - } -} \ No newline at end of file + override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { + val calledProcedures = LinkedHashSet() + builder + .getEdges() + .map { it.getFlatLabels().filter { it is InvokeLabel || it is StartLabel } } + .flatten() + .forEach { + when (it) { + is InvokeLabel -> calledProcedures.add(it.name) + is StartLabel -> calledProcedures.add(it.name) + else -> error("Will never be here (due to filter above)") + } + } + builder.parent + .getProcedures() + .filter { calledProcedures.contains(it.name) } + .forEach { it.metaData["reachable-from-${builder.name}"] = Unit } + return builder + } +} diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/DeterministicPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/DeterministicPass.kt index 1f4b1ab032..af5c64b9fb 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/DeterministicPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/DeterministicPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,32 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.passes import hu.bme.mit.theta.xcfa.model.NondetLabel import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder /** - * This pass converts all edges to a deterministic normal form, i.e., no NonDetLabels can be found on the edges. - * Requires the ProcedureBuilder to be `normal` (@see NormalizePass) - * Sets the `deterministic` flag on the ProcedureBuilder + * This pass converts all edges to a deterministic normal form, i.e., no NonDetLabels can be found + * on the edges. Requires the ProcedureBuilder to be `normal` (@see NormalizePass) Sets the + * `deterministic` flag on the ProcedureBuilder */ - class DeterministicPass : ProcedurePass { - override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { - checkNotNull(builder.metaData["normal"]) - val edges = LinkedHashSet(builder.getEdges()) - for (edge in edges) { - if (edge.label is NondetLabel) { - builder.removeEdge(edge) - for (label in edge.label.labels) { - builder.addEdge(edge.withLabel(label)) - } - } + override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { + checkNotNull(builder.metaData["normal"]) + val edges = LinkedHashSet(builder.getEdges()) + for (edge in edges) { + if (edge.label is NondetLabel) { + builder.removeEdge(edge) + for (label in edge.label.labels) { + builder.addEdge(edge.withLabel(label)) } - builder.metaData["deterministic"] = Unit - return builder + } } -} \ No newline at end of file + builder.metaData["deterministic"] = Unit + return builder + } +} diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EliminateSelfLoops.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EliminateSelfLoops.kt index b30444ccab..7589c665e0 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EliminateSelfLoops.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EliminateSelfLoops.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EmptyEdgeRemovalPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EmptyEdgeRemovalPass.kt index 72a4ac29cd..96209063a8 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EmptyEdgeRemovalPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/EmptyEdgeRemovalPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 5964d29473..c7c74d5aa8 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 0bd2e6c4ad..74ab6a32c6 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 2e776e805b..c4a05afd80 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 74d4c53ca9..605224cefa 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 c93b6ee723..1d78039d05 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 aa36b412ad..5aecc2dfc5 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 36e724e5dc..5a4a329048 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LoopUnrollPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LoopUnrollPass.kt index 2d42ee3197..7000a3813e 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LoopUnrollPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/LoopUnrollPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 97538816ff..e22b6e5381 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MemsafetyPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MemsafetyPass.kt index e29faf60c8..5d5fbdc361 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MemsafetyPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MemsafetyPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MutexToVarPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MutexToVarPass.kt index fda7623a5c..7c9970555f 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MutexToVarPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/MutexToVarPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 c5e531a058..1ae874c09f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 3e5167823a..8356074116 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 7222ac96e2..83954665c4 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePass.kt index 36f06af8b0..a7c760b78b 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/ProcedurePass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.passes import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder interface ProcedurePass { - fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder -} \ No newline at end of file + fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder +} 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 ac8a7e4650..c3b67e9e62 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 8fa9614f0b..b43275d55d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/RemoveDeadEnds.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/RemoveDeadEnds.kt index cd593d1772..f7b0fbe2aa 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/RemoveDeadEnds.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/RemoveDeadEnds.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SimplifyExprsPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SimplifyExprsPass.kt index 84d3648685..d81012d3b2 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SimplifyExprsPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SimplifyExprsPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.passes import hu.bme.mit.theta.core.model.ImmutableValuation @@ -32,85 +31,94 @@ import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder import hu.bme.mit.theta.xcfa.simplify /** - * This pass simplifies the expressions inside statements and substitutes the values of constant variables - * (that is, variables assigned only once). - * Requires the ProcedureBuilder to be `deterministic` (@see DeterministicPass) - * Sets the `simplifiedExprs` flag on the ProcedureBuilder + * This pass simplifies the expressions inside statements and substitutes the values of constant + * variables (that is, variables assigned only once). Requires the ProcedureBuilder to be + * `deterministic` (@see DeterministicPass) Sets the `simplifiedExprs` flag on the ProcedureBuilder */ - class SimplifyExprsPass(val parseContext: ParseContext) : ProcedurePass { - override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { - checkNotNull(builder.metaData["deterministic"]) - val unusedLocRemovalPass = UnusedLocRemovalPass() - val valuations = LinkedHashMap() - var edges = LinkedHashSet(builder.getEdges()) - val constValuation = MutableValuation() - val modifiedGlobalVars = builder.parent.getVars().map { it.wrappedVar }.filter { v -> - var firstWrite: XcfaEdge? = null - (builder.parent.getProcedures().sumOf { p -> - p.getEdges().count { e -> - e.getFlatLabels().any { l -> - l.collectVarsWithAccessType().any { it.value.isWritten && it.key == v } - }.also { written -> - if (written && firstWrite == null) firstWrite = e - } - } - } > 1).also { modified -> - if (!modified && firstWrite != null) { - val valuation = MutableValuation() - firstWrite!!.getFlatLabels().forEach { it.simplify(valuation, parseContext) } - valuation.toMap()[v]?.let { constValuation.put(v, it) } - } + override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { + checkNotNull(builder.metaData["deterministic"]) + val unusedLocRemovalPass = UnusedLocRemovalPass() + val valuations = LinkedHashMap() + var edges = LinkedHashSet(builder.getEdges()) + val constValuation = MutableValuation() + val modifiedGlobalVars = + builder.parent + .getVars() + .map { it.wrappedVar } + .filter { v -> + var firstWrite: XcfaEdge? = null + (builder.parent.getProcedures().sumOf { p -> + p.getEdges().count { e -> + e.getFlatLabels() + .any { l -> + l.collectVarsWithAccessType().any { it.value.isWritten && it.key == v } + } + .also { written -> if (written && firstWrite == null) firstWrite = e } + } + } > 1) + .also { modified -> + if (!modified && firstWrite != null) { + val valuation = MutableValuation() + firstWrite!!.getFlatLabels().forEach { it.simplify(valuation, parseContext) } + valuation.toMap()[v]?.let { constValuation.put(v, it) } + } } } - lateinit var lastEdges: LinkedHashSet - do { - lastEdges = edges + lateinit var lastEdges: LinkedHashSet + do { + lastEdges = edges - val toVisit = builder.initLoc.outgoingEdges.toMutableList() - val visited = mutableSetOf() - while (toVisit.isNotEmpty()) { - val edge = toVisit.removeFirst() - visited.add(edge) + val toVisit = builder.initLoc.outgoingEdges.toMutableList() + val visited = mutableSetOf() + while (toVisit.isNotEmpty()) { + val edge = toVisit.removeFirst() + visited.add(edge) - val incomingValuations = edge.source.incomingEdges - .filter { it.getFlatLabels().none { l -> l is StmtLabel && l.stmt == Assume(False()) } } - .map(valuations::get).reduceOrNull(this::intersect) - val localValuation = MutableValuation.copyOf(incomingValuations ?: ImmutableValuation.empty()) - localValuation.putAll(constValuation) - val oldLabels = edge.getFlatLabels() - val newLabels = oldLabels.map { it.simplify(localValuation, parseContext) } + val incomingValuations = + edge.source.incomingEdges + .filter { it.getFlatLabels().none { l -> l is StmtLabel && l.stmt == Assume(False()) } } + .map(valuations::get) + .reduceOrNull(this::intersect) + val localValuation = + MutableValuation.copyOf(incomingValuations ?: ImmutableValuation.empty()) + localValuation.putAll(constValuation) + val oldLabels = edge.getFlatLabels() + val newLabels = oldLabels.map { it.simplify(localValuation, parseContext) } - // note that global variable values are still propagated within an edge (XcfaEdge is considered atomic) - modifiedGlobalVars.forEach { localValuation.remove(it) } + // note that global variable values are still propagated within an edge (XcfaEdge is + // considered atomic) + modifiedGlobalVars.forEach { localValuation.remove(it) } - if (newLabels != oldLabels) { - builder.removeEdge(edge) - valuations.remove(edge) - if (newLabels.firstOrNull().let { (it as? StmtLabel)?.stmt != Assume(False()) }) { - val newEdge = edge.withLabel(SequenceLabel(newLabels)) - builder.addEdge(newEdge) - valuations[newEdge] = localValuation - } - } else { - valuations[edge] = localValuation - } + if (newLabels != oldLabels) { + builder.removeEdge(edge) + valuations.remove(edge) + if (newLabels.firstOrNull().let { (it as? StmtLabel)?.stmt != Assume(False()) }) { + val newEdge = edge.withLabel(SequenceLabel(newLabels)) + builder.addEdge(newEdge) + valuations[newEdge] = localValuation + } + } else { + valuations[edge] = localValuation + } - toVisit.addAll(edge.target.outgoingEdges.filter { it !in visited }) - } - unusedLocRemovalPass.run(builder) + toVisit.addAll(edge.target.outgoingEdges.filter { it !in visited }) + } + unusedLocRemovalPass.run(builder) - edges = LinkedHashSet(builder.getEdges()) - } while (lastEdges != edges) - builder.metaData["simplifiedExprs"] = Unit - return builder - } + edges = LinkedHashSet(builder.getEdges()) + } while (lastEdges != edges) + builder.metaData["simplifiedExprs"] = Unit + return builder + } - private fun intersect(v1: Valuation?, v2: Valuation?): Valuation { - if (v1 == null || v2 == null) return ImmutableValuation.empty() - val v1map = v1.toMap() - val v2map = v2.toMap() - return ImmutableValuation.from(v1map.filter { v2map.containsKey(it.key) && v2map[it.key] == it.value }) - } + private fun intersect(v1: Valuation?, v2: Valuation?): Valuation { + if (v1 == null || v2 == null) return ImmutableValuation.empty() + val v1map = v1.toMap() + val v2map = v2.toMap() + return ImmutableValuation.from( + v1map.filter { v2map.containsKey(it.key) && v2map[it.key] == it.value } + ) + } } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SsaPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SsaPass.kt index 9dd3558796..92aaa7eba7 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SsaPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/SsaPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.passes import hu.bme.mit.theta.core.decl.IndexedVarDecl @@ -29,105 +28,120 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexing import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory import hu.bme.mit.theta.xcfa.model.* -/** - * Transform the procedure to Static Single Assignment (SSA) form. - */ +/** Transform the procedure to Static Single Assignment (SSA) form. */ class SSAPass : ProcedurePass { - private val ssaUtils = SSAUtils() + private val ssaUtils = SSAUtils() - override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { - builder.getEdges().toSet().forEach { edge -> - builder.removeEdge(edge) - builder.addEdge(edge.withLabel(ssaUtils.toSSA(edge))) - } - return builder + override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { + builder.getEdges().toSet().forEach { edge -> + builder.removeEdge(edge) + builder.addEdge(edge.withLabel(ssaUtils.toSSA(edge))) } + return builder + } } internal class SSAUtils { - private var indexing: VarIndexing = VarIndexingFactory.indexing(0) + private var indexing: VarIndexing = VarIndexingFactory.indexing(0) - private val indexedVars = mutableSetOf>() + private val indexedVars = mutableSetOf>() - fun toSSA(edge: XcfaEdge) = edge.label.toSSA() - fun removeSSA(edge: XcfaEdge) = edge.withLabel(edge.label.removeSSA()) + fun toSSA(edge: XcfaEdge) = edge.label.toSSA() - // Convert to SSA + fun removeSSA(edge: XcfaEdge) = edge.withLabel(edge.label.removeSSA()) - private fun XcfaLabel.toSSA(): XcfaLabel { - return when (this) { - is StmtLabel -> { - when (val stmt = this.stmt) { - is AssignStmt<*> -> StmtLabel(stmt.toSSA(), choiceType, metadata) - is AssumeStmt -> StmtLabel(stmt.toSSA(), choiceType, metadata) - is HavocStmt<*> -> StmtLabel(stmt.toSSA(), choiceType, metadata) - else -> error("Unsupported statement at SSA conversion: $stmt") - } - } + // Convert to SSA - is StartLabel -> StartLabel(name, params.map { it.toSSA() }, pidVar.getIndexed(), metadata, tempLookup) - is JoinLabel -> JoinLabel(pidVar.getIndexed(), metadata) - is SequenceLabel -> SequenceLabel(labels.map { it.toSSA() }, metadata) - is NopLabel, is FenceLabel -> this - else -> error("Unsupported label at SSA conversion: $this") + private fun XcfaLabel.toSSA(): XcfaLabel { + return when (this) { + is StmtLabel -> { + when (val stmt = this.stmt) { + is AssignStmt<*> -> StmtLabel(stmt.toSSA(), choiceType, metadata) + is AssumeStmt -> StmtLabel(stmt.toSSA(), choiceType, metadata) + is HavocStmt<*> -> StmtLabel(stmt.toSSA(), choiceType, metadata) + else -> error("Unsupported statement at SSA conversion: $stmt") } + } + + is StartLabel -> + StartLabel(name, params.map { it.toSSA() }, pidVar.getIndexed(), metadata, tempLookup) + is JoinLabel -> JoinLabel(pidVar.getIndexed(), metadata) + is SequenceLabel -> SequenceLabel(labels.map { it.toSSA() }, metadata) + is NopLabel, + is FenceLabel -> this + else -> error("Unsupported label at SSA conversion: $this") } + } - private fun Expr.toSSA(): Expr { - val unfolded = toSSAAtomic() - ExprUtils.getVars(this).forEach { indexing = indexing.inc(it) } - return unfolded - } + private fun Expr.toSSA(): Expr { + val unfolded = toSSAAtomic() + ExprUtils.getVars(this).forEach { indexing = indexing.inc(it) } + return unfolded + } - private fun Expr.toSSAAtomic(): Expr = if (this is RefExpr) { - (decl as? VarDecl)?.getIndexed(false)?.ref ?: this + private fun Expr.toSSAAtomic(): Expr = + if (this is RefExpr) { + (decl as? VarDecl)?.getIndexed(false)?.ref ?: this } else { - map { it.toSSAAtomic() } - } - - private fun VarDecl.getIndexed(increment: Boolean = true): VarDecl { - val newName = this.name + "#" + indexing[this] - indexedVars.find { it.name == newName }?.let { return it as VarDecl } - val newVar = IndexedVarDecl.of(newName, this) - indexedVars.add(newVar) - if (increment) indexing = indexing.inc(this) - return newVar + map { it.toSSAAtomic() } } - private fun AssignStmt.toSSA() = AssignStmt.of(varDecl.getIndexed(), expr.toSSA()) - private fun AssumeStmt.toSSA() = AssumeStmt.of(cond.toSSA()) - private fun HavocStmt.toSSA() = HavocStmt.of(varDecl.getIndexed()) - - // Remove SSA - - private fun XcfaLabel.removeSSA(): XcfaLabel { - return when (this) { - is StmtLabel -> { - when (val stmt = this.stmt) { - is AssignStmt<*> -> StmtLabel(stmt.removeSSA(), choiceType, metadata) - is AssumeStmt -> StmtLabel(stmt.removeSSA(), choiceType, metadata) - is HavocStmt<*> -> StmtLabel(stmt.removeSSA(), choiceType, metadata) - else -> this - } - } - - is StartLabel -> StartLabel(name, params.map { it.removeSSA() }, pidVar.noindex, metadata, tempLookup) - is JoinLabel -> JoinLabel(pidVar.noindex, metadata) - is SequenceLabel -> SequenceLabel(labels.map { it.removeSSA() }, metadata) - else -> this + private fun VarDecl.getIndexed(increment: Boolean = true): VarDecl { + val newName = this.name + "#" + indexing[this] + indexedVars + .find { it.name == newName } + ?.let { + return it as VarDecl + } + val newVar = IndexedVarDecl.of(newName, this) + indexedVars.add(newVar) + if (increment) indexing = indexing.inc(this) + return newVar + } + + private fun AssignStmt.toSSA() = AssignStmt.of(varDecl.getIndexed(), expr.toSSA()) + + private fun AssumeStmt.toSSA() = AssumeStmt.of(cond.toSSA()) + + private fun HavocStmt.toSSA() = HavocStmt.of(varDecl.getIndexed()) + + // Remove SSA + + private fun XcfaLabel.removeSSA(): XcfaLabel { + return when (this) { + is StmtLabel -> { + when (val stmt = this.stmt) { + is AssignStmt<*> -> StmtLabel(stmt.removeSSA(), choiceType, metadata) + is AssumeStmt -> StmtLabel(stmt.removeSSA(), choiceType, metadata) + is HavocStmt<*> -> StmtLabel(stmt.removeSSA(), choiceType, metadata) + else -> this } + } + + is StartLabel -> + StartLabel(name, params.map { it.removeSSA() }, pidVar.noindex, metadata, tempLookup) + is JoinLabel -> JoinLabel(pidVar.noindex, metadata) + is SequenceLabel -> SequenceLabel(labels.map { it.removeSSA() }, metadata) + else -> this } + } - private fun Expr.removeSSA(): Expr = if (this is RefExpr) { - ((decl as? IndexedVarDecl)?.original ?: decl).ref + private fun Expr.removeSSA(): Expr = + if (this is RefExpr) { + ((decl as? IndexedVarDecl)?.original ?: decl).ref } else { - map { it.removeSSA() } + map { it.removeSSA() } } - private val VarDecl.noindex get() = (this as? IndexedVarDecl)?.original ?: this - private fun AssignStmt.removeSSA() = AssignStmt.of(varDecl.noindex, expr.removeSSA()) - private fun AssumeStmt.removeSSA() = AssumeStmt.of(cond.removeSSA()) - private fun HavocStmt.removeSSA() = HavocStmt.of(varDecl.noindex) + private val VarDecl.noindex + get() = (this as? IndexedVarDecl)?.original ?: this + + private fun AssignStmt.removeSSA() = + AssignStmt.of(varDecl.noindex, expr.removeSSA()) + + private fun AssumeStmt.removeSSA() = AssumeStmt.of(cond.removeSSA()) + + private fun HavocStmt.removeSSA() = HavocStmt.of(varDecl.noindex) } diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/StaticCoiPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/StaticCoiPass.kt index c86b1e47ee..d220bdab5b 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/StaticCoiPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/StaticCoiPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,102 +23,114 @@ import hu.bme.mit.theta.xcfa.model.* class StaticCoiPass : ProcedurePass { - companion object { + companion object { - var enabled = false - } + var enabled = false + } - private val directObservers: MutableMap> = mutableMapOf() - private val interProcessObservers: MutableMap> = mutableMapOf() - private val interProcessVarObservers: MutableMap, Set> = mutableMapOf() - - override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { - if (!enabled) return builder - - builder.parent.getProcedures().forEach { procedure -> - procedure.getEdges().forEach { edge -> - val flatLabels = edge.getFlatLabels() - flatLabels.forEachIndexed { index, label -> - if (label is StmtLabel) { - findDirectObservers(edge, label, flatLabels.subList(index + 1, flatLabels.size)) - findIndirectObservers(label, builder) - } - } - } - } + private val directObservers: MutableMap> = mutableMapOf() + private val interProcessObservers: MutableMap> = mutableMapOf() + private val interProcessVarObservers: MutableMap, Set> = mutableMapOf() - builder.getEdges().toSet().forEach { edge -> - val labels = edge.getFlatLabels() - val kept = mutableListOf() - labels.forEach { label -> - if (!label.canBeSimplified || isObserved(label)) { - kept.add(label) - } - } - if (kept.size != labels.size) { - builder.removeEdge(edge) - builder.addEdge(edge.withLabel(SequenceLabel(kept, edge.label.metadata))) - } - } + override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { + if (!enabled) return builder - return builder + builder.parent.getProcedures().forEach { procedure -> + procedure.getEdges().forEach { edge -> + val flatLabels = edge.getFlatLabels() + flatLabels.forEachIndexed { index, label -> + if (label is StmtLabel) { + findDirectObservers(edge, label, flatLabels.subList(index + 1, flatLabels.size)) + findIndirectObservers(label, builder) + } + } + } } - private val XcfaLabel.canBeSimplified - get() = this is StmtLabel && - ((this.stmt is AssignStmt<*> && "_ret" !in this.stmt.varDecl.name) || this.stmt is HavocStmt<*>) && - dereferencesWithAccessTypes.none { it.second.isWritten } - - private fun findDirectObservers(edge: XcfaEdge, label: XcfaLabel, remaining: List) { - val writtenVars = label.collectVarsWithAccessType().filter { it.value.isWritten }.map { it.key }.toSet() - if (writtenVars.isEmpty()) return - - val toVisit = mutableListOf(edge) - val visited = mutableSetOf() - while (toVisit.isNotEmpty()) { - val visiting = toVisit.removeFirst() - visited.add(visiting) - val labels = if (visiting == edge) remaining else visiting.getFlatLabels() - labels.forEach { target -> - val vars = target.collectVarsWithAccessType() - if (vars.any { it.key in writtenVars && it.value.isRead }) { - directObservers[label] = directObservers.getOrDefault(label, setOf()) + target - } - } - - toVisit.addAll(visiting.target.outgoingEdges.filter { it !in visited }) + builder.getEdges().toSet().forEach { edge -> + val labels = edge.getFlatLabels() + val kept = mutableListOf() + labels.forEach { label -> + if (!label.canBeSimplified || isObserved(label)) { + kept.add(label) } + } + if (kept.size != labels.size) { + builder.removeEdge(edge) + builder.addEdge(edge.withLabel(SequenceLabel(kept, edge.label.metadata))) + } } - private fun findIndirectObservers(label: XcfaLabel, builder: XcfaProcedureBuilder) { - val writtenVars = label.collectVarsWithAccessType().filter { it.value.isWritten }.map { it.key }.toSet() - if (writtenVars.isEmpty()) return - - interProcessObservers[label] = writtenVars.flatMap { v -> - interProcessVarObservers.getOrPut(v) { - builder.parent.getProcedures().flatMap { procedure -> - procedure.getEdges().flatMap { e -> - e.getFlatLabels().filter { l -> - l.collectVarsWithAccessType().any { it.key == v && it.value.isRead } - } - } - }.toSet() - } - }.toSet() - } + return builder + } + + private val XcfaLabel.canBeSimplified + get() = + this is StmtLabel && + ((this.stmt is AssignStmt<*> && "_ret" !in this.stmt.varDecl.name) || + this.stmt is HavocStmt<*>) && + dereferencesWithAccessTypes.none { it.second.isWritten } + + private fun findDirectObservers(edge: XcfaEdge, label: XcfaLabel, remaining: List) { + val writtenVars = + label.collectVarsWithAccessType().filter { it.value.isWritten }.map { it.key }.toSet() + if (writtenVars.isEmpty()) return + + val toVisit = mutableListOf(edge) + val visited = mutableSetOf() + while (toVisit.isNotEmpty()) { + val visiting = toVisit.removeFirst() + visited.add(visiting) + val labels = if (visiting == edge) remaining else visiting.getFlatLabels() + labels.forEach { target -> + val vars = target.collectVarsWithAccessType() + if (vars.any { it.key in writtenVars && it.value.isRead }) { + directObservers[label] = directObservers.getOrDefault(label, setOf()) + target + } + } - private fun isObserved(label: XcfaLabel): Boolean { - val toVisit = mutableListOf(label) - val visited = mutableSetOf() - while (toVisit.isNotEmpty()) { - val visiting = toVisit.removeFirst() - if (visiting.collectAssumesVars().isNotEmpty()) return true - if (visiting.dereferencesWithAccessTypes.any { it.second.isWritten }) return true - - visited.add(visiting) - val toAdd = (directObservers[visiting] ?: emptySet()) union (interProcessObservers[visiting] ?: emptySet()) - toVisit.addAll(toAdd.filter { it !in visited }) + toVisit.addAll(visiting.target.outgoingEdges.filter { it !in visited }) + } + } + + private fun findIndirectObservers(label: XcfaLabel, builder: XcfaProcedureBuilder) { + val writtenVars = + label.collectVarsWithAccessType().filter { it.value.isWritten }.map { it.key }.toSet() + if (writtenVars.isEmpty()) return + + interProcessObservers[label] = + writtenVars + .flatMap { v -> + interProcessVarObservers.getOrPut(v) { + builder.parent + .getProcedures() + .flatMap { procedure -> + procedure.getEdges().flatMap { e -> + e.getFlatLabels().filter { l -> + l.collectVarsWithAccessType().any { it.key == v && it.value.isRead } + } + } + } + .toSet() + } } - return false + .toSet() + } + + private fun isObserved(label: XcfaLabel): Boolean { + val toVisit = mutableListOf(label) + val visited = mutableSetOf() + while (toVisit.isNotEmpty()) { + val visiting = toVisit.removeFirst() + if (visiting.collectAssumesVars().isNotEmpty()) return true + if (visiting.dereferencesWithAccessTypes.any { it.second.isWritten }) return true + + visited.add(visiting) + val toAdd = + (directObservers[visiting] ?: emptySet()) union + (interProcessObservers[visiting] ?: emptySet()) + toVisit.addAll(toAdd.filter { it !in visited }) } -} \ No newline at end of file + return false + } +} 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 f97e1adf74..ae04a77cb7 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedLocRemovalPass.kt b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedLocRemovalPass.kt index 02211601fa..a1ef31d0f9 100644 --- a/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedLocRemovalPass.kt +++ b/subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/UnusedLocRemovalPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,24 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa.passes import hu.bme.mit.theta.xcfa.model.XcfaProcedureBuilder -/** - * Removes unused locations - */ - +/** Removes unused locations */ class UnusedLocRemovalPass : ProcedurePass { - override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { - builder.removeLocs { - !it.final && - !it.error && - !it.initial && - it.incomingEdges.size == 0 - } - return builder - } -} \ No newline at end of file + override fun run(builder: XcfaProcedureBuilder): XcfaProcedureBuilder { + builder.removeLocs { !it.final && !it.error && !it.initial && it.incomingEdges.size == 0 } + return builder + } +} 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 7ac6cfb5ee..dc0ab0477b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 6c00d3f8f2..be88456613 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 bb30bddb81..3f42ea4cbf 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaDslTest.kt b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaDslTest.kt index 4a6f1638e7..600ac4a4a4 100644 --- a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaDslTest.kt +++ b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaDslTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,61 +24,55 @@ import org.junit.Test class XcfaDslTest { - private fun getXcfa() = xcfa("example") { - lateinit var x: VarDecl<*> - lateinit var y: VarDecl<*> - global { - x = "x" type Int() init "1" - } - threadlocal { - y = "y" type Int() init "2" - } - val proc1 = procedure("proc1") { - "a" type Int() direction IN - "b" type Int() direction OUT - val c = "c" type Int() direction INOUT - val d = "d" type Int() + private fun getXcfa() = + xcfa("example") { + lateinit var x: VarDecl<*> + lateinit var y: VarDecl<*> + global { x = "x" type Int() init "1" } + threadlocal { y = "y" type Int() init "2" } + val proc1 = + procedure("proc1") { + "a" type Int() direction IN + "b" type Int() direction OUT + val c = "c" type Int() direction INOUT + val d = "d" type Int() - (init to final) { - d assign "a + c" + (init to final) { + d assign "a + c" - havoc("b") - havoc(c) + havoc("b") + havoc(c) - "x" assign d.ref - "y" assign d.ref - } + "x" assign d.ref + "y" assign d.ref + } } - val main = procedure("main") { - val ret = "ret" type Int() - val param = "param" type Int() + val main = + procedure("main") { + val ret = "ret" type Int() + val param = "param" type Int() - val thr1 = "thr1" type Int() - val thr2 = "thr2" type Int() - (init to "L0") { - param assign "0" - proc1("1", ret.ref, param.ref) - thr1.start(proc1, "1", ret.ref, param.ref) - "thr2".start(proc1, "2", ret.ref, param.ref) - } - ("L0" to "L1") { - thr1.join() - thr2.join() - } - ("L1" to final) { - assume(Eq(x.ref as RefExpr, y.ref as RefExpr)) - } - ("L1" to err) { - assume("(/= x y)") - } + val thr1 = "thr1" type Int() + val thr2 = "thr2" type Int() + (init to "L0") { + param assign "0" + proc1("1", ret.ref, param.ref) + thr1.start(proc1, "1", ret.ref, param.ref) + "thr2".start(proc1, "2", ret.ref, param.ref) + } + ("L0" to "L1") { + thr1.join() + thr2.join() + } + ("L1" to final) { assume(Eq(x.ref as RefExpr, y.ref as RefExpr)) } + ("L1" to err) { assume("(/= x y)") } } - main.start() - } - - @Test - fun defineXcfa() { - getXcfa() + main.start() } -} \ No newline at end of file + @Test + fun defineXcfa() { + getXcfa() + } +} diff --git a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaSerializationTest.kt b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaSerializationTest.kt index 8125ddcf8d..d7ffb6c849 100644 --- a/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaSerializationTest.kt +++ b/subprojects/xcfa/xcfa/src/test/java/hu/bme/mit/theta/xcfa/model/XcfaSerializationTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,55 +27,49 @@ import org.junit.Test class XcfaSerializationTest { - private fun getXcfa() = xcfa("example") { - lateinit var x: VarDecl<*> - lateinit var y: VarDecl<*> - global { - x = "x" type Int() init "1" - } - threadlocal { - y = "y" type Int() init "2" - } - val proc1 = procedure("proc1") { - "a" type Int() direction IN - "b" type Int() direction OUT - val c = "c" type Int() direction INOUT - val d = "d" type Int() + private fun getXcfa() = + xcfa("example") { + lateinit var x: VarDecl<*> + lateinit var y: VarDecl<*> + global { x = "x" type Int() init "1" } + threadlocal { y = "y" type Int() init "2" } + val proc1 = + procedure("proc1") { + "a" type Int() direction IN + "b" type Int() direction OUT + val c = "c" type Int() direction INOUT + val d = "d" type Int() - (init to final) { - d assign "a + c" + (init to final) { + d assign "a + c" - havoc("b") - havoc(c) + havoc("b") + havoc(c) - "x" assign d.ref - "y" assign d.ref - } + "x" assign d.ref + "y" assign d.ref + } } - val main = procedure("main") { - val ret = "ret" type Int() - val param = "param" type Int() + val main = + procedure("main") { + val ret = "ret" type Int() + val param = "param" type Int() - (init to "L0") { - param assign "0" - proc1("1", ret.ref, param.ref) - proc1.invoke("1", ret.ref, param.ref) - proc1.invoke("2", ret.ref, param.ref) - } - ("L0" to final) { - assume(Eq(x.ref as RefExpr, y.ref as RefExpr)) - } - ("L0" to err) { - assume("(/= x y)") - } + (init to "L0") { + param assign "0" + proc1("1", ret.ref, param.ref) + proc1.invoke("1", ret.ref, param.ref) + proc1.invoke("2", ret.ref, param.ref) + } + ("L0" to final) { assume(Eq(x.ref as RefExpr, y.ref as RefExpr)) } + ("L0" to err) { assume("(/= x y)") } } - main.start() - } - - @Test - fun serializeXcfa() { - getXcfa().toC(ParseContext(), true, true, true) + main.start() } -} \ No newline at end of file + @Test + fun serializeXcfa() { + getXcfa().toC(ParseContext(), true, true, true) + } +} 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 f7604eb9dd..cce9c63e5f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 ceac776dc8..9926a27c3e 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa2chc/build.gradle.kts b/subprojects/xcfa/xcfa2chc/build.gradle.kts index 59d9d068bd..d9d892824b 100644 --- a/subprojects/xcfa/xcfa2chc/build.gradle.kts +++ b/subprojects/xcfa/xcfa2chc/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xcfa/xcfa2chc/src/main/java/hu/bme/mit/theta/xcfa2chc/Xcfa2Chc.kt b/subprojects/xcfa/xcfa2chc/src/main/java/hu/bme/mit/theta/xcfa2chc/Xcfa2Chc.kt index 23c1f29e3c..1dceb98da1 100644 --- a/subprojects/xcfa/xcfa2chc/src/main/java/hu/bme/mit/theta/xcfa2chc/Xcfa2Chc.kt +++ b/subprojects/xcfa/xcfa2chc/src/main/java/hu/bme/mit/theta/xcfa2chc/Xcfa2Chc.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xcfa2chc import hu.bme.mit.theta.core.Relation @@ -33,56 +32,62 @@ import hu.bme.mit.theta.xcfa.collectVars import hu.bme.mit.theta.xcfa.model.XcfaProcedure fun XcfaProcedure.toCHC(): List { - val i2i = ArrayType.of(Int(), Int()) - - val vars = edges.flatMap { it.label.collectVars() }.toSet().toList() - - val types = vars.map { it.type }.toTypedArray() - val oldParams = vars.associateWith { Param("|" + it.name + "|", it.type) } - val oldParamList = vars.map { oldParams[it]!!.ref }.toTypedArray() - val newParams = vars.associateWith { Param("|" + it.name + "_new|", it.type) } - - val ufs = locs.associateWith { Relation(it.name, *types) } // br, co, rf, com - - edges.forEach { - val unfoldResult = StmtUtils.toExpr(it.label.toStmt(), VarIndexingFactory.basicVarIndexing(0)) - val expr = PathUtils.unfold(And(unfoldResult.exprs), VarIndexingFactory.indexing(0)) - // var[0] is oldParam, var[-1]is newParam, everything else is a fresh param - var cnt = 0 - val consts = ExprUtils.getIndexedConstants(expr).associateWith { - if (it.index == 0) oldParams[it.varDecl]!! - else if (it.index == unfoldResult.indexing[it.varDecl]) newParams[it.varDecl]!! - else Param("__tmp_${cnt++}", it.type) - } - val newParamList = vars.map { if (unfoldResult.indexing[it] == 0) oldParams[it]!!.ref else newParams[it]!!.ref } - .toTypedArray() - val paramdExpr = ExprUtils.changeDecls(expr, consts) - (ufs[it.target]!!)(*newParamList) += (ufs[it.source]!!)(*oldParamList).expr + paramdExpr - } - - if (errorLoc.isPresent) { - !(ufs[errorLoc.get()]!!(*oldParamList)) - } - - ufs[initLoc]!!(*oldParamList) += True() - - return ufs.values.toList() + val i2i = ArrayType.of(Int(), Int()) + + val vars = edges.flatMap { it.label.collectVars() }.toSet().toList() + + val types = vars.map { it.type }.toTypedArray() + val oldParams = vars.associateWith { Param("|" + it.name + "|", it.type) } + val oldParamList = vars.map { oldParams[it]!!.ref }.toTypedArray() + val newParams = vars.associateWith { Param("|" + it.name + "_new|", it.type) } + + val ufs = locs.associateWith { Relation(it.name, *types) } // br, co, rf, com + + edges.forEach { + val unfoldResult = StmtUtils.toExpr(it.label.toStmt(), VarIndexingFactory.basicVarIndexing(0)) + val expr = PathUtils.unfold(And(unfoldResult.exprs), VarIndexingFactory.indexing(0)) + // var[0] is oldParam, var[-1]is newParam, everything else is a fresh param + var cnt = 0 + val consts = + ExprUtils.getIndexedConstants(expr).associateWith { + if (it.index == 0) oldParams[it.varDecl]!! + else if (it.index == unfoldResult.indexing[it.varDecl]) newParams[it.varDecl]!! + else Param("__tmp_${cnt++}", it.type) + } + val newParamList = + vars + .map { if (unfoldResult.indexing[it] == 0) oldParams[it]!!.ref else newParams[it]!!.ref } + .toTypedArray() + val paramdExpr = ExprUtils.changeDecls(expr, consts) + (ufs[it.target]!!)(*newParamList) += (ufs[it.source]!!)(*oldParamList).expr + paramdExpr + } + + if (errorLoc.isPresent) { + !(ufs[errorLoc.get()]!!(*oldParamList)) + } + + ufs[initLoc]!!(*oldParamList) += True() + + return ufs.values.toList() } fun XcfaProcedure.toSMT2CHC(): String { - val chc = toCHC() - val smt2 = chc.toSMT2() - return smt2 + val chc = toCHC() + val smt2 = chc.toSMT2() + return smt2 } - fun List.toSMT2(): String { - val symbolTable = GenericSmtLibSymbolTable() - val transformationManager = GenericSmtLibTransformationManager(symbolTable) - val terms = flatMap { it.rules.map { "(assert " + transformationManager.toTerm(it.toExpr()) + ")" } } - val decls = filter { symbolTable.definesConst(it.constDecl) }.map { symbolTable.getDeclaration(it.constDecl) } - - return """ + val symbolTable = GenericSmtLibSymbolTable() + val transformationManager = GenericSmtLibTransformationManager(symbolTable) + val terms = flatMap { + it.rules.map { "(assert " + transformationManager.toTerm(it.toExpr()) + ")" } + } + val decls = + filter { symbolTable.definesConst(it.constDecl) } + .map { symbolTable.getDeclaration(it.constDecl) } + + return """ ; generated by Theta ; https://github.com/ftsrg/theta/ @@ -96,7 +101,8 @@ ${terms.joinToString("\n")} (check-sat) (exit) -""".trimIndent() +""" + .trimIndent() } fun Relation.toSMT2() = listOf(this).toSMT2() 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 19d0e67234..3bb0e2fbc9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/build.gradle.kts b/subprojects/xsts/xsts-analysis/build.gradle.kts index 2f3d02e007..117dfa52dc 100644 --- a/subprojects/xsts/xsts-analysis/build.gradle.kts +++ b/subprojects/xsts/xsts-analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAction.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAction.java index c7876f9bfb..d2a3370bd5 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAction.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import hu.bme.mit.theta.analysis.expr.StmtAction; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.stmt.Stmt; - import java.util.List; public final class XstsAction extends StmtAction { diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAnalysis.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAnalysis.java index 7ccda678a3..44361c63e6 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAnalysis.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,11 @@ */ package hu.bme.mit.theta.xsts.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.*; import hu.bme.mit.theta.analysis.expr.ExprState; -import static com.google.common.base.Preconditions.checkNotNull; - public final class XstsAnalysis implements Analysis, XstsAction, P> { diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsInitFunc.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsInitFunc.java index a503ec3681..975b266d15 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsInitFunc.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,12 +18,11 @@ import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.expr.ExprState; - import java.util.ArrayList; import java.util.Collection; -public final class XstsInitFunc implements - InitFunc, P> { +public final class XstsInitFunc + implements InitFunc, P> { private final InitFunc initFunc; diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsLts.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsLts.java index 6d762ad336..be99527022 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsLts.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.core.stmt.NonDetStmt; import hu.bme.mit.theta.xsts.XSTS; - import java.util.Collection; import java.util.stream.Collectors; @@ -39,8 +38,8 @@ private XstsLts(final XSTS xsts, final XstsStmtOptimizer stmtOptimizer) { this.stmtOptimizer = stmtOptimizer; } - public static LTS, XstsAction> create(final XSTS xsts, - final XstsStmtOptimizer stmtOptimizer) { + public static LTS, XstsAction> create( + final XSTS xsts, final XstsStmtOptimizer stmtOptimizer) { return new XstsLts<>(xsts, stmtOptimizer); } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsOrd.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsOrd.java index 5c078dc7b9..cead32468e 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsOrd.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,11 @@ */ package hu.bme.mit.theta.xsts.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.expr.ExprState; -import static com.google.common.base.Preconditions.checkNotNull; - public final class XstsOrd implements PartialOrd> { private final PartialOrd partialOrd; diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsState.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsState.java index 852b42de16..affafa4e02 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsState.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,7 +19,6 @@ import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Objects; public final class XstsState implements ExprState { @@ -34,8 +33,8 @@ private XstsState(S state, boolean lastActionWasEnv, boolean initialized) { this.initialized = initialized; } - public static XstsState of(final S state, - final boolean lastActionWasEnv, final boolean initialized) { + public static XstsState of( + final S state, final boolean lastActionWasEnv, final boolean initialized) { return new XstsState<>(state, lastActionWasEnv, initialized); } @@ -63,9 +62,13 @@ public boolean isBottom() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).aligned() + return Utils.lispStringBuilder(getClass().getSimpleName()) + .aligned() .add(initialized ? "post_init" : "pre_init") - .add(lastActionWasEnv ? "last_env" : "last_internal").body().add(state).toString(); + .add(lastActionWasEnv ? "last_env" : "last_internal") + .body() + .add(state) + .toString(); } @Override @@ -78,7 +81,8 @@ public boolean equals(Object o) { } XstsState xstsState = (XstsState) o; return lastActionWasEnv == xstsState.lastActionWasEnv - && initialized == xstsState.initialized && state.equals(xstsState.state); + && initialized == xstsState.initialized + && state.equals(xstsState.state); } @Override diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStatePredicate.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStatePredicate.java index b70c5040ce..9771d3aebf 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStatePredicate.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStatePredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,11 +16,10 @@ package hu.bme.mit.theta.xsts.analysis; import hu.bme.mit.theta.analysis.expr.ExprState; - import java.util.function.Predicate; -public class XstsStatePredicate

implements - Predicate> { +public class XstsStatePredicate

+ implements Predicate> { private final P pred; diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStmtOptimizer.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStmtOptimizer.java index aa367fa01b..0bddf35dce 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStmtOptimizer.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsStmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,8 +15,8 @@ */ package hu.bme.mit.theta.xsts.analysis; -import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; import hu.bme.mit.theta.analysis.expr.ExprState; +import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; import hu.bme.mit.theta.core.stmt.Stmt; public class XstsStmtOptimizer implements StmtOptimizer> { diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsTransFunc.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsTransFunc.java index c086446867..7abdc3861e 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsTransFunc.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/XstsTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.xsts.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expr.ExprState; - import java.util.ArrayList; import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class XstsTransFunc implements - TransFunc, XstsAction, P> { +public final class XstsTransFunc + implements TransFunc, XstsAction, P> { private final TransFunc transFunc; @@ -39,8 +38,8 @@ public static XstsTransFunc create( } @Override - public Collection> getSuccStates(final XstsState state, - final XstsAction action, final P prec) { + public Collection> getSuccStates( + final XstsState state, final XstsAction action, final P prec) { checkNotNull(state); checkNotNull(action); @@ -50,8 +49,8 @@ public Collection> getSuccStates(final XstsState state final S subState = state.getState(); final boolean succWasLastEnv = !state.lastActionWasEnv(); - final Collection subSuccStates = transFunc.getSuccStates(subState, action, - prec); + final Collection subSuccStates = + transFunc.getSuccStates(subState, action, prec); for (final S subSuccState : subSuccStates) { final XstsState succState = XstsState.of(subSuccState, succWasLastEnv, true); succStates.add(succState); diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsAutoExpl.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsAutoExpl.java index fe43ea42b7..af44cd441e 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsAutoExpl.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,5 +21,4 @@ public interface XstsAutoExpl { AutoExpl create(final XSTS xsts); - } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewAtomsAutoExpl.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewAtomsAutoExpl.java index 430426c3a1..2d53906612 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewAtomsAutoExpl.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewAtomsAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,10 +20,9 @@ import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.utils.StmtAtomCollector; import hu.bme.mit.theta.core.utils.ExprUtils; +import hu.bme.mit.theta.core.utils.StmtAtomCollector; import hu.bme.mit.theta.xsts.XSTS; - import java.util.Set; import java.util.stream.Collectors; @@ -38,10 +37,11 @@ public AutoExpl create(XSTS xsts) { atoms.addAll(ExprUtils.getAtoms(xsts.getProp())); atoms.addAll(ExprUtils.getAtoms(xsts.getInitFormula())); - final Set> canonicalAtoms = atoms.stream() - .map(ExprUtils::canonize) - .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) - .collect(Collectors.toSet()); + final Set> canonicalAtoms = + atoms.stream() + .map(ExprUtils::canonize) + .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) + .collect(Collectors.toSet()); return new NewAtomsAutoExpl(xsts.getCtrlVars(), canonicalAtoms, 0); } } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewOperandsAutoExpl.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewOperandsAutoExpl.java index b12ac774e9..6320ef9c1b 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewOperandsAutoExpl.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsNewOperandsAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,14 +19,12 @@ import hu.bme.mit.theta.analysis.expr.refinement.autoexpl.NewOperandsAutoExpl; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.Decl; -import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import hu.bme.mit.theta.core.utils.StmtAtomCollector; import hu.bme.mit.theta.core.utils.ExprUtils; +import hu.bme.mit.theta.core.utils.StmtAtomCollector; import hu.bme.mit.theta.xsts.XSTS; - import java.util.Map; import java.util.Set; import java.util.function.Predicate; @@ -43,10 +41,11 @@ public AutoExpl create(XSTS xsts) { atoms.addAll(ExprUtils.getAtoms(xsts.getProp())); atoms.addAll(ExprUtils.getAtoms(xsts.getInitFormula())); - final Set> canonicalAtoms = atoms.stream() - .map(ExprUtils::canonize) - .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) - .collect(Collectors.toSet()); + final Set> canonicalAtoms = + atoms.stream() + .map(ExprUtils::canonize) + .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) + .collect(Collectors.toSet()); final Map, Set>> declToOps = Containers.createMap(); canonicalAtoms.stream() .filter(atom -> atom.getOps().size() > 1) @@ -56,15 +55,20 @@ public AutoExpl create(XSTS xsts) { .filter(RefExpr.class::isInstance) .map(RefExpr.class::cast) .forEach( - ref -> atom.getOps().stream() - .filter(Predicate.not(ref::equals)) - .forEach( - op -> declToOps.computeIfAbsent(ref.getDecl(), - k -> Containers.createSet()).add((op)) - ) - ); - } - ); + ref -> + atom.getOps().stream() + .filter(Predicate.not(ref::equals)) + .forEach( + op -> + declToOps + .computeIfAbsent( + ref + .getDecl(), + k -> + Containers + .createSet()) + .add((op)))); + }); return new NewOperandsAutoExpl(xsts.getCtrlVars(), declToOps, 0); } } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsStaticAutoExpl.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsStaticAutoExpl.java index f26d8de29d..705d9dd7d8 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsStaticAutoExpl.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/autoexpl/XstsStaticAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/VarFilter.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/VarFilter.java index a7a7414c5a..8f4c8aeeb8 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/VarFilter.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/VarFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,6 @@ import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.xsts.XSTS; - import java.util.Optional; public final class VarFilter { @@ -45,5 +44,4 @@ public Valuation filter(final Valuation valuation) { } return filteredValuation; } - } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsStateSequence.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsStateSequence.java index a0923508d7..d51f078526 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsStateSequence.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsStateSequence.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.xsts.analysis.concretizer; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkElementIndex; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.common.LispStringBuilder; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.xsts.XSTS; import hu.bme.mit.theta.xsts.analysis.XstsState; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkElementIndex; -import static com.google.common.base.Preconditions.checkNotNull; - public final class XstsStateSequence { private final ImmutableList> states; @@ -80,12 +79,13 @@ public String toString() { final LispStringBuilder sb = Utils.lispStringBuilder(getClass().getSimpleName()).body(); for (int i = 0; i <= length(); i++) { XstsState state = states.get(i); - sb.add(Utils.lispStringBuilder(XstsState.class.getSimpleName()) - .add(state.isInitialized() ? "post_init" : "pre_init") - .add(state.lastActionWasEnv() ? "last_env" : "last_internal").body() - .add(state.getState().toString())); + sb.add( + Utils.lispStringBuilder(XstsState.class.getSimpleName()) + .add(state.isInitialized() ? "post_init" : "pre_init") + .add(state.lastActionWasEnv() ? "last_env" : "last_internal") + .body() + .add(state.getState().toString())); } return sb.toString(); } - } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsTraceConcretizerUtil.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsTraceConcretizerUtil.java index 0c3a789d41..deb6871cae 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsTraceConcretizerUtil.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/concretizer/XstsTraceConcretizerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.xsts.analysis.concretizer; +import static com.google.common.base.Preconditions.checkArgument; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expl.ExplState; @@ -27,25 +30,24 @@ import hu.bme.mit.theta.xsts.XSTS; import hu.bme.mit.theta.xsts.analysis.XstsAction; import hu.bme.mit.theta.xsts.analysis.XstsState; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; - public final class XstsTraceConcretizerUtil { - private XstsTraceConcretizerUtil() { - } + private XstsTraceConcretizerUtil() {} public static XstsStateSequence concretize( - final Trace, XstsAction> trace, SolverFactory solverFactory, final XSTS xsts) { + final Trace, XstsAction> trace, + SolverFactory solverFactory, + final XSTS xsts) { final VarFilter varFilter = VarFilter.of(xsts); - final ExprTraceChecker checker = ExprTraceFwBinItpChecker.create( - xsts.getInitFormula(), - Not(xsts.getProp()), solverFactory.createItpSolver()); + final ExprTraceChecker checker = + ExprTraceFwBinItpChecker.create( + xsts.getInitFormula(), + Not(xsts.getProp()), + solverFactory.createItpSolver()); final ExprTraceStatus status = checker.check(trace); checkArgument(status.isFeasible(), "Infeasible trace."); final Trace valuations = status.asFeasible().getValuations(); @@ -54,10 +56,13 @@ public static XstsStateSequence concretize( final List> xstsStates = new ArrayList<>(); for (int i = 0; i < trace.getStates().size(); ++i) { - xstsStates.add(XstsState.of(ExplState.of(varFilter.filter(valuations.getState(i))), - trace.getState(i).lastActionWasEnv(), trace.getState(i).isInitialized())); + xstsStates.add( + XstsState.of( + ExplState.of(varFilter.filter(valuations.getState(i))), + trace.getState(i).lastActionWasEnv(), + trace.getState(i).isInitialized())); } return XstsStateSequence.of(xstsStates, xsts); } -} \ No newline at end of file +} diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfig.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfig.java index 4c1839a5f3..141641d4c4 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfig.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -38,5 +38,4 @@ public static XstsConfig, Trace> check() { return checker.check(initPrec); } - -} \ No newline at end of file +} diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfigBuilder.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfigBuilder.java index 016d828fcb..0b9b85b58c 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfigBuilder.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/config/XstsConfigBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsAllVarsInitPrec.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsAllVarsInitPrec.java index 0e3a2e79ed..3e871e8df9 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsAllVarsInitPrec.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsAllVarsInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsCtrlInitPrec.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsCtrlInitPrec.java index e18358d7df..8d2b1b0991 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsCtrlInitPrec.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsCtrlInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsEmptyInitPrec.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsEmptyInitPrec.java index a0252dea0c..cf295b5e94 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsEmptyInitPrec.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsEmptyInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -36,5 +36,4 @@ public PredPrec createPred(final XSTS sts) { public Prod2Prec createProd2ExplPred(final XSTS sts) { return Prod2Prec.of(ExplPrec.empty(), PredPrec.of()); } - } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsInitPrec.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsInitPrec.java index 3c74354f77..8fe487495e 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsInitPrec.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,18 +22,12 @@ public interface XstsInitPrec { - /** - * Creates initial ExplPrec based on an XSTS. - */ + /** Creates initial ExplPrec based on an XSTS. */ ExplPrec createExpl(XSTS xsts); - /** - * Creates initial PredPrec based on an XSTS. - */ + /** Creates initial PredPrec based on an XSTS. */ PredPrec createPred(XSTS xsts); - /** - * Creates initial Prod2ExplPredPrec based on an XSTS. - */ + /** Creates initial Prod2ExplPredPrec based on an XSTS. */ Prod2Prec createProd2ExplPred(XSTS xsts); } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsPropInitPrec.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsPropInitPrec.java index 5cdd313340..8526ea3b9b 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsPropInitPrec.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/initprec/XstsPropInitPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -35,7 +35,7 @@ public PredPrec createPred(XSTS xsts) { @Override public Prod2Prec createProd2ExplPred(XSTS xsts) { - return Prod2Prec.of(ExplPrec.of(xsts.getCtrlVars()), - PredPrec.of(ExprUtils.getAtoms(xsts.getProp()))); + return Prod2Prec.of( + ExplPrec.of(xsts.getCtrlVars()), PredPrec.of(ExprUtils.getAtoms(xsts.getProp()))); } } diff --git a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/mdd/XstsMddChecker.java b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/mdd/XstsMddChecker.java index 9d23f5547c..b575f2a476 100644 --- a/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/mdd/XstsMddChecker.java +++ b/subprojects/xsts/xsts-analysis/src/main/java/hu/bme/mit/theta/xsts/analysis/mdd/XstsMddChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToMonolithicExpr.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToMonolithicExpr.kt index a72c8f79c7..c7d1d3f74c 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToMonolithicExpr.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsToMonolithicExpr.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,38 +18,32 @@ package hu.bme.mit.theta.xsts.analysis.hu.bme.mit.theta.xsts.analysis import hu.bme.mit.theta.analysis.algorithm.bounded.MonolithicExpr import hu.bme.mit.theta.analysis.expl.ExplState import hu.bme.mit.theta.core.model.Valuation -import hu.bme.mit.theta.core.stmt.Stmts; +import hu.bme.mit.theta.core.stmt.Stmts import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And -import hu.bme.mit.theta.core.utils.StmtUtils; -import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; -import hu.bme.mit.theta.xsts.XSTS; +import hu.bme.mit.theta.core.utils.StmtUtils +import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory +import hu.bme.mit.theta.xsts.XSTS import hu.bme.mit.theta.xsts.analysis.XstsAction import hu.bme.mit.theta.xsts.analysis.XstsState fun XSTS.toMonolithicExpr(): MonolithicExpr { - val initUnfoldResult = StmtUtils.toExpr(this.init, VarIndexingFactory.indexing(0)) - val initExpr = And(And(initUnfoldResult.exprs), this.initFormula) - val initOffsetIndex = initUnfoldResult.indexing - val envTran = Stmts.SequenceStmt(listOf(this.env, this.tran)) - val envTranUnfoldResult = StmtUtils.toExpr(envTran, VarIndexingFactory.indexing(0)); - val transExpr = And(envTranUnfoldResult.exprs); - val transOffsetIndex = envTranUnfoldResult.indexing; - val propExpr = this.prop + val initUnfoldResult = StmtUtils.toExpr(this.init, VarIndexingFactory.indexing(0)) + val initExpr = And(And(initUnfoldResult.exprs), this.initFormula) + val initOffsetIndex = initUnfoldResult.indexing + val envTran = Stmts.SequenceStmt(listOf(this.env, this.tran)) + val envTranUnfoldResult = StmtUtils.toExpr(envTran, VarIndexingFactory.indexing(0)) + val transExpr = And(envTranUnfoldResult.exprs) + val transOffsetIndex = envTranUnfoldResult.indexing + val propExpr = this.prop - return MonolithicExpr(initExpr, transExpr, propExpr, transOffsetIndex, initOffsetIndex) + return MonolithicExpr(initExpr, transExpr, propExpr, transOffsetIndex, initOffsetIndex) } fun XSTS.valToAction(val1: Valuation, val2: Valuation): XstsAction { - return XstsAction.create( - Stmts.SequenceStmt(listOf(this.env, this.tran)) - ) + return XstsAction.create(Stmts.SequenceStmt(listOf(this.env, this.tran))) } fun XSTS.valToState(val1: Valuation): XstsState { - return XstsState.of( - ExplState.of(val1), - false, - true - ) -} \ No newline at end of file + return XstsState.of(ExplState.of(val1), false, true) +} 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 bae9dee270..fb2c7c3f10 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsVarOrdering.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsVarOrdering.kt index 4587811487..49986b987a 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsVarOrdering.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/XstsVarOrdering.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 071890cd0c..49bb325fe1 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtils.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtils.kt index e8afeb3081..4a62b3bf37 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtils.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFunc.kt b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFunc.kt index f8eaaa1b41..def9dbc381 100644 --- a/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFunc.kt +++ b/subprojects/xsts/xsts-analysis/src/main/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFunc.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.analysis.util import hu.bme.mit.theta.analysis.Prec @@ -21,5 +20,5 @@ import hu.bme.mit.theta.analysis.unit.UnitState import hu.bme.mit.theta.xsts.analysis.XstsInitFunc fun

xstsControlInitFunc(): XstsInitFunc { - return XstsInitFunc.create { _: P -> listOf(UnitState.getInstance()) } -} \ No newline at end of file + return XstsInitFunc.create { _: P -> listOf(UnitState.getInstance()) } +} 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 0cb2ccccd3..5841e305be 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -14,7 +14,7 @@ * limitations under the License. */ package hu.bme.mit.theta.xsts.analysis.util /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsBfsMddCheckerTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsBfsMddCheckerTest.java index fb49ddc335..406c3b39d2 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsBfsMddCheckerTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsBfsMddCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -39,7 +39,7 @@ public static java.util.Collection data() { @Test public void test() throws Exception { - XstsMddCheckerTest.runTestWithIterationStrategy(filePath, propPath, safe, IterationStrategy.BFS); + XstsMddCheckerTest.runTestWithIterationStrategy( + filePath, propPath, safe, IterationStrategy.BFS); } - } diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsEnumSemanticsTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsEnumSemanticsTest.java index bccabf00bf..3b9477eebe 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsEnumSemanticsTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsEnumSemanticsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,22 +16,22 @@ package hu.bme.mit.theta.xsts.analysis; import hu.bme.mit.theta.xsts.dsl.XstsDslManager; -import org.junit.Test; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; +import org.junit.Test; public class XstsEnumSemanticsTest { @Test(expected = ClassCastException.class) public void test() throws IOException { - try (InputStream inputStream = new SequenceInputStream(new FileInputStream("src/test/resources/model/literals_bad.xsts"), - new FileInputStream("src/test/resources/property/literals.prop"))) { + try (InputStream inputStream = + new SequenceInputStream( + new FileInputStream("src/test/resources/model/literals_bad.xsts"), + new FileInputStream("src/test/resources/property/literals.prop"))) { XstsDslManager.createXsts(inputStream); } } - } diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsGsatMddCheckerTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsGsatMddCheckerTest.java index 88e8d46928..0b138a562b 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsGsatMddCheckerTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsGsatMddCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -39,7 +39,7 @@ public static java.util.Collection data() { @Test public void test() throws Exception { - XstsMddCheckerTest.runTestWithIterationStrategy(filePath, propPath, safe, IterationStrategy.GSAT); + XstsMddCheckerTest.runTestWithIterationStrategy( + filePath, propPath, safe, IterationStrategy.GSAT); } - } diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsHornTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsHornTest.java index e3df33dd48..e339dfd688 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsHornTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsHornTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsInitExprNodeTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsInitExprNodeTest.java index 9c76321588..86eb332546 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsInitExprNodeTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsInitExprNodeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,29 +15,24 @@ */ package hu.bme.mit.theta.xsts.analysis; +import static org.junit.Assert.assertEquals; + import hu.bme.mit.delta.java.mdd.*; import hu.bme.mit.theta.analysis.algorithm.mdd.MddValuationCollector; -import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.ExprLatticeDefinition; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.MddExpressionTemplate; -import hu.bme.mit.theta.analysis.utils.MddNodeVisualizer; -import hu.bme.mit.theta.common.visualization.Graph; -import hu.bme.mit.theta.common.visualization.writer.GraphvizWriter; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.PathUtils; +import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; import hu.bme.mit.theta.xsts.XSTS; import hu.bme.mit.theta.xsts.dsl.XstsDslManager; -import org.junit.Test; - import java.io.*; import java.util.Set; - -import static org.junit.Assert.assertEquals; - +import org.junit.Test; public class XstsInitExprNodeTest { @@ -45,22 +40,30 @@ public class XstsInitExprNodeTest { public void testInit() throws IOException { XSTS xsts; - try (InputStream inputStream = new SequenceInputStream(new FileInputStream("src/test/resources/model/trafficlight.xsts"), new FileInputStream("src/test/resources/property/green_and_red.prop"))) { + try (InputStream inputStream = + new SequenceInputStream( + new FileInputStream("src/test/resources/model/trafficlight.xsts"), + new FileInputStream("src/test/resources/property/green_and_red.prop"))) { xsts = XstsDslManager.createXsts(inputStream); } - MddGraph mddGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + MddGraph mddGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); MddVariableOrder varOrder = JavaMddFactory.getDefault().createMddVariableOrder(mddGraph); Expr expr = PathUtils.unfold(xsts.getInitFormula(), 0); MddVariable lastVar = null; for (var v : xsts.getVars()) { - lastVar = varOrder.createOnTop(hu.bme.mit.delta.mdd.MddVariableDescriptor.create(v.getConstDecl(0), 0)); + lastVar = + varOrder.createOnTop( + hu.bme.mit.delta.mdd.MddVariableDescriptor.create( + v.getConstDecl(0), 0)); } SolverPool solverPool = new SolverPool(Z3LegacySolverFactory.getInstance()); - MddNode rootNode = lastVar.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); + MddNode rootNode = + lastVar.checkInNode(MddExpressionTemplate.of(expr, o -> (Decl) o, solverPool)); var recursiveCursor = rootNode.cursor(); recursiveCursor.moveNext(); @@ -68,7 +71,5 @@ public void testInit() throws IOException { final Set valuations = MddValuationCollector.collect(rootNode); assertEquals(valuations.size(), 1); - } - } diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddCheckerTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddCheckerTest.java index c5313c1dc3..5d3a466cb3 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddCheckerTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddStructuralSymbolicComparisonTest.java b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddStructuralSymbolicComparisonTest.java index 49d5efc60f..b5d8753328 100644 --- a/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddStructuralSymbolicComparisonTest.java +++ b/subprojects/xsts/xsts-analysis/src/test/java/hu/bme/mit/theta/xsts/analysis/XstsMddStructuralSymbolicComparisonTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,13 @@ */ package hu.bme.mit.theta.xsts.analysis; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.xsts.analysis.util.RandomXstsKt.generateXsts; +import static org.junit.Assert.assertTrue; + import com.koloboke.collect.map.hash.HashObjObjMaps; import hu.bme.mit.delta.collections.RecursiveIntObjCursor; import hu.bme.mit.delta.java.mdd.JavaMddFactory; @@ -23,7 +30,6 @@ import hu.bme.mit.delta.java.mdd.MddToStructuralTransformer; import hu.bme.mit.delta.java.mdd.MddVariableOrder; import hu.bme.mit.delta.mdd.MddVariableDescriptor; -import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.ExprLatticeDefinition; import hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode.MddExpressionTemplate; import hu.bme.mit.theta.core.decl.Decl; @@ -33,11 +39,8 @@ import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.core.utils.StmtUtils; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; +import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.solver.z3legacy.Z3LegacySolverFactory; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -45,13 +48,9 @@ import java.util.Random; import java.util.stream.Collectors; import java.util.stream.IntStream; - -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Geq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.xsts.analysis.util.RandomXstsKt.generateXsts; -import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; @RunWith(value = org.junit.runners.Parameterized.class) public class XstsMddStructuralSymbolicComparisonTest { @@ -65,7 +64,7 @@ public class XstsMddStructuralSymbolicComparisonTest { @Parameterized.Parameters(name = "{index}: {0}") public static List data() { return IntStream.range(0, iterations) - .mapToObj(i -> new Object[]{i}) + .mapToObj(i -> new Object[] {i}) .collect(Collectors.toList()); } @@ -75,50 +74,82 @@ public void test() throws Exception { try (var pool = new SolverPool(Z3LegacySolverFactory.getInstance())) { var xsts = generateXsts(seed); - final MddGraph transGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); - final MddGraph structGraph = JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + final MddGraph transGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); + final MddGraph structGraph = + JavaMddFactory.getDefault().createMddGraph(ExprLatticeDefinition.forExpr()); - final MddVariableOrder transOrder = JavaMddFactory.getDefault().createMddVariableOrder(transGraph); - final MddVariableOrder structOrder = JavaMddFactory.getDefault().createMddVariableOrder(structGraph); + final MddVariableOrder transOrder = + JavaMddFactory.getDefault().createMddVariableOrder(transGraph); + final MddVariableOrder structOrder = + JavaMddFactory.getDefault().createMddVariableOrder(structGraph); - final var tranToExprResult = StmtUtils.toExpr(xsts.getTran(), VarIndexingFactory.indexing(0)); + final var tranToExprResult = + StmtUtils.toExpr(xsts.getTran(), VarIndexingFactory.indexing(0)); final List> boundExprs = new ArrayList<>(); final var shuffledVars = new ArrayList<>(xsts.getVars()); Collections.shuffle(shuffledVars, new Random(seed)); for (var v : shuffledVars) { - final int domainSize = v.getType().getDomainSize() == DomainSize.INFINITY ? 0 : v.getType().getDomainSize().getFiniteSize().intValue(); - - transOrder.createOnTop(MddVariableDescriptor.create(v.getConstDecl(tranToExprResult.getIndexing().get(v) == 0 ? 1 : tranToExprResult.getIndexing().get(v)), domainSize)); + final int domainSize = + v.getType().getDomainSize() == DomainSize.INFINITY + ? 0 + : v.getType().getDomainSize().getFiniteSize().intValue(); + + transOrder.createOnTop( + MddVariableDescriptor.create( + v.getConstDecl( + tranToExprResult.getIndexing().get(v) == 0 + ? 1 + : tranToExprResult.getIndexing().get(v)), + domainSize)); transOrder.createOnTop(MddVariableDescriptor.create(v.getConstDecl(0), domainSize)); - structOrder.createOnTop(MddVariableDescriptor.create(v.getName() + "2", domainSize)); + structOrder.createOnTop( + MddVariableDescriptor.create(v.getName() + "2", domainSize)); structOrder.createOnTop(MddVariableDescriptor.create(v.getName(), domainSize)); if (v.getType() instanceof hu.bme.mit.theta.core.type.inttype.IntType) { boundExprs.add(Geq(v.getConstDecl(0).getRef(), Int(0))); boundExprs.add(Leq(v.getConstDecl(0).getRef(), Int(upperbound))); - boundExprs.add(Geq(v.getConstDecl(tranToExprResult.getIndexing().get(v) == 0 ? 1 : tranToExprResult.getIndexing().get(v)).getRef(), Int(0))); - boundExprs.add(Leq(v.getConstDecl(tranToExprResult.getIndexing().get(v) == 0 ? 1 : tranToExprResult.getIndexing().get(v)).getRef(), Int(upperbound))); + boundExprs.add( + Geq( + v.getConstDecl( + tranToExprResult.getIndexing().get(v) == 0 + ? 1 + : tranToExprResult.getIndexing().get(v)) + .getRef(), + Int(0))); + boundExprs.add( + Leq( + v.getConstDecl( + tranToExprResult.getIndexing().get(v) == 0 + ? 1 + : tranToExprResult.getIndexing().get(v)) + .getRef(), + Int(upperbound))); } } final var transSig = transOrder.getDefaultSetSignature(); final var structSig = structOrder.getDefaultSetSignature(); - var stmtUnfold = PathUtils.unfold(tranToExprResult.getExprs().stream().findFirst().get(), 0); + var stmtUnfold = + PathUtils.unfold(tranToExprResult.getExprs().stream().findFirst().get(), 0); stmtUnfold = And(stmtUnfold, And(boundExprs)); - final MddHandle transitionNode = transSig.getTopVariableHandle().checkInNode(MddExpressionTemplate.of(stmtUnfold, o -> (Decl) o, pool)); + final MddHandle transitionNode = + transSig.getTopVariableHandle() + .checkInNode(MddExpressionTemplate.of(stmtUnfold, o -> (Decl) o, pool)); - final MddHandle structuralTransitionNode = MddToStructuralTransformer.transform(transitionNode, structSig.getTopVariableHandle()); + final MddHandle structuralTransitionNode = + MddToStructuralTransformer.transform( + transitionNode, structSig.getTopVariableHandle()); final Long symbolicSize = calculateNonzeroCount(transitionNode); final Long structuralSize = calculateNonzeroCount(structuralTransitionNode); assertTrue(symbolicSize >= structuralSize); } - } - private static Long calculateNonzeroCount(MddHandle root) { if (root == null) { throw new IllegalArgumentException("Root handle cannot be null."); @@ -130,7 +161,11 @@ private static Long calculateNonzeroCount(MddHandle root) { } } - private static Long calculateNonzeroCount(MddHandle node, int level, Map cache, RecursiveIntObjCursor cursor) { + private static Long calculateNonzeroCount( + MddHandle node, + int level, + Map cache, + RecursiveIntObjCursor cursor) { Long cached = (Long) cache.getOrDefault(node, null); if (cached != null) { return cached; @@ -158,5 +193,4 @@ private static Long calculateNonzeroCount(MddHandle node, int level, Map data() { - return Arrays.asList(new Object[][]{ - - {"src/test/resources/model/trafficlight.xsts", - "src/test/resources/property/green_and_red.prop", true, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/trafficlight.xsts", - "src/test/resources/property/green_and_red.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/trafficlight.xsts", - "src/test/resources/property/green_and_red.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/trafficlight_v2.xsts", - "src/test/resources/property/green_and_red.prop", true, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/trafficlight_v2.xsts", - "src/test/resources/property/green_and_red.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/trafficlight_v2.xsts", - "src/test/resources/property/green_and_red.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/counter5.xsts", - "src/test/resources/property/x_between_0_and_5.prop", true, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/counter5.xsts", - "src/test/resources/property/x_between_0_and_5.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/counter5.xsts", - "src/test/resources/property/x_between_0_and_5.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/counter5.xsts", "src/test/resources/property/x_eq_5.prop", - false, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/counter5.xsts", "src/test/resources/property/x_eq_5.prop", - false, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/counter5.xsts", "src/test/resources/property/x_eq_5.prop", - false, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/x_and_y.xsts", "src/test/resources/property/x_geq_y.prop", - true, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/x_powers.xsts", "src/test/resources/property/x_even.prop", - true, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/cross_with.xsts", "src/test/resources/property/cross.prop", - false, XstsConfigBuilder.Domain.PRED_CART}, - -// { "src/test/resources/model/cross_with.xsts", "src/test/resources/property/cross.prop", false, XstsConfigBuilder.Domain.EXPL}, - -// { "src/test/resources/model/cross_with.xsts", "src/test/resources/property/cross.prop", false, XstsConfigBuilder.Domain.PROD}, - - {"src/test/resources/model/cross_without.xsts", - "src/test/resources/property/cross.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - -// { "src/test/resources/model/cross_without.xsts", "src/test/resources/property/cross.prop", false, XstsConfigBuilder.Domain.EXPL}, - -// { "src/test/resources/model/cross_without.xsts", "src/test/resources/property/cross.prop", false, XstsConfigBuilder.Domain.PROD}, - - {"src/test/resources/model/choices.xsts", "src/test/resources/property/choices.prop", - false, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/choices.xsts", "src/test/resources/property/choices.prop", - false, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/choices.xsts", "src/test/resources/property/choices.prop", - false, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/literals.xsts", "src/test/resources/property/literals.prop", - false, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/literals.xsts", "src/test/resources/property/literals.prop", - false, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/literals.xsts", "src/test/resources/property/literals.prop", - false, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/cross3.xsts", "src/test/resources/property/cross.prop", - false, XstsConfigBuilder.Domain.PRED_CART}, - -// { "src/test/resources/model/cross3.xsts", "src/test/resources/property/cross.prop", false, XstsConfigBuilder.Domain.EXPL}, - -// { "src/test/resources/model/cross3.xsts", "src/test/resources/property/cross.prop", false, XstsConfigBuilder.Domain.PROD}, - - {"src/test/resources/model/sequential.xsts", - "src/test/resources/property/sequential.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/sequential.xsts", - "src/test/resources/property/sequential.prop", true, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/sequential.xsts", - "src/test/resources/property/sequential.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/sequential.xsts", - "src/test/resources/property/sequential2.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/sequential.xsts", - "src/test/resources/property/sequential2.prop", false, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/sequential.xsts", - "src/test/resources/property/sequential2.prop", false, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine.prop", false, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine.prop", false, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine2.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine2.prop", true, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine2.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine3.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine3.prop", false, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/on_off_statemachine.xsts", - "src/test/resources/property/on_off_statemachine3.prop", false, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_5.prop", - false, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_5.prop", - false, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_5.prop", - false, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - -// { "src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_50.prop", false, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_50.prop", - false, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_50.prop", - false, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_51.prop", - true, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_51.prop", - true, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/counter50.xsts", "src/test/resources/property/x_eq_51.prop", - true, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/count_up_down.xsts", - "src/test/resources/property/count_up_down.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/count_up_down.xsts", - "src/test/resources/property/count_up_down.prop", false, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/count_up_down.xsts", - "src/test/resources/property/count_up_down.prop", false, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/count_up_down.xsts", - "src/test/resources/property/count_up_down2.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/count_up_down.xsts", - "src/test/resources/property/count_up_down2.prop", true, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/count_up_down.xsts", - "src/test/resources/property/count_up_down2.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/bhmr2007.xsts", "src/test/resources/property/bhmr2007.prop", - true, XstsConfigBuilder.Domain.PRED_CART}, - -// { "src/test/resources/model/bhmr2007.xsts", "src/test/resources/property/bhmr2007.prop", true, XstsConfigBuilder.Domain.EXPL}, - -// { "src/test/resources/model/bhmr2007.xsts", "src/test/resources/property/bhmr2007.prop", true, XstsConfigBuilder.Domain.PROD}, - - {"src/test/resources/model/css2003.xsts", "src/test/resources/property/css2003.prop", - true, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/css2003.xsts", "src/test/resources/property/css2003.prop", - true, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/css2003.xsts", "src/test/resources/property/css2003.prop", - true, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - -// { "src/test/resources/model/ort.xsts", "src/test/resources/property/x_gt_2.prop", false, XstsConfigBuilder.Domain.PRED_CART}, - -// { "src/test/resources/model/ort2.xsts", "src/test/resources/property/ort2.prop", true, XstsConfigBuilder.Domain.PRED_CART}, - -// { "src/test/resources/model/crossroad_composite.xsts", "src/test/resources/property/both_green.prop", true, XstsConfigBuilder.Domain.EXPL} - - {"src/test/resources/model/array_counter.xsts", - "src/test/resources/property/array_10.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/array_counter.xsts", - "src/test/resources/property/array_10.prop", false, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/array_counter.xsts", - "src/test/resources/property/array_10.prop", false, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/array_constant.xsts", - "src/test/resources/property/array_constant.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/array_constant.xsts", - "src/test/resources/property/array_constant.prop", true, - XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/array_constant.xsts", - "src/test/resources/property/array_constant.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/localvars.xsts", - "src/test/resources/property/localvars.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/localvars.xsts", - "src/test/resources/property/localvars.prop", true, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/localvars.xsts", - "src/test/resources/property/localvars.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/localvars2.xsts", - "src/test/resources/property/localvars2.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/localvars2.xsts", - "src/test/resources/property/localvars2.prop", true, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/localvars2.xsts", - "src/test/resources/property/localvars2.prop", true, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/loopxy.xsts", "src/test/resources/property/loopxy.prop", - true, XstsConfigBuilder.Domain.EXPL}, - - {"src/test/resources/model/loopxy.xsts", "src/test/resources/property/loopxy.prop", - true, XstsConfigBuilder.Domain.EXPL_PRED_COMBINED}, - - {"src/test/resources/model/loopxy.xsts", "src/test/resources/property/loopxy.prop", - true, XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/arraywrite_sugar.xsts", - "src/test/resources/property/arraywrite_sugar.prop", false, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/if1.xsts", "src/test/resources/property/if1.prop", true, - XstsConfigBuilder.Domain.PRED_CART}, - - {"src/test/resources/model/if2.xsts", "src/test/resources/property/if2.prop", false, - XstsConfigBuilder.Domain.EXPL_PRED_COMBINED} - }); + return Arrays.asList( + new Object[][] { + { + "src/test/resources/model/trafficlight.xsts", + "src/test/resources/property/green_and_red.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/trafficlight.xsts", + "src/test/resources/property/green_and_red.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/trafficlight.xsts", + "src/test/resources/property/green_and_red.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/trafficlight_v2.xsts", + "src/test/resources/property/green_and_red.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/trafficlight_v2.xsts", + "src/test/resources/property/green_and_red.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/trafficlight_v2.xsts", + "src/test/resources/property/green_and_red.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/counter5.xsts", + "src/test/resources/property/x_between_0_and_5.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/counter5.xsts", + "src/test/resources/property/x_between_0_and_5.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/counter5.xsts", + "src/test/resources/property/x_between_0_and_5.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/counter5.xsts", + "src/test/resources/property/x_eq_5.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/counter5.xsts", + "src/test/resources/property/x_eq_5.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/counter5.xsts", + "src/test/resources/property/x_eq_5.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/x_and_y.xsts", + "src/test/resources/property/x_geq_y.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/x_powers.xsts", + "src/test/resources/property/x_even.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/cross_with.xsts", + "src/test/resources/property/cross.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + + // { "src/test/resources/model/cross_with.xsts", + // "src/test/resources/property/cross.prop", false, + // XstsConfigBuilder.Domain.EXPL}, + + // { "src/test/resources/model/cross_with.xsts", + // "src/test/resources/property/cross.prop", false, + // XstsConfigBuilder.Domain.PROD}, + + { + "src/test/resources/model/cross_without.xsts", + "src/test/resources/property/cross.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + + // { "src/test/resources/model/cross_without.xsts", + // "src/test/resources/property/cross.prop", false, + // XstsConfigBuilder.Domain.EXPL}, + + // { "src/test/resources/model/cross_without.xsts", + // "src/test/resources/property/cross.prop", false, + // XstsConfigBuilder.Domain.PROD}, + + { + "src/test/resources/model/choices.xsts", + "src/test/resources/property/choices.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/choices.xsts", + "src/test/resources/property/choices.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/choices.xsts", + "src/test/resources/property/choices.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/literals.xsts", + "src/test/resources/property/literals.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/literals.xsts", + "src/test/resources/property/literals.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/literals.xsts", + "src/test/resources/property/literals.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/cross3.xsts", + "src/test/resources/property/cross.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + + // { "src/test/resources/model/cross3.xsts", + // "src/test/resources/property/cross.prop", false, + // XstsConfigBuilder.Domain.EXPL}, + + // { "src/test/resources/model/cross3.xsts", + // "src/test/resources/property/cross.prop", false, + // XstsConfigBuilder.Domain.PROD}, + + { + "src/test/resources/model/sequential.xsts", + "src/test/resources/property/sequential.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/sequential.xsts", + "src/test/resources/property/sequential.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/sequential.xsts", + "src/test/resources/property/sequential.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/sequential.xsts", + "src/test/resources/property/sequential2.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/sequential.xsts", + "src/test/resources/property/sequential2.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/sequential.xsts", + "src/test/resources/property/sequential2.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine2.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine2.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine2.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine3.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine3.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/on_off_statemachine.xsts", + "src/test/resources/property/on_off_statemachine3.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_5.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_5.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_5.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + + // { "src/test/resources/model/counter50.xsts", + // "src/test/resources/property/x_eq_50.prop", false, + // XstsConfigBuilder.Domain.PRED_CART}, + + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_50.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_50.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_51.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_51.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/counter50.xsts", + "src/test/resources/property/x_eq_51.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/count_up_down.xsts", + "src/test/resources/property/count_up_down.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/count_up_down.xsts", + "src/test/resources/property/count_up_down.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/count_up_down.xsts", + "src/test/resources/property/count_up_down.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/count_up_down.xsts", + "src/test/resources/property/count_up_down2.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/count_up_down.xsts", + "src/test/resources/property/count_up_down2.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/count_up_down.xsts", + "src/test/resources/property/count_up_down2.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/bhmr2007.xsts", + "src/test/resources/property/bhmr2007.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + + // { "src/test/resources/model/bhmr2007.xsts", + // "src/test/resources/property/bhmr2007.prop", true, + // XstsConfigBuilder.Domain.EXPL}, + + // { "src/test/resources/model/bhmr2007.xsts", + // "src/test/resources/property/bhmr2007.prop", true, + // XstsConfigBuilder.Domain.PROD}, + + { + "src/test/resources/model/css2003.xsts", + "src/test/resources/property/css2003.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/css2003.xsts", + "src/test/resources/property/css2003.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/css2003.xsts", + "src/test/resources/property/css2003.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + + // { "src/test/resources/model/ort.xsts", + // "src/test/resources/property/x_gt_2.prop", false, + // XstsConfigBuilder.Domain.PRED_CART}, + + // { "src/test/resources/model/ort2.xsts", + // "src/test/resources/property/ort2.prop", true, + // XstsConfigBuilder.Domain.PRED_CART}, + + // { "src/test/resources/model/crossroad_composite.xsts", + // "src/test/resources/property/both_green.prop", true, + // XstsConfigBuilder.Domain.EXPL} + + { + "src/test/resources/model/array_counter.xsts", + "src/test/resources/property/array_10.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/array_counter.xsts", + "src/test/resources/property/array_10.prop", + false, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/array_counter.xsts", + "src/test/resources/property/array_10.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/array_constant.xsts", + "src/test/resources/property/array_constant.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/array_constant.xsts", + "src/test/resources/property/array_constant.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/array_constant.xsts", + "src/test/resources/property/array_constant.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/localvars.xsts", + "src/test/resources/property/localvars.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/localvars.xsts", + "src/test/resources/property/localvars.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/localvars.xsts", + "src/test/resources/property/localvars.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/localvars2.xsts", + "src/test/resources/property/localvars2.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/localvars2.xsts", + "src/test/resources/property/localvars2.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/localvars2.xsts", + "src/test/resources/property/localvars2.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/loopxy.xsts", + "src/test/resources/property/loopxy.prop", + true, + XstsConfigBuilder.Domain.EXPL + }, + { + "src/test/resources/model/loopxy.xsts", + "src/test/resources/property/loopxy.prop", + true, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + }, + { + "src/test/resources/model/loopxy.xsts", + "src/test/resources/property/loopxy.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/arraywrite_sugar.xsts", + "src/test/resources/property/arraywrite_sugar.prop", + false, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/if1.xsts", + "src/test/resources/property/if1.prop", + true, + XstsConfigBuilder.Domain.PRED_CART + }, + { + "src/test/resources/model/if2.xsts", + "src/test/resources/property/if2.prop", + false, + XstsConfigBuilder.Domain.EXPL_PRED_COMBINED + } + }); } @BeforeClass @@ -357,10 +569,16 @@ public static void installSolver() { if (SOLVER_STRING.contains("Z3") || SOLVER_STRING.contains("JavaSMT")) { return; } - try (final var solverManager = SmtLibSolverManager.create(SMTLIB_HOME, new ConsoleLogger(Level.DETAIL))) { + try (final var solverManager = + SmtLibSolverManager.create(SMTLIB_HOME, new ConsoleLogger(Level.DETAIL))) { String solverVersion = SmtLibSolverManager.getSolverVersion(SOLVER_STRING); String solverName = SmtLibSolverManager.getSolverName(SOLVER_STRING); - if (solverManager.managesSolver(SOLVER_STRING) && !solverManager.getInstalledVersions(solverName).contains(solverManager.getVersionString(solverName, solverVersion, false))) { + if (solverManager.managesSolver(SOLVER_STRING) + && !solverManager + .getInstalledVersions(solverName) + .contains( + solverManager.getVersionString( + solverName, solverVersion, false))) { solverManager.install(solverName, solverVersion, solverVersion, null, false); } } catch (Exception e) { @@ -371,7 +589,8 @@ public static void installSolver() { @Test public void test() throws Exception { final Logger logger = new ConsoleLogger(Level.SUBSTEP); - SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3legacy.Z3SolverManager.create()); + SolverManager.registerSolverManager( + hu.bme.mit.theta.solver.z3legacy.Z3SolverManager.create()); SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3.Z3SolverManager.create()); SolverManager.registerSolverManager(SmtLibSolverManager.create(SMTLIB_HOME, logger)); SolverManager.registerSolverManager(JavaSMTSolverManager.create()); @@ -385,18 +604,26 @@ public void test() throws Exception { } XSTS xsts; - try (InputStream inputStream = new SequenceInputStream(new FileInputStream(filePath), - new FileInputStream(propPath))) { + try (InputStream inputStream = + new SequenceInputStream( + new FileInputStream(filePath), new FileInputStream(propPath))) { xsts = XstsDslManager.createXsts(inputStream); } try { - final XstsConfig configuration = new XstsConfigBuilder(domain, - XstsConfigBuilder.Refinement.SEQ_ITP, solverFactory, - solverFactory).initPrec(XstsConfigBuilder.InitPrec.CTRL) - .optimizeStmts(XstsConfigBuilder.OptimizeStmts.ON) - .predSplit(XstsConfigBuilder.PredSplit.CONJUNCTS).maxEnum(250) - .autoExpl(XstsConfigBuilder.AutoExpl.NEWOPERANDS).logger(logger).build(xsts); + final XstsConfig configuration = + new XstsConfigBuilder( + domain, + XstsConfigBuilder.Refinement.SEQ_ITP, + solverFactory, + solverFactory) + .initPrec(XstsConfigBuilder.InitPrec.CTRL) + .optimizeStmts(XstsConfigBuilder.OptimizeStmts.ON) + .predSplit(XstsConfigBuilder.PredSplit.CONJUNCTS) + .maxEnum(250) + .autoExpl(XstsConfigBuilder.AutoExpl.NEWOPERANDS) + .logger(logger) + .build(xsts); final SafetyResult status = configuration.check(); if (safe) { @@ -408,5 +635,4 @@ public void test() throws Exception { SolverManager.closeAll(); } } - } diff --git a/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/ChcUtils.kt b/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/ChcUtils.kt index 7fe5dbe07b..10358f770c 100644 --- a/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/ChcUtils.kt +++ b/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/ChcUtils.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.analysis.util import hu.bme.mit.theta.core.Relation @@ -21,12 +20,16 @@ import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibSymbolTable import hu.bme.mit.theta.solver.smtlib.impl.generic.GenericSmtLibTransformationManager fun List.toSMT2(): String { - val symbolTable = GenericSmtLibSymbolTable() - val transformationManager = GenericSmtLibTransformationManager(symbolTable) - val terms = flatMap { it.rules.map { "(assert " + transformationManager.toTerm(it.toExpr()) + ")" } } - val decls = filter { symbolTable.definesConst(it.constDecl) }.map { symbolTable.getDeclaration(it.constDecl) } - - return """ + val symbolTable = GenericSmtLibSymbolTable() + val transformationManager = GenericSmtLibTransformationManager(symbolTable) + val terms = flatMap { + it.rules.map { "(assert " + transformationManager.toTerm(it.toExpr()) + ")" } + } + val decls = + filter { symbolTable.definesConst(it.constDecl) } + .map { symbolTable.getDeclaration(it.constDecl) } + + return """ ; generated by Theta ; https://github.com/ftsrg/theta/ @@ -40,7 +43,8 @@ ${terms.joinToString("\n")} (check-sat) (exit) -""".trimIndent() +""" + .trimIndent() } -fun Relation.toSMT2() = listOf(this).toSMT2() \ No newline at end of file +fun Relation.toSMT2() = listOf(this).toSMT2() diff --git a/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtilsUnitTest.kt b/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtilsUnitTest.kt index 1f9b0a3d7e..4a2ddb7e58 100644 --- a/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtilsUnitTest.kt +++ b/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsCombineExtractUtilsUnitTest.kt @@ -1,17 +1,18 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. + * 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.xsts.analysis.util import hu.bme.mit.theta.analysis.pred.PredState @@ -22,15 +23,15 @@ import org.junit.jupiter.api.Test class XstsCombineExtractUtilsUnitTest { - val dataState = PredState.of() - val controlState = XstsState.of(UnitState.getInstance(), true, false) - val xstsState = XstsState.of(dataState, true, false) + val dataState = PredState.of() + val controlState = XstsState.of(UnitState.getInstance(), true, false) + val xstsState = XstsState.of(dataState, true, false) - @Test - fun `Utils work as expected`() { - assert(xstsCombineStates(controlState, dataState) == xstsState) - assert(xstsExtractControlState(xstsState) == controlState) - assert(xstsExtractDataState(xstsState) == dataState) - assert(xstsExtractControlPrec(UnitPrec.getInstance()) == UnitPrec.getInstance()) - } -} \ No newline at end of file + @Test + fun `Utils work as expected`() { + assert(xstsCombineStates(controlState, dataState) == xstsState) + assert(xstsExtractControlState(xstsState) == controlState) + assert(xstsExtractDataState(xstsState) == dataState) + assert(xstsExtractControlPrec(UnitPrec.getInstance()) == UnitPrec.getInstance()) + } +} diff --git a/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFuncUnitTest.kt b/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFuncUnitTest.kt index 81271e3953..2b49e6071c 100644 --- a/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFuncUnitTest.kt +++ b/subprojects/xsts/xsts-analysis/src/test/kotlin/hu/bme/mit/theta/xsts/analysis/util/XstsControlInitFuncUnitTest.kt @@ -1,17 +1,18 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. + * 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.xsts.analysis.util import hu.bme.mit.theta.analysis.expl.ExplPrec @@ -20,11 +21,11 @@ import org.junit.jupiter.api.Test class XstsControlInitFuncUnitTest { - @Test - fun `Returns single unitstate`() { - val result = xstsControlInitFunc().getInitStates(ExplPrec.empty()) + @Test + fun `Returns single unitstate`() { + val result = xstsControlInitFunc().getInitStates(ExplPrec.empty()) - assert(result.size == 1) - assert(result.single().state == UnitState.getInstance()) - } -} \ No newline at end of file + assert(result.size == 1) + assert(result.single().state == UnitState.getInstance()) + } +} diff --git a/subprojects/xsts/xsts-cli/build.gradle.kts b/subprojects/xsts/xsts-cli/build.gradle.kts index 209b728b48..7d7aa6b1e3 100644 --- a/subprojects/xsts/xsts-cli/build.gradle.kts +++ b/subprojects/xsts/xsts-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBaseCommand.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBaseCommand.kt index 90c2af692e..0b2defa3e0 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBaseCommand.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBaseCommand.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli import com.github.ajalt.clikt.core.CliktCommand @@ -25,8 +24,6 @@ import com.github.ajalt.clikt.parameters.options.versionOption import com.github.ajalt.clikt.parameters.types.file import hu.bme.mit.theta.analysis.Trace import hu.bme.mit.theta.analysis.algorithm.SafetyResult -import hu.bme.mit.theta.analysis.algorithm.arg.ARG -import hu.bme.mit.theta.analysis.algorithm.cegar.CegarStatistics import hu.bme.mit.theta.common.logging.ConsoleLogger import hu.bme.mit.theta.common.logging.Logger import hu.bme.mit.theta.common.logging.NullLogger @@ -44,62 +41,63 @@ import java.io.File import java.io.PrintWriter abstract class XstsCliBaseCommand(name: String? = null, help: String = "") : - CliktCommand(name = name, help = help, printHelpOnEmptyArgs = true) { + CliktCommand(name = name, help = help, printHelpOnEmptyArgs = true) { - init { - versionOption(javaClass.`package`.implementationVersion ?: "unknown") - } + init { + versionOption(javaClass.`package`.implementationVersion ?: "unknown") + } - protected val inputOptions by InputOptions() - protected val outputOptions by OutputOptions() - protected open val defaultSolver: String = "Z3" - protected val solver: String by option(help = "The solver to use for the check").defaultLazy { defaultSolver } - private val smtHome: File by option().file().default(SmtLibSolverManager.HOME.toFile()) - protected val logger: Logger by lazy { - if (outputOptions.benchmarkMode) NullLogger.getInstance() else ConsoleLogger(outputOptions.logLevel) - } - protected val writer = BasicTableWriter(System.out, ",", "\"", "\"") + protected val inputOptions by InputOptions() + protected val outputOptions by OutputOptions() + protected open val defaultSolver: String = "Z3" + protected val solver: String by + option(help = "The solver to use for the check").defaultLazy { defaultSolver } + private val smtHome: File by option().file().default(SmtLibSolverManager.HOME.toFile()) + protected val logger: Logger by lazy { + if (outputOptions.benchmarkMode) NullLogger.getInstance() + else ConsoleLogger(outputOptions.logLevel) + } + protected val writer = BasicTableWriter(System.out, ",", "\"", "\"") - fun printError(exception: Exception) { - val message = exception.message ?: "" - val exceptionName = exception.javaClass.simpleName - if (outputOptions.benchmarkMode) { - writer.cell("[EX] $exceptionName: $message") - writer.newRow() - return - } - logger.write(Logger.Level.RESULT, "%s occurred, message: %s%n", exceptionName, message) - if (outputOptions.stacktrace) { - logger.write(Logger.Level.RESULT, "Trace:%n%s%n", exception.stackTraceToString()) - } else { - logger.write(Logger.Level.RESULT, "Use --stacktrace for stack trace%n") - } + fun printError(exception: Exception) { + val message = exception.message ?: "" + val exceptionName = exception.javaClass.simpleName + if (outputOptions.benchmarkMode) { + writer.cell("[EX] $exceptionName: $message") + writer.newRow() + return } - - fun printCommonResult(status: SafetyResult<*, *>, xsts: XSTS, totalTimeMs: Long) { - listOf( - status.isSafe, - totalTimeMs, - if (status.isUnsafe) "${status.asUnsafe().cex?.length() ?: "N/A"}" else "", - xsts.vars.size, - ).forEach(writer::cell) + logger.write(Logger.Level.RESULT, "%s occurred, message: %s%n", exceptionName, message) + if (outputOptions.stacktrace) { + logger.write(Logger.Level.RESULT, "Trace:%n%s%n", exception.stackTraceToString()) + } else { + logger.write(Logger.Level.RESULT, "Use --stacktrace for stack trace%n") } + } - fun registerSolverManagers() { - SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3.Z3SolverManager.create()) - SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3legacy.Z3SolverManager.create()) - SolverManager.registerSolverManager(SmtLibSolverManager.create(smtHome.toPath(), logger)) - SolverManager.registerSolverManager(JavaSMTSolverManager.create()) - } + fun printCommonResult(status: SafetyResult<*, *>, xsts: XSTS, totalTimeMs: Long) { + listOf( + status.isSafe, + totalTimeMs, + if (status.isUnsafe) "${status.asUnsafe().cex?.length() ?: "N/A"}" else "", + xsts.vars.size, + ) + .forEach(writer::cell) + } - protected fun writeCex(status: SafetyResult<*, *>, xsts: XSTS) { - if (outputOptions.cexfile == null || status.isSafe) return - val trace = status.asUnsafe().cex as Trace, XstsAction> - val concreteTrace = - XstsTraceConcretizerUtil.concretize(trace, SolverManager.resolveSolverFactory(solver), xsts) - val file: File = outputOptions.cexfile!! - PrintWriter(file).use { printWriter -> - printWriter.write(concreteTrace.toString()) - } - } + fun registerSolverManagers() { + SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3.Z3SolverManager.create()) + SolverManager.registerSolverManager(hu.bme.mit.theta.solver.z3legacy.Z3SolverManager.create()) + SolverManager.registerSolverManager(SmtLibSolverManager.create(smtHome.toPath(), logger)) + SolverManager.registerSolverManager(JavaSMTSolverManager.create()) + } + + protected fun writeCex(status: SafetyResult<*, *>, xsts: XSTS) { + if (outputOptions.cexfile == null || status.isSafe) return + val trace = status.asUnsafe().cex as Trace, XstsAction> + val concreteTrace = + XstsTraceConcretizerUtil.concretize(trace, SolverManager.resolveSolverFactory(solver), xsts) + val file: File = outputOptions.cexfile!! + PrintWriter(file).use { printWriter -> printWriter.write(concreteTrace.toString()) } + } } diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBounded.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBounded.kt index 7df23a5d53..b6ee960a00 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBounded.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliBounded.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliCegar.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliCegar.kt index ade34d7127..30f2145a44 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliCegar.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliCegar.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliChc.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliChc.kt index 1feb10ec45..3e286f3372 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliChc.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliChc.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli -import com.github.ajalt.clikt.parameters.options.default -import com.github.ajalt.clikt.parameters.options.option import com.google.common.base.Stopwatch import hu.bme.mit.theta.analysis.algorithm.SafetyResult import hu.bme.mit.theta.analysis.algorithm.chc.CexTree @@ -29,42 +26,34 @@ import hu.bme.mit.theta.xsts.analysis.toRelations import java.util.concurrent.TimeUnit import kotlin.system.exitProcess +class XstsCliChc : + XstsCliBaseCommand(name = "CHC", help = "Model checking using the Horn solving backend") { -class XstsCliChc : XstsCliBaseCommand( - name = "CHC", - help = "Model checking using the Horn solving backend" -) { - - override val defaultSolver: String = "z3:4.13.0" - - private fun printResult(status: SafetyResult, xsts: XSTS, totalTimeMs: Long) { - if (!outputOptions.benchmarkMode) return - printCommonResult(status, xsts, totalTimeMs) - writer.newRow() - } + override val defaultSolver: String = "z3:4.13.0" - override fun run() { - try { - doRun() - } catch (e: Exception) { - printError(e) - exitProcess(1) - } - } + private fun printResult(status: SafetyResult, xsts: XSTS, totalTimeMs: Long) { + if (!outputOptions.benchmarkMode) return + printCommonResult(status, xsts, totalTimeMs) + writer.newRow() + } - private fun doRun() { - registerSolverManagers() - val solverFactory = SolverManager.resolveSolverFactory(solver) - val xsts = inputOptions.loadXsts() - val sw = Stopwatch.createStarted() - val checker = HornChecker( - xsts.toRelations(), - solverFactory, - logger - ) - val result = checker.check() - sw.stop() - printResult(result, xsts, sw.elapsed(TimeUnit.MILLISECONDS)) + override fun run() { + try { + doRun() + } catch (e: Exception) { + printError(e) + exitProcess(1) } - -} \ No newline at end of file + } + + private fun doRun() { + registerSolverManagers() + val solverFactory = SolverManager.resolveSolverFactory(solver) + val xsts = inputOptions.loadXsts() + val sw = Stopwatch.createStarted() + val checker = HornChecker(xsts.toRelations(), solverFactory, logger) + val result = checker.check() + sw.stop() + printResult(result, xsts, sw.elapsed(TimeUnit.MILLISECONDS)) + } +} diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliHeader.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliHeader.kt index f5e7d0575d..4248765abc 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliHeader.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliHeader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli import com.github.ajalt.clikt.core.CliktCommand @@ -26,91 +25,97 @@ import hu.bme.mit.theta.common.table.BasicTableWriter class XstsCliHeader : CliktCommand(name = "header") { - private val writer = BasicTableWriter(System.out, ",", "\"", "\"") + private val writer = BasicTableWriter(System.out, ",", "\"", "\"") - enum class Algorithm { CEGAR, MDD, BOUNDED, PN_MDD, CHC } + enum class Algorithm { + CEGAR, + MDD, + BOUNDED, + PN_MDD, + CHC, + } - private val algorithm: Algorithm by option( - help = "The algorithm to print the header for" - ).enum().required() - private val iterationStrategy: MddChecker.IterationStrategy by option( - help = "The state space generation algorithm for symbolic checking" - ).enum().default(MddChecker.IterationStrategy.GSAT) + private val algorithm: Algorithm by + option(help = "The algorithm to print the header for").enum().required() + private val iterationStrategy: MddChecker.IterationStrategy by + option(help = "The state space generation algorithm for symbolic checking") + .enum() + .default(MddChecker.IterationStrategy.GSAT) - override fun run() { - when (algorithm) { - Algorithm.CEGAR -> printCegarHeader() - Algorithm.BOUNDED -> printBoundedHeader() - Algorithm.MDD -> printMddHeader() - Algorithm.PN_MDD -> printSymbolicHeader() - Algorithm.CHC -> printChcHeader() - } + override fun run() { + when (algorithm) { + Algorithm.CEGAR -> printCegarHeader() + Algorithm.BOUNDED -> printBoundedHeader() + Algorithm.MDD -> printMddHeader() + Algorithm.PN_MDD -> printSymbolicHeader() + Algorithm.CHC -> printChcHeader() } + } - private fun printCommonHeader() { - listOf( - "Result", "TimeMs", "CexLen", "Vars" - ).forEach(writer::cell) - } + private fun printCommonHeader() { + listOf("Result", "TimeMs", "CexLen", "Vars").forEach(writer::cell) + } - private fun printCegarHeader() { - printCommonHeader() - listOf( - "AlgoTimeMs", "AbsTimeMs", "RefTimeMs", "Iterations", - "ArgSize", "ArgDepth", "ArgMeanBranchFactor" - ).forEach(writer::cell) - writer.newRow() - } + private fun printCegarHeader() { + printCommonHeader() + listOf( + "AlgoTimeMs", + "AbsTimeMs", + "RefTimeMs", + "Iterations", + "ArgSize", + "ArgDepth", + "ArgMeanBranchFactor", + ) + .forEach(writer::cell) + writer.newRow() + } - private fun printBoundedHeader() { - printCommonHeader() - listOf( - "Iterations", - ).forEach(writer::cell) - writer.newRow() - } + private fun printBoundedHeader() { + printCommonHeader() + listOf("Iterations").forEach(writer::cell) + writer.newRow() + } - private fun printMddHeader() { - printCommonHeader() - listOf( - "ViolatingSize", "StateSpaceSize", "HitCount", "QueryCount", "CacheSize", - ).forEach(writer::cell) - writer.newRow() - } + private fun printMddHeader() { + printCommonHeader() + listOf("ViolatingSize", "StateSpaceSize", "HitCount", "QueryCount", "CacheSize") + .forEach(writer::cell) + writer.newRow() + } - private fun printChcHeader() { - printCommonHeader() - writer.newRow() - } + private fun printChcHeader() { + printCommonHeader() + writer.newRow() + } - private fun printSymbolicHeader() { - listOf( - "id", - "modelPath", - "modelName", - "stateSpaceSize", - "finalMddSize", - "totalTimeUs", - "ssgTimeUs", - "nodeCount", - "unionCacheSize", - "unionQueryCount", - "unionHitCount", - ).forEach(writer::cell) - if (iterationStrategy in setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT)) { - listOf( - "saturateCacheSize", - "saturateQueryCount", - "saturateHitCount" - ).forEach(writer::cell) - } - listOf( - "relProdCacheSize", - "relProdQueryCount", - "relProdHitCount", - ).forEach(writer::cell) - if (iterationStrategy in setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT)) { - listOf("saturatedNodeCount").forEach(writer::cell) - } + private fun printSymbolicHeader() { + listOf( + "id", + "modelPath", + "modelName", + "stateSpaceSize", + "finalMddSize", + "totalTimeUs", + "ssgTimeUs", + "nodeCount", + "unionCacheSize", + "unionQueryCount", + "unionHitCount", + ) + .forEach(writer::cell) + if ( + iterationStrategy in + setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT) + ) { + listOf("saturateCacheSize", "saturateQueryCount", "saturateHitCount").forEach(writer::cell) + } + listOf("relProdCacheSize", "relProdQueryCount", "relProdHitCount").forEach(writer::cell) + if ( + iterationStrategy in + setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT) + ) { + listOf("saturatedNodeCount").forEach(writer::cell) } -} \ No newline at end of file + } +} diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliLtlCegar.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliLtlCegar.kt index 49aa4cffce..6fb067bf9f 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliLtlCegar.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliLtlCegar.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMain.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMain.kt index 2f49876547..24a82ce234 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMain.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMain.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMdd.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMdd.kt index f64094d0a8..6aa3011285 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMdd.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMdd.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMetrics.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMetrics.kt index 33a2af151a..183e3493b1 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMetrics.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliMetrics.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli import com.github.ajalt.clikt.core.CliktCommand @@ -30,40 +29,47 @@ import hu.bme.mit.theta.xsts.cli.optiongroup.InputOptions class XstsCliMetrics : CliktCommand(name = "metrics") { - private val inputOptions by InputOptions() + private val inputOptions by InputOptions() - override fun run() { - val logger = ConsoleLogger(Logger.Level.VERBOSE) - val xsts = inputOptions.loadXsts() - logger.write(Logger.Level.RESULT, "Vars: %s%n", xsts.vars.size) - logger.write( - Logger.Level.RESULT, " Bool vars: %s%n", - xsts.vars.stream().filter { v: VarDecl<*> -> v.type is BoolType }.count() - ) - logger.write( - Logger.Level.RESULT, " Int vars: %s%n", - xsts.vars.stream().filter { v: VarDecl<*> -> v.type is IntType }.count() - ) - logger.write( - Logger.Level.RESULT, " Bitvector vars: %s%n", - xsts.vars.stream().filter { v: VarDecl<*> -> v.type is BvType }.count() - ) - logger.write( - Logger.Level.RESULT, " Array vars: %s%n", - xsts.vars.stream().filter { v: VarDecl<*> -> v.type is ArrayType<*, *> }.count() - ) - logger.write(Logger.Level.RESULT, " Ctrl vars: %s%n", xsts.ctrlVars.size) - logger.write( - Logger.Level.RESULT, "Tran statements: %s%n", - xsts.tran.accept(StmtCounterVisitor.getInstance(), null) - ) - logger.write( - Logger.Level.RESULT, "Env statements: %s%n", - xsts.env.accept(StmtCounterVisitor.getInstance(), null) - ) - logger.write( - Logger.Level.RESULT, "Init statements: %s%n", - xsts.init.accept(StmtCounterVisitor.getInstance(), null) - ) - } -} \ No newline at end of file + override fun run() { + val logger = ConsoleLogger(Logger.Level.VERBOSE) + val xsts = inputOptions.loadXsts() + logger.write(Logger.Level.RESULT, "Vars: %s%n", xsts.vars.size) + logger.write( + Logger.Level.RESULT, + " Bool vars: %s%n", + xsts.vars.stream().filter { v: VarDecl<*> -> v.type is BoolType }.count(), + ) + logger.write( + Logger.Level.RESULT, + " Int vars: %s%n", + xsts.vars.stream().filter { v: VarDecl<*> -> v.type is IntType }.count(), + ) + logger.write( + Logger.Level.RESULT, + " Bitvector vars: %s%n", + xsts.vars.stream().filter { v: VarDecl<*> -> v.type is BvType }.count(), + ) + logger.write( + Logger.Level.RESULT, + " Array vars: %s%n", + xsts.vars.stream().filter { v: VarDecl<*> -> v.type is ArrayType<*, *> }.count(), + ) + logger.write(Logger.Level.RESULT, " Ctrl vars: %s%n", xsts.ctrlVars.size) + logger.write( + Logger.Level.RESULT, + "Tran statements: %s%n", + xsts.tran.accept(StmtCounterVisitor.getInstance(), null), + ) + logger.write( + Logger.Level.RESULT, + "Env statements: %s%n", + xsts.env.accept(StmtCounterVisitor.getInstance(), null), + ) + logger.write( + Logger.Level.RESULT, + "Init statements: %s%n", + xsts.init.accept(StmtCounterVisitor.getInstance(), null), + ) + } +} diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliPetrinetMdd.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliPetrinetMdd.kt index d0a2fa277e..c973c59419 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliPetrinetMdd.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/XstsCliPetrinetMdd.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli import com.github.ajalt.clikt.parameters.groups.provideDelegate @@ -44,131 +43,144 @@ import java.util.concurrent.TimeUnit import javax.imageio.ImageIO import kotlin.system.exitProcess -class XstsCliPetrinetMdd : XstsCliBaseCommand( - name = "PN_MDD", help = "Model checking of Petri nets using MDDs (Multi-value Decision Diagrams)" -) { +class XstsCliPetrinetMdd : + XstsCliBaseCommand( + name = "PN_MDD", + help = "Model checking of Petri nets using MDDs (Multi-value Decision Diagrams)", + ) { - private val ordering: File? by option(help = "Path of the input variable ordering").file( - mustExist = true, canBeDir = false, mustBeReadable = true - ) - private val id: String by option(help = "ID of the input model. Used for symbolic output").default("") - private val iterationStrategy: MddChecker.IterationStrategy by option( - help = "The state space generation algorithm to use" - ).enum().default(MddChecker.IterationStrategy.GSAT) - private val dependencyOutput by PetrinetDependencyOutputOptions() + private val ordering: File? by + option(help = "Path of the input variable ordering") + .file(mustExist = true, canBeDir = false, mustBeReadable = true) + private val id: String by + option(help = "ID of the input model. Used for symbolic output").default("") + private val iterationStrategy: MddChecker.IterationStrategy by + option(help = "The state space generation algorithm to use") + .enum() + .default(MddChecker.IterationStrategy.GSAT) + private val dependencyOutput by PetrinetDependencyOutputOptions() - private fun loadOrdering(petriNet: PetriNet): List = - if (ordering == null) petriNet.places.sortedWith { p1: Place, p2: Place -> - String.CASE_INSENSITIVE_ORDER.compare( - p1.id.reversed(), p2.id.reversed() - ) - } else VariableOrderingFactory.fromFile(ordering, petriNet) + private fun loadOrdering(petriNet: PetriNet): List = + if (ordering == null) + petriNet.places.sortedWith { p1: Place, p2: Place -> + String.CASE_INSENSITIVE_ORDER.compare(p1.id.reversed(), p2.id.reversed()) + } + else VariableOrderingFactory.fromFile(ordering, petriNet) - private fun petrinetAnalysis() { - val totalTimer = Stopwatch.createStarted() - val petriNet = inputOptions.loadPetriNet()[0] - val effectiveOrdering = loadOrdering(petriNet) - val system = PtNetSystem(petriNet, effectiveOrdering) - createDepGxl(system) - createDepGxlGSat(system) - createDepMat(system) - createDepMatPng(system) - val variableOrder = JavaMddFactory.getDefault().createMddVariableOrder(LatticeDefinition.forSets()) - effectiveOrdering.forEach { variableOrder.createOnTop(MddVariableDescriptor.create(it)) } - val ssgTimer = Stopwatch.createStarted() - val provider: StateSpaceEnumerationProvider = when (iterationStrategy) { - MddChecker.IterationStrategy.BFS -> BfsProvider(variableOrder) - MddChecker.IterationStrategy.SAT -> SimpleSaturationProvider(variableOrder) - MddChecker.IterationStrategy.GSAT -> GeneralizedSaturationProvider(variableOrder) - } - val stateSpace = provider.compute( - system.initializer, system.transitions, variableOrder.defaultSetSignature.topVariableHandle - ) - ssgTimer.stop() - totalTimer.stop() + private fun petrinetAnalysis() { + val totalTimer = Stopwatch.createStarted() + val petriNet = inputOptions.loadPetriNet()[0] + val effectiveOrdering = loadOrdering(petriNet) + val system = PtNetSystem(petriNet, effectiveOrdering) + createDepGxl(system) + createDepGxlGSat(system) + createDepMat(system) + createDepMatPng(system) + val variableOrder = + JavaMddFactory.getDefault().createMddVariableOrder(LatticeDefinition.forSets()) + effectiveOrdering.forEach { variableOrder.createOnTop(MddVariableDescriptor.create(it)) } + val ssgTimer = Stopwatch.createStarted() + val provider: StateSpaceEnumerationProvider = + when (iterationStrategy) { + MddChecker.IterationStrategy.BFS -> BfsProvider(variableOrder) + MddChecker.IterationStrategy.SAT -> SimpleSaturationProvider(variableOrder) + MddChecker.IterationStrategy.GSAT -> GeneralizedSaturationProvider(variableOrder) + } + val stateSpace = + provider.compute( + system.initializer, + system.transitions, + variableOrder.defaultSetSignature.topVariableHandle, + ) + ssgTimer.stop() + totalTimer.stop() - val unionProvider = variableOrder.defaultUnionProvider - listOf( - id, - inputOptions.model.path, - system.name, - MddInterpreter.calculateNonzeroCount(stateSpace), - numberOfNodes(stateSpace), - totalTimer.elapsed(TimeUnit.MICROSECONDS), - ssgTimer.elapsed(TimeUnit.MICROSECONDS), - variableOrder.mddGraph.uniqueTableSize, - unionProvider.cacheSize, - unionProvider.queryCount, - unionProvider.hitCount, - ).forEach(writer::cell) - if (iterationStrategy in setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT)) { - listOf( - provider.cacheSize, provider.queryCount, provider.hitCount - ).forEach(writer::cell) - } - listOf( - provider.cacheSize, provider.queryCount, provider.hitCount - ).forEach(writer::cell) - if (iterationStrategy in setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT)) { - val collector: MutableSet = mutableSetOf() - provider.clear() - listOf(collector.size).forEach(writer::cell) - } + val unionProvider = variableOrder.defaultUnionProvider + listOf( + id, + inputOptions.model.path, + system.name, + MddInterpreter.calculateNonzeroCount(stateSpace), + numberOfNodes(stateSpace), + totalTimer.elapsed(TimeUnit.MICROSECONDS), + ssgTimer.elapsed(TimeUnit.MICROSECONDS), + variableOrder.mddGraph.uniqueTableSize, + unionProvider.cacheSize, + unionProvider.queryCount, + unionProvider.hitCount, + ) + .forEach(writer::cell) + if ( + iterationStrategy in + setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT) + ) { + listOf(provider.cacheSize, provider.queryCount, provider.hitCount).forEach(writer::cell) } - - private fun createDepMatPng(system: PtNetSystem) { - if (dependencyOutput.depMatPng == null) return - if (system.placeCount > 10000 || system.transitionCount > 10000) { - logger.write( - Logger.Level.INFO, - "[WARNING] Skipping image generation because the model size exceeds 10k places or " + "transitions." - ) - return - } - ImageIO.write(system.dependencyMatrixImage(1), "PNG", dependencyOutput.depMatPng) + listOf(provider.cacheSize, provider.queryCount, provider.hitCount).forEach(writer::cell) + if ( + iterationStrategy in + setOf(MddChecker.IterationStrategy.GSAT, MddChecker.IterationStrategy.SAT) + ) { + val collector: MutableSet = mutableSetOf() + provider.clear() + listOf(collector.size).forEach(writer::cell) } + } - private fun createDepMat(system: PtNetSystem) { - val file = dependencyOutput.depMat ?: return - file.createNewFile() - with(PrintStream(file)) { print(system.printDependencyMatrixCsv()) } + private fun createDepMatPng(system: PtNetSystem) { + if (dependencyOutput.depMatPng == null) return + if (system.placeCount > 10000 || system.transitionCount > 10000) { + logger.write( + Logger.Level.INFO, + "[WARNING] Skipping image generation because the model size exceeds 10k places or " + + "transitions.", + ) + return } + ImageIO.write(system.dependencyMatrixImage(1), "PNG", dependencyOutput.depMatPng) + } - private fun createDepGxlGSat(system: PtNetSystem) { - val file = dependencyOutput.depGxlGsat ?: return - file.createNewFile() - with(PrintStream(file)) { print(PtNetDependency2Gxl.toGxl(system, true)) } - } + private fun createDepMat(system: PtNetSystem) { + val file = dependencyOutput.depMat ?: return + file.createNewFile() + with(PrintStream(file)) { print(system.printDependencyMatrixCsv()) } + } - private fun createDepGxl(system: PtNetSystem) { - val file = dependencyOutput.depGxl ?: return - file.createNewFile() - with(PrintStream(file)) { print(PtNetDependency2Gxl.toGxl(system, false)) } - } + private fun createDepGxlGSat(system: PtNetSystem) { + val file = dependencyOutput.depGxlGsat ?: return + file.createNewFile() + with(PrintStream(file)) { print(PtNetDependency2Gxl.toGxl(system, true)) } + } - override fun run() { - try { - if (inputOptions.isPnml()) petrinetAnalysis() - } catch (e: Exception) { - printError(e) - exitProcess(1) - } - } + private fun createDepGxl(system: PtNetSystem) { + val file = dependencyOutput.depGxl ?: return + file.createNewFile() + with(PrintStream(file)) { print(PtNetDependency2Gxl.toGxl(system, false)) } + } - private fun numberOfNodes(root: MddHandle): Int { - val result: MutableSet = mutableSetOf() - val stack = Stack() - stack.push(root.node) + override fun run() { + try { + if (inputOptions.isPnml()) petrinetAnalysis() + } catch (e: Exception) { + printError(e) + exitProcess(1) + } + } - while (stack.isNotEmpty()) { - val current = stack.pop() - if (!result.add(current) || current.isTerminal) continue - val cursor = current.cursor() - while (cursor.moveNext()) { - stack.push(cursor.value()) - } - } + private fun numberOfNodes(root: MddHandle): Int { + val result: MutableSet = mutableSetOf() + val stack = Stack() + stack.push(root.node) - return result.size + while (stack.isNotEmpty()) { + val current = stack.pop() + if (!result.add(current) || current.isTerminal) continue + val cursor = current.cursor() + while (cursor.moveNext()) { + stack.push(cursor.value()) + } } -} \ No newline at end of file + + return result.size + } +} diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/InputOptions.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/InputOptions.kt index 24c474808f..7882eabc5b 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/InputOptions.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/InputOptions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli.optiongroup import com.github.ajalt.clikt.parameters.groups.OptionGroup @@ -30,34 +29,39 @@ import hu.bme.mit.theta.xsts.XSTS import hu.bme.mit.theta.xsts.dsl.XstsDslManager import java.io.* -class InputOptions : OptionGroup( - name = "Input options", - help = "Options related to model and property input" -) { +class InputOptions : + OptionGroup(name = "Input options", help = "Options related to model and property input") { - val model: File by option( - help = "Path of the input model (XSTS or Pnml). Extension should be .pnml to be handled as petri-net input" - ).file(mustExist = true, canBeDir = false).required() - private val property: InputStream? by option( - help = "Path of the property file. Has priority over --inlineProperty" - ).inputStream() - private val inlineProperty: String? by option(help = "Input property as a string. Ignored if --property is defined") - private val initialmarking: String by option(help = "Initial marking of the pnml model").default("") + val model: File by + option( + help = + "Path of the input model (XSTS or Pnml). Extension should be .pnml to be handled as petri-net input" + ) + .file(mustExist = true, canBeDir = false) + .required() + private val property: InputStream? by + option(help = "Path of the property file. Has priority over --inlineProperty").inputStream() + private val inlineProperty: String? by + option(help = "Input property as a string. Ignored if --property is defined") + private val initialmarking: String by + option(help = "Initial marking of the pnml model").default("") - fun isPnml() = model.path.endsWith("pnml") + fun isPnml() = model.path.endsWith("pnml") - fun loadXsts(): XSTS { - val propertyStream = if (property != null) property else (if (inlineProperty != null) ByteArrayInputStream( - "prop { $inlineProperty }".toByteArray() - ) else null) - if (isPnml()) { - val petriNet = XMLPnmlToPetrinet.parse(model.absolutePath, initialmarking) - return PetriNetToXSTS.createXSTS(petriNet, propertyStream) - } - return XstsDslManager.createXsts( - SequenceInputStream(FileInputStream(model), propertyStream ?: InputStream.nullInputStream()) - ) + fun loadXsts(): XSTS { + val propertyStream = + if (property != null) property + else + (if (inlineProperty != null) ByteArrayInputStream("prop { $inlineProperty }".toByteArray()) + else null) + if (isPnml()) { + val petriNet = XMLPnmlToPetrinet.parse(model.absolutePath, initialmarking) + return PetriNetToXSTS.createXSTS(petriNet, propertyStream) } + return XstsDslManager.createXsts( + SequenceInputStream(FileInputStream(model), propertyStream ?: InputStream.nullInputStream()) + ) + } - fun loadPetriNet(): MutableList = PetriNetParser.loadPnml(model).parsePTNet() -} \ No newline at end of file + fun loadPetriNet(): MutableList = PetriNetParser.loadPnml(model).parsePTNet() +} diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/OutputOptions.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/OutputOptions.kt index ea4d34440a..4331f7a559 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/OutputOptions.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/OutputOptions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli.optiongroup import com.github.ajalt.clikt.parameters.groups.OptionGroup @@ -26,19 +25,18 @@ import com.github.ajalt.clikt.parameters.types.file import hu.bme.mit.theta.common.logging.Logger import java.io.File -class OutputOptions : OptionGroup( - name = "Output options", - help = "Options related to output and statistics" -) { - - val logLevel: Logger.Level by option(help = "Detailedness of logging").enum() - .default(Logger.Level.SUBSTEP) - val benchmarkMode: Boolean by option( - "--benchmark", help = "Quiet mode, output will be just the result metrics" - ).boolean().default(false) +class OutputOptions : + OptionGroup(name = "Output options", help = "Options related to output and statistics") { - val cexfile: File? by option(help = "Write concrete counterexample to a file").file() - val stacktrace: Boolean by option(help = "Print stack trace of exceptions").flag() - val visualize: File? by option(help = "Write proof or counterexample to file in dot format").file() + val logLevel: Logger.Level by + option(help = "Detailedness of logging").enum().default(Logger.Level.SUBSTEP) + val benchmarkMode: Boolean by + option("--benchmark", help = "Quiet mode, output will be just the result metrics") + .boolean() + .default(false) -} \ No newline at end of file + val cexfile: File? by option(help = "Write concrete counterexample to a file").file() + val stacktrace: Boolean by option(help = "Print stack trace of exceptions").flag() + val visualize: File? by + option(help = "Write proof or counterexample to file in dot format").file() +} diff --git a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/PetrinetDependencyOutputOptions.kt b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/PetrinetDependencyOutputOptions.kt index fef333cccb..577e400f82 100644 --- a/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/PetrinetDependencyOutputOptions.kt +++ b/subprojects/xsts/xsts-cli/src/main/kotlin/hu/bme/mit/theta/xsts/cli/optiongroup/PetrinetDependencyOutputOptions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.xsts.cli.optiongroup import com.github.ajalt.clikt.parameters.groups.OptionGroup @@ -23,16 +22,20 @@ import java.io.File class PetrinetDependencyOutputOptions : OptionGroup() { - val depGxl: File? by option( + val depGxl: File? by + option( help = "Generate GXL representation of (extended) dependency graph for variable ordering" - ).file(mustExist = false, canBeDir = false, mustBeWritable = true) - val depGxlGsat: File? by option( + ) + .file(mustExist = false, canBeDir = false, mustBeWritable = true) + val depGxlGsat: File? by + option( help = "Generate GXL representation of (extended) dependency graph for variable ordering" - ).file(mustExist = false, canBeDir = false, mustBeWritable = true) - val depMat: File? by option(help = "Generate dependency matrix from the model as a CSV file").file( - mustExist = false, canBeDir = false, mustBeWritable = true - ) - val depMatPng: File? by option(help = "Generate dependency matrix from the model as a PNG file").file( - mustExist = false, canBeDir = false, mustBeWritable = true - ) -} \ No newline at end of file + ) + .file(mustExist = false, canBeDir = false, mustBeWritable = true) + val depMat: File? by + option(help = "Generate dependency matrix from the model as a CSV file") + .file(mustExist = false, canBeDir = false, mustBeWritable = true) + val depMatPng: File? by + option(help = "Generate dependency matrix from the model as a PNG file") + .file(mustExist = false, canBeDir = false, mustBeWritable = true) +} diff --git a/subprojects/xsts/xsts/build.gradle.kts b/subprojects/xsts/xsts/build.gradle.kts index 25854d3935..af5dd39f3f 100644 --- a/subprojects/xsts/xsts/build.gradle.kts +++ b/subprojects/xsts/xsts/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/XSTS.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/XSTS.java index b5617c11da..d1edd1b609 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/XSTS.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/XSTS.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/CustomTypeDeclarationUtil.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/CustomTypeDeclarationUtil.java index 57694872c4..fc2e26fd32 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/CustomTypeDeclarationUtil.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/CustomTypeDeclarationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,16 +19,16 @@ import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.type.enumtype.EnumType; - import java.util.Optional; public final class CustomTypeDeclarationUtil { - private CustomTypeDeclarationUtil() { - } + private CustomTypeDeclarationUtil() {} - public static void declareTypeWithShortName(DynamicScope currentScope, EnumType enumType, String literal, Env env) { - Symbol fullNameSymbol = currentScope.resolve(EnumType.makeLongName(enumType, literal)).orElseThrow(); + public static void declareTypeWithShortName( + DynamicScope currentScope, EnumType enumType, String literal, Env env) { + Symbol fullNameSymbol = + currentScope.resolve(EnumType.makeLongName(enumType, literal)).orElseThrow(); if (fullNameSymbol instanceof XstsCustomLiteralSymbol fNameCustLitSymbol) { var customSymbol = XstsCustomLiteralSymbol.copyWithName(fNameCustLitSymbol, literal); Optional optionalSymbol = currentScope.resolve(literal); @@ -39,8 +39,8 @@ public static void declareTypeWithShortName(DynamicScope currentScope, EnumType env.define(customSymbol, customSymbol.instantiate()); } } else { - throw new IllegalArgumentException(String.format("%s is not a literal of type %s", literal, enumType.getName())); + throw new IllegalArgumentException( + String.format("%s is not a literal of type %s", literal, enumType.getName())); } } - } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomLiteralSymbol.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomLiteralSymbol.java index 22be26aa81..f0052e0a27 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomLiteralSymbol.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomLiteralSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -49,8 +49,8 @@ public Expr instantiate() { return EnumLitExpr.of(type, EnumType.getShortName(literal)); } - public static XstsCustomLiteralSymbol copyWithName(XstsCustomLiteralSymbol symbol, String newName) { + public static XstsCustomLiteralSymbol copyWithName( + XstsCustomLiteralSymbol symbol, String newName) { return new XstsCustomLiteralSymbol(symbol.type, newName); } - } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomTypeSymbol.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomTypeSymbol.java index 8fc41e1565..d2608cdaf8 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomTypeSymbol.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsCustomTypeSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,7 +18,6 @@ import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.enumtype.EnumType; - import java.util.Objects; public final class XstsCustomTypeSymbol implements Symbol { diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsDslManager.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsDslManager.java index ea4c238086..a31b347677 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsDslManager.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsDslManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,22 +18,20 @@ import hu.bme.mit.theta.xsts.XSTS; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslLexer; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import org.antlr.v4.runtime.CharStreams; +import org.antlr.v4.runtime.CommonTokenStream; public final class XstsDslManager { - private XstsDslManager() { - } + private XstsDslManager() {} public static XSTS createXsts(final String inputString) throws IOException { - final InputStream stream = new ByteArrayInputStream( - inputString.getBytes(StandardCharsets.UTF_8.name())); + final InputStream stream = + new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8.name())); return createXsts(stream); } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsExpression.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsExpression.java index a0fd5b35ff..a804006127 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsExpression.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,21 @@ */ package hu.bme.mit.theta.xsts.dsl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.common.Utils.head; +import static hu.bme.mit.theta.common.Utils.tail; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.*; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.ExprUtils.simplify; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; +import static hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser.*; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Tuple2; import hu.bme.mit.theta.common.dsl.DynamicScope; @@ -34,8 +49,6 @@ import hu.bme.mit.theta.core.type.enumtype.EnumType; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslBaseVisitor; -import org.antlr.v4.runtime.Token; - import java.math.BigInteger; import java.util.Collection; import java.util.List; @@ -43,21 +56,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.common.Utils.head; -import static hu.bme.mit.theta.common.Utils.tail; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.*; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.ExprUtils.simplify; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; -import static hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser.*; -import static java.util.stream.Collectors.toList; +import org.antlr.v4.runtime.Token; final class XstsExpression { @@ -65,8 +64,8 @@ final class XstsExpression { private final SymbolTable typeTable; private final ExprContext context; - public XstsExpression(final DynamicScope scope, final SymbolTable typeTable, - final ExprContext context) { + public XstsExpression( + final DynamicScope scope, final SymbolTable typeTable, final ExprContext context) { this.scope = checkNotNull(scope); this.typeTable = checkNotNull(typeTable); this.context = checkNotNull(context); @@ -88,8 +87,8 @@ private static final class ExprCreatorVisitor extends XstsDslBaseVisitor private final SymbolTable typeTable; private final Env env; - private ExprCreatorVisitor(final DynamicScope scope, final SymbolTable typeTable, - final Env env) { + private ExprCreatorVisitor( + final DynamicScope scope, final SymbolTable typeTable, final Env env) { currentScope = checkNotNull(scope); this.typeTable = checkNotNull(typeTable); this.env = checkNotNull(env); @@ -132,8 +131,8 @@ public Expr visitImplyExpr(final ImplyExprContext ctx) { @Override public Expr visitOrExpr(final OrExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return Or(ops); } else { @@ -155,8 +154,8 @@ public Expr visitXorExpr(final XorExprContext ctx) { @Override public Expr visitAndExpr(final AndExprContext ctx) { if (ctx.ops.size() > 1) { - final Stream> opStream = ctx.ops.stream() - .map(op -> cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.ops.stream().map(op -> cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return And(ops); } else { @@ -190,11 +189,14 @@ public Expr visitEqualityExpr(final EqualityExprContext ctx) { } if (leftOp.getType() instanceof EnumType enumType) { env.push(); - enumType.getValues().forEach(literal -> CustomTypeDeclarationUtil.declareTypeWithShortName(currentScope, enumType, literal, env)); + enumType.getValues() + .forEach( + literal -> + CustomTypeDeclarationUtil.declareTypeWithShortName( + currentScope, enumType, literal, env)); } rightOp = (inverse ? ctx.leftOp : ctx.rightOp).accept(this); - if (leftOp.getType() instanceof EnumType) - env.pop(); + if (leftOp.getType() instanceof EnumType) env.pop(); return switch (ctx.oper.getType()) { case EQ -> Eq(leftOp, rightOp); case NEQ -> Neq(leftOp, rightOp); @@ -245,9 +247,11 @@ public Expr visitAdditiveExpr(final AdditiveExprContext ctx) { } } - private Expr createAdditiveExpr(final Expr opsHead, - final List> opsTail, - final List opers, final AdditiveExprContext ctx) { + private Expr createAdditiveExpr( + final Expr opsHead, + final List> opsTail, + final List opers, + final AdditiveExprContext ctx) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -265,11 +269,12 @@ private Expr createAdditiveExpr(final Expr opsHead, } } - private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper, - final AdditiveExprContext ctx) { + private Expr createAdditiveSubExpr( + final Expr leftOp, + final Expr rightOp, + final Token oper, + final AdditiveExprContext ctx) { switch (oper.getType()) { - case PLUS: return createAddExpr(leftOp, rightOp); @@ -284,9 +289,11 @@ private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightO private AddExpr createAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof AddExpr) { final AddExpr addLeftOp = (AddExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Add(ops); } else { return Add(leftOp, rightOp); @@ -310,12 +317,13 @@ public Expr visitMultiplicativeExpr(final MultiplicativeExprContext ctx) { } else { return visitChildren(ctx); } - } - private Expr createMutliplicativeExpr(final Expr opsHead, - final List> opsTail, - final List opers, final MultiplicativeExprContext ctx) { + private Expr createMutliplicativeExpr( + final Expr opsHead, + final List> opsTail, + final List opers, + final MultiplicativeExprContext ctx) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -327,18 +335,19 @@ private Expr createMutliplicativeExpr(final Expr opsHead, final Token operHead = opers.get(0); final List opersTail = opers.subList(1, opers.size()); - final Expr subExpr = createMultiplicativeSubExpr(opsHead, newOpsHead, operHead, - ctx); + final Expr subExpr = + createMultiplicativeSubExpr(opsHead, newOpsHead, operHead, ctx); return createMutliplicativeExpr(subExpr, newOpsTail, opersTail, ctx); } } - private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr rightOp, - final Token oper, - final MultiplicativeExprContext ctx) { + private Expr createMultiplicativeSubExpr( + final Expr leftOp, + final Expr rightOp, + final Token oper, + final MultiplicativeExprContext ctx) { switch (oper.getType()) { - case MUL: return createMulExpr(leftOp, rightOp); @@ -359,9 +368,11 @@ private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof MulExpr) { final MulExpr addLeftOp = (MulExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Mul(ops); } else { return Mul(leftOp, rightOp); @@ -429,18 +440,20 @@ private Expr createAccessSubExpr(final Expr op, final AccessContext access } } - private Expr createArrayReadExpr(final Expr op, - final ArrayReadAccessContext ctx) { + private Expr createArrayReadExpr( + final Expr op, final ArrayReadAccessContext ctx) { checkArgument(op.getType() instanceof ArrayType); - @SuppressWarnings("unchecked") final Expr> array = (Expr>) op; + @SuppressWarnings("unchecked") + final Expr> array = (Expr>) op; final Expr index = cast(ctx.index.accept(this), array.getType().getIndexType()); return Read(array, index); } - private Expr createArrayWriteExpr(final Expr op, - final ArrayWriteAccessContext ctx) { + private Expr createArrayWriteExpr( + final Expr op, final ArrayWriteAccessContext ctx) { checkArgument(op.getType() instanceof ArrayType); - @SuppressWarnings("unchecked") final Expr> array = (Expr>) op; + @SuppressWarnings("unchecked") + final Expr> array = (Expr>) op; final Expr index = cast(ctx.index.accept(this), array.getType().getIndexType()); final Expr elem = cast(ctx.elem.accept(this), array.getType().getElemType()); return Write(array, index, elem); @@ -484,13 +497,18 @@ private Expr createArrayLitExpr( } valueType = (T2) ctx.elseExpr.accept(this).getType(); - final List, Expr>> elems = IntStream - .range(0, ctx.indexExpr.size()) - .mapToObj(i -> Tuple2.of( - cast(ctx.indexExpr.get(i).accept(this), indexType), - cast(ctx.valueExpr.get(i).accept(this), valueType) - )) - .collect(Collectors.toUnmodifiableList()); + final List, Expr>> elems = + IntStream.range(0, ctx.indexExpr.size()) + .mapToObj( + i -> + Tuple2.of( + cast( + ctx.indexExpr.get(i).accept(this), + indexType), + cast( + ctx.valueExpr.get(i).accept(this), + valueType))) + .collect(Collectors.toUnmodifiableList()); final Expr elseExpr = cast(ctx.elseExpr.accept(this), valueType); return simplify(ArrayInit(elems, elseExpr, ArrayType.of(indexType, valueType))); @@ -500,8 +518,8 @@ private Expr createArrayLitExpr( public Expr visitIdExpr(final IdExprContext ctx) { Optional optSymbol = currentScope.resolve(ctx.id.getText()); if (optSymbol.isEmpty()) { - throw new ParseException(ctx, - "Identifier '" + ctx.id.getText() + "' cannot be resolved"); + throw new ParseException( + ctx, "Identifier '" + ctx.id.getText() + "' cannot be resolved"); } final Symbol symbol = optSymbol.get(); final Object val = env.eval(symbol); @@ -510,15 +528,14 @@ public Expr visitIdExpr(final IdExprContext ctx) { } else if (val instanceof Decl decl) { return decl.getRef(); } - throw new ParseException(ctx, + throw new ParseException( + ctx, "Identifier '" + ctx.id.getText() + "' does not refer to a valid expression"); - } @Override public Expr visitParenExpr(final ParenExprContext ctx) { return ctx.op.accept(this); } - } } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsSpecification.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsSpecification.java index ff7a78bf51..d7d11e45fc 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsSpecification.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsSpecification.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsStatement.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsStatement.java index ef74b56a46..d7310c13f2 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsStatement.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsStatement.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,21 @@ */ package hu.bme.mit.theta.xsts.dsl; +import static com.google.common.base.Preconditions.*; +import static hu.bme.mit.theta.core.stmt.Stmts.*; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import hu.bme.mit.theta.common.dsl.*; import hu.bme.mit.theta.core.decl.Decls; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.dsl.DeclSymbol; import hu.bme.mit.theta.core.dsl.ParseException; +import hu.bme.mit.theta.core.stmt.*; import hu.bme.mit.theta.core.stmt.NonDetStmt; import hu.bme.mit.theta.core.stmt.SequenceStmt; -import hu.bme.mit.theta.core.stmt.*; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.arraytype.ArrayType; @@ -31,25 +38,17 @@ import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslBaseVisitor; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser.*; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.*; -import static hu.bme.mit.theta.core.stmt.Stmts.*; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Write; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - public class XstsStatement { private final DynamicScope scope; private final SymbolTable typeTable; private final StmtContext context; - public XstsStatement(final DynamicScope scope, final SymbolTable typeTable, - final StmtContext context) { + public XstsStatement( + final DynamicScope scope, final SymbolTable typeTable, final StmtContext context) { this.scope = checkNotNull(scope); this.typeTable = checkNotNull(typeTable); this.context = checkNotNull(context); @@ -71,8 +70,8 @@ private static final class StmtCreatorVisitor extends XstsDslBaseVisitor { private final SymbolTable typeTable; private final Env env; - public StmtCreatorVisitor(final DynamicScope scope, final SymbolTable typeTable, - final Env env) { + public StmtCreatorVisitor( + final DynamicScope scope, final SymbolTable typeTable, final Env env) { this.currentScope = checkNotNull(scope); this.typeTable = checkNotNull(typeTable); this.env = checkNotNull(env); @@ -84,8 +83,8 @@ private void push() { } private void pop() { - checkState(currentScope.enclosingScope().isPresent(), - "Enclosing scope is not present."); + checkState( + currentScope.enclosingScope().isPresent(), "Enclosing scope is not present."); currentScope = currentScope.enclosingScope().get(); env.pop(); } @@ -116,16 +115,21 @@ public Stmt visitAssignStmt(final AssignStmtContext ctx) { if (var.getType() instanceof EnumType enumType) { env.push(); - enumType.getValues().forEach(literal -> CustomTypeDeclarationUtil.declareTypeWithShortName(currentScope, enumType, literal, env)); + enumType.getValues() + .forEach( + literal -> + CustomTypeDeclarationUtil.declareTypeWithShortName( + currentScope, enumType, literal, env)); } - final XstsExpression expression = new XstsExpression(currentScope, typeTable, - ctx.value); + final XstsExpression expression = + new XstsExpression(currentScope, typeTable, ctx.value); final Expr expr = expression.instantiate(env); - if (var.getType() instanceof EnumType) - env.pop(); + if (var.getType() instanceof EnumType) env.pop(); if (expr.getType().equals(var.getType())) { - @SuppressWarnings("unchecked") final VarDecl tVar = (VarDecl) var; - @SuppressWarnings("unchecked") final Expr tExpr = (Expr) expr; + @SuppressWarnings("unchecked") + final VarDecl tVar = (VarDecl) var; + @SuppressWarnings("unchecked") + final Expr tExpr = (Expr) expr; return Assign(tVar, tExpr); } else { throw new IllegalArgumentException( @@ -160,11 +164,13 @@ public Stmt visitAssignArrayWriteSugar(AssignArrayWriteSugarContext ctx) { final XstsExpression value = new XstsExpression(currentScope, typeTable, ctx.value); final Expr valueExpr = value.instantiate(env); - final Expr arrayWriteExpr = createArrayWriteExpr(var.getRef(), indexExpr, - valueExpr); + final Expr arrayWriteExpr = + createArrayWriteExpr(var.getRef(), indexExpr, valueExpr); if (arrayWriteExpr.getType().equals(var.getType())) { - @SuppressWarnings("unchecked") final VarDecl tVar = (VarDecl) var; - @SuppressWarnings("unchecked") final Expr tExpr = (Expr) arrayWriteExpr; + @SuppressWarnings("unchecked") + final VarDecl tVar = (VarDecl) var; + @SuppressWarnings("unchecked") + final Expr tExpr = (Expr) arrayWriteExpr; return Assign(tVar, tExpr); } else { throw new IllegalArgumentException( @@ -175,9 +181,10 @@ public Stmt visitAssignArrayWriteSugar(AssignArrayWriteSugarContext ctx) { } } - private Expr createArrayWriteExpr(Expr var, - Expr indexExpr, Expr valueExpr) { - @SuppressWarnings("unchecked") final Expr> array = (Expr>) var; + private Expr createArrayWriteExpr( + Expr var, Expr indexExpr, Expr valueExpr) { + @SuppressWarnings("unchecked") + final Expr> array = (Expr>) var; final Expr index = cast(indexExpr, array.getType().getIndexType()); final Expr value = cast(valueExpr, array.getType().getElemType()); return Write(array, index, value); @@ -189,19 +196,24 @@ public Stmt visitLoopStmt(LoopStmtContext ctx) { final String loopVarId = ctx.loopVar.getText(); if (currentScope.resolve(loopVarId).isPresent()) { - throw new ParseException(ctx, - String.format("Loop variable %s is already declared in this scope.", - loopVarId)); + throw new ParseException( + ctx, + String.format( + "Loop variable %s is already declared in this scope.", loopVarId)); } final var decl = Decls.Var(loopVarId, Int()); final Symbol symbol = DeclSymbol.of(decl); currentScope.declare(symbol); env.define(symbol, decl); - final Expr from = cast( - new XstsExpression(currentScope, typeTable, ctx.from).instantiate(env), Int()); - final Expr to = cast( - new XstsExpression(currentScope, typeTable, ctx.to).instantiate(env), Int()); + final Expr from = + cast( + new XstsExpression(currentScope, typeTable, ctx.from).instantiate(env), + Int()); + final Expr to = + cast( + new XstsExpression(currentScope, typeTable, ctx.to).instantiate(env), + Int()); final Stmt stmt = ctx.subStmt.accept(this); pop(); @@ -213,8 +225,7 @@ public Stmt visitLoopStmt(LoopStmtContext ctx) { @SuppressWarnings("unchecked") public Stmt visitLocalVarDeclStmt(LocalVarDeclStmtContext ctx) { final String name = ctx.name.getText(); - final Type type = new XstsType(typeTable, - ctx.ttype).instantiate(env); + final Type type = new XstsType(typeTable, ctx.ttype).instantiate(env); final var decl = Decls.Var(name, type); final Symbol symbol = DeclSymbol.of(decl); @@ -222,11 +233,13 @@ public Stmt visitLocalVarDeclStmt(LocalVarDeclStmtContext ctx) { if (ctx.initValue == null) { result = SkipStmt.getInstance(); } else { - var expr = new XstsExpression(currentScope, typeTable, ctx.initValue).instantiate( - env); + var expr = + new XstsExpression(currentScope, typeTable, ctx.initValue).instantiate(env); if (expr.getType().equals(decl.getType())) { - @SuppressWarnings("unchecked") final VarDecl tVar = (VarDecl) decl; - @SuppressWarnings("unchecked") final Expr tExpr = (Expr) expr; + @SuppressWarnings("unchecked") + final VarDecl tVar = (VarDecl) decl; + @SuppressWarnings("unchecked") + final Expr tExpr = (Expr) expr; result = Assign(tVar, tExpr); } else { throw new IllegalArgumentException( @@ -276,5 +289,4 @@ public Stmt visitIfStmt(IfStmtContext ctx) { } } } - } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsTransitionSet.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsTransitionSet.java index 0347f5c9a7..04d504a2a9 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsTransitionSet.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsTransitionSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.xsts.dsl; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.dsl.DynamicScope; import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.SymbolTable; @@ -22,19 +24,18 @@ import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslBaseVisitor; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser.TransitionSetContext; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - public class XstsTransitionSet { private final DynamicScope scope; private final SymbolTable typeTable; private final TransitionSetContext context; - public XstsTransitionSet(final DynamicScope scope, final SymbolTable typeTable, - final TransitionSetContext context) { + public XstsTransitionSet( + final DynamicScope scope, + final SymbolTable typeTable, + final TransitionSetContext context) { this.scope = checkNotNull(scope); this.typeTable = checkNotNull(typeTable); this.context = checkNotNull(context); @@ -60,12 +61,14 @@ public TransitionSetCreatorVisitor(final Env env) { @Override public NonDetStmt visitTransitionSet(TransitionSetContext ctx) { - final List stmts = ctx.stmts.stream() - .map((stmtContext -> - new XstsStatement(scope, typeTable, stmtContext) - .instantiate(env))).toList(); + final List stmts = + ctx.stmts.stream() + .map( + (stmtContext -> + new XstsStatement(scope, typeTable, stmtContext) + .instantiate(env))) + .toList(); return NonDetStmt.of(stmts); } } - } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsType.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsType.java index 1914625170..452d50c52d 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsType.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.xsts.dsl; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.common.dsl.SymbolTable; @@ -22,14 +27,8 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslBaseVisitor; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser.*; - import java.util.Optional; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - final class XstsType { private final SymbolTable typeTable; @@ -50,8 +49,7 @@ public Type instantiate(final Env env) { } } - private static class TypeCreatorVisitor extends - XstsDslBaseVisitor { + private static class TypeCreatorVisitor extends XstsDslBaseVisitor { private final SymbolTable typeTable; private final Env env; @@ -65,8 +63,8 @@ public TypeCreatorVisitor(final SymbolTable typeTable, final Env env) { public Type visitCustomType(final CustomTypeContext ctx) { Optional optSymbol = typeTable.get(ctx.name.getText()); if (optSymbol.isEmpty()) { - throw new ParseException(ctx, - "Type '" + ctx.name.getText() + "' cannot be resolved"); + throw new ParseException( + ctx, "Type '" + ctx.name.getText() + "' cannot be resolved"); } final Symbol symbol = optSymbol.get(); return (Type) env.eval(symbol); @@ -88,7 +86,5 @@ public Type visitArrayType(final ArrayTypeContext ctx) { final Type elemType = ctx.elemType.accept(this); return Array(indexType, elemType); } - } - } diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsVariableSymbol.java b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsVariableSymbol.java index a1c97f9fbc..e47ca14624 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsVariableSymbol.java +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/dsl/XstsVariableSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,22 +15,22 @@ */ package hu.bme.mit.theta.xsts.dsl; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.decl.Decls.Var; + import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.common.dsl.SymbolTable; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.xsts.dsl.gen.XstsDslParser.VariableDeclarationContext; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.decl.Decls.Var; - public class XstsVariableSymbol implements Symbol { private final String name; private final XstsType type; - public XstsVariableSymbol(final SymbolTable typeTable, - final VariableDeclarationContext context) { + public XstsVariableSymbol( + final SymbolTable typeTable, final VariableDeclarationContext context) { checkNotNull(context); name = context.name.getText(); type = new XstsType(typeTable, context.ttype); diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsNormalizerPass.kt b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsNormalizerPass.kt index 14c7087ff4..580103b3d8 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsNormalizerPass.kt +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsNormalizerPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsPass.kt b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsPass.kt index dc2dfc5f07..d0a1333994 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsPass.kt +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/passes/XstsPass.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt index c1023766e3..b79273f488 100644 --- a/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt +++ b/subprojects/xsts/xsts/src/main/java/hu/bme/mit/theta/xsts/utils/XSTSVarChanger.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xsts/xsts/src/test/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChangerUnitTest.kt b/subprojects/xsts/xsts/src/test/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChangerUnitTest.kt index af7af05863..5adfecb178 100644 --- a/subprojects/xsts/xsts/src/test/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChangerUnitTest.kt +++ b/subprojects/xsts/xsts/src/test/kotlin/hu/bme/mit/theta/xsts/utils/XSTSVarChangerUnitTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,37 +20,34 @@ import hu.bme.mit.theta.core.type.inttype.IntType import hu.bme.mit.theta.core.utils.StmtUtils import hu.bme.mit.theta.xsts.XSTS import hu.bme.mit.theta.xsts.dsl.XstsDslManager -import org.junit.jupiter.api.Test import java.io.FileInputStream +import org.junit.jupiter.api.Test class XSTSVarChangerUnitTest { - @Test - fun `xsts variable changing`() { - var origXsts: XSTS - FileInputStream("src/test/resources/incrementors.xsts").use { inputStream -> - origXsts = XstsDslManager.createXsts(inputStream) - } - val newX = Decls.Var("x", IntType.getInstance()) - val newY = Decls.Var("y", IntType.getInstance()) - val newXsts = origXsts.copyWithReplacingVars( - listOf(newX, newY) - .associateBy { it.name } - ) + @Test + fun `xsts variable changing`() { + var origXsts: XSTS + FileInputStream("src/test/resources/incrementors.xsts").use { inputStream -> + origXsts = XstsDslManager.createXsts(inputStream) + } + val newX = Decls.Var("x", IntType.getInstance()) + val newY = Decls.Var("y", IntType.getInstance()) + val newXsts = origXsts.copyWithReplacingVars(listOf(newX, newY).associateBy { it.name }) - val origVars = setOf( - StmtUtils.getVars(origXsts.init), - StmtUtils.getVars(origXsts.tran), - StmtUtils.getVars(origXsts.env) - ) - val newVars = setOf( - StmtUtils.getVars(newXsts.init), - StmtUtils.getVars(newXsts.tran), - StmtUtils.getVars(newXsts.env) - ) + val origVars = + setOf( + StmtUtils.getVars(origXsts.init), + StmtUtils.getVars(origXsts.tran), + StmtUtils.getVars(origXsts.env), + ) + val newVars = + setOf( + StmtUtils.getVars(newXsts.init), + StmtUtils.getVars(newXsts.tran), + StmtUtils.getVars(newXsts.env), + ) - assert(!newVars.any { - origVars.contains(it) - }) - } -} \ No newline at end of file + assert(!newVars.any { origVars.contains(it) }) + } +} diff --git a/subprojects/xta/xta-analysis/build.gradle.kts b/subprojects/xta/xta-analysis/build.gradle.kts index 15083ecbc0..e3bd519e6c 100644 --- a/subprojects/xta/xta-analysis/build.gradle.kts +++ b/subprojects/xta/xta-analysis/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAction.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAction.java index ec6a184541..2b91c8455a 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAction.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,19 @@ */ package hu.bme.mit.theta.xta.analysis; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.collect.Streams.zip; +import static hu.bme.mit.theta.core.decl.Decls.Var; +import static hu.bme.mit.theta.core.stmt.Stmts.*; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Or; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.*; +import static hu.bme.mit.theta.xta.Sync.Kind.EMIT; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.Streams; @@ -34,26 +47,12 @@ import hu.bme.mit.theta.xta.XtaProcess.Loc; import hu.bme.mit.theta.xta.XtaProcess.LocKind; import hu.bme.mit.theta.xta.XtaSystem; - import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static com.google.common.collect.ImmutableSet.toImmutableSet; -import static com.google.common.collect.Streams.zip; -import static hu.bme.mit.theta.core.decl.Decls.Var; -import static hu.bme.mit.theta.core.stmt.Stmts.*; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Or; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.*; -import static hu.bme.mit.theta.xta.Sync.Kind.EMIT; - public abstract class XtaAction extends StmtAction { private static final VarDecl DELAY = Var("_delay", Rat()); @@ -67,20 +66,24 @@ private XtaAction(final XtaSystem system, final List source) { this.sourceLocs = ImmutableList.copyOf(checkNotNull(source)); } - public static BasicXtaAction basic(final XtaSystem system, final List sourceLocs, - final Edge edge) { + public static BasicXtaAction basic( + final XtaSystem system, final List sourceLocs, final Edge edge) { return new BasicXtaAction(system, sourceLocs, edge); } - public static BinaryXtaAction binary(final XtaSystem system, final List sourceLocs, - final Edge emitEdge, - final Edge recvEdge) { + public static BinaryXtaAction binary( + final XtaSystem system, + final List sourceLocs, + final Edge emitEdge, + final Edge recvEdge) { return new BinaryXtaAction(system, sourceLocs, emitEdge, recvEdge); } - public static BroadcastXtaAction broadcast(final XtaSystem system, final List sourceLocs, - final Edge emitEdge, - final List recvEdges) { + public static BroadcastXtaAction broadcast( + final XtaSystem system, + final List sourceLocs, + final Edge emitEdge, + final List recvEdges) { return new BroadcastXtaAction(system, sourceLocs, emitEdge, recvEdges); } @@ -125,8 +128,8 @@ public static final class BasicXtaAction extends XtaAction { private volatile List stmts = null; - private BasicXtaAction(final XtaSystem system, final List sourceLocs, - final Edge edge) { + private BasicXtaAction( + final XtaSystem system, final List sourceLocs, final Edge edge) { super(system, sourceLocs); this.edge = checkNotNull(edge); @@ -187,11 +190,12 @@ public List getStmts() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).body() + return Utils.lispStringBuilder(getClass().getSimpleName()) + .body() .addAll(edge.getGuards()) - .addAll(edge.getUpdates()).toString(); + .addAll(edge.getUpdates()) + .toString(); } - } public static final class BinaryXtaAction extends XtaAction { @@ -202,9 +206,11 @@ public static final class BinaryXtaAction extends XtaAction { private volatile List stmts = null; - private BinaryXtaAction(final XtaSystem system, final List sourceLocs, - final Edge emitEdge, - final Edge recvEdge) { + private BinaryXtaAction( + final XtaSystem system, + final List sourceLocs, + final Edge emitEdge, + final Edge recvEdge) { super(system, sourceLocs); this.emitEdge = checkNotNull(emitEdge); this.recvEdge = checkNotNull(recvEdge); @@ -287,12 +293,16 @@ public List getStmts() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).add(emitEdge.getSync().get()) - .add(recvEdge.getSync().get()).body().addAll(emitEdge.getGuards()) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .add(emitEdge.getSync().get()) + .add(recvEdge.getSync().get()) + .body() + .addAll(emitEdge.getGuards()) .addAll(recvEdge.getGuards()) - .addAll(emitEdge.getUpdates()).addAll(recvEdge.getUpdates()).toString(); + .addAll(emitEdge.getUpdates()) + .addAll(recvEdge.getUpdates()) + .toString(); } - } public static final class BroadcastXtaAction extends XtaAction { @@ -304,8 +314,11 @@ public static final class BroadcastXtaAction extends XtaAction { private volatile List stmts = null; - private BroadcastXtaAction(final XtaSystem system, final List sourceLocs, - final Edge emitEdge, List recvEdges) { + private BroadcastXtaAction( + final XtaSystem system, + final List sourceLocs, + final Edge emitEdge, + List recvEdges) { super(system, sourceLocs); this.emitEdge = checkNotNull(emitEdge); this.recvEdges = ImmutableList.copyOf(checkNotNull(recvEdges)); @@ -314,7 +327,8 @@ private BroadcastXtaAction(final XtaSystem system, final List sourceLocs, final Sync emitSync = emitEdge.getSync().get(); checkArgument(emitSync.getKind().equals(EMIT)); - final ImmutableList.Builder> nonRecvEdgesBuilder = ImmutableList.builder(); + final ImmutableList.Builder> nonRecvEdgesBuilder = + ImmutableList.builder(); final ImmutableList.Builder targetLocsBuilder = ImmutableList.builder(); final Loc emitSource = emitEdge.getSource(); final Loc emitTarget = emitEdge.getTarget(); @@ -328,8 +342,8 @@ private BroadcastXtaAction(final XtaSystem system, final List sourceLocs, targetLocsBuilder.add(emitTarget); emitMatched = true; } else if (!optRecvEdge.isPresent() || !optRecvEdge.get().getSource().equals(loc)) { - final Collection nonRecvEdgesForLoc = outEdgesOfLocThatMayReceiveSync(loc, - emitSync); + final Collection nonRecvEdgesForLoc = + outEdgesOfLocThatMayReceiveSync(loc, emitSync); if (!nonRecvEdgesForLoc.isEmpty()) { nonRecvEdgesBuilder.add(nonRecvEdgesForLoc); } @@ -355,28 +369,34 @@ private BroadcastXtaAction(final XtaSystem system, final List sourceLocs, targetLocs = targetLocsBuilder.build(); final long nrLocsExceptEmitSourceWithAnyEdgeThatMayRecvSync = - nrLocsExceptEmitSourceWithAnyEdgeThatMayRecvSync(emitSource, sourceLocs, emitSync); + nrLocsExceptEmitSourceWithAnyEdgeThatMayRecvSync( + emitSource, sourceLocs, emitSync); assert nrLocsExceptEmitSourceWithAnyEdgeThatMayRecvSync == recvEdges.size() + nonRecvEdges.size(); assert targetLocs.size() == sourceLocs.size(); } - private Collection outEdgesOfLocThatMayReceiveSync(final Loc loc, - final Sync emitSync) { + private Collection outEdgesOfLocThatMayReceiveSync( + final Loc loc, final Sync emitSync) { return loc.getOutEdges().stream() - .filter(e -> - e.getSync().isPresent() && - e.getSync().get().mayReceive(emitSync)) + .filter(e -> e.getSync().isPresent() && e.getSync().get().mayReceive(emitSync)) .collect(toImmutableSet()); } - private long nrLocsExceptEmitSourceWithAnyEdgeThatMayRecvSync(final Loc emitSource, - final List sourceLocs, final Sync emitSync) { + private long nrLocsExceptEmitSourceWithAnyEdgeThatMayRecvSync( + final Loc emitSource, final List sourceLocs, final Sync emitSync) { return sourceLocs.stream() .filter(l -> !l.equals(emitSource)) - .filter(l -> l.getOutEdges().stream().anyMatch(e -> - e.getSync().isPresent() && e.getSync().get().mayReceive(emitSync)) - ).count(); + .filter( + l -> + l.getOutEdges().stream() + .anyMatch( + e -> + e.getSync().isPresent() + && e.getSync() + .get() + .mayReceive(emitSync))) + .count(); } private final Optional safeNext(Iterator iterator) { @@ -428,8 +448,16 @@ public List getStmts() { addUpdates(builder, emitEdge); recvEdges.stream().forEachOrdered(recvEdge -> addUpdates(builder, recvEdge)); - nonRecvEdges.stream().forEachOrdered(c -> c.stream().forEachOrdered(nonRecvEdge -> - addNonRecvSyncAndGuards(builder, emitEdge, nonRecvEdge))); + nonRecvEdges.stream() + .forEachOrdered( + c -> + c.stream() + .forEachOrdered( + nonRecvEdge -> + addNonRecvSyncAndGuards( + builder, + emitEdge, + nonRecvEdge))); addInvariants(builder, targetLocs); if (shouldApplyDelay(getTargetLocs())) { @@ -449,19 +477,31 @@ public String toString() { builder.addAll(emitEdge.getGuards()); - builder.addAll(recvEdges.stream().map(edge -> - Utils.lispStringBuilder("enabled") - .add(edge.getSync().get()) - .body() - .addAll(edge.getGuards()))); - - builder.addAll(nonRecvEdges.stream().flatMap(edges -> - edges.stream().map(edge -> - Utils.lispStringBuilder("disabled") - .add(edge.getSync().get()) - .body() - .addAll(edge.getGuards() - )))); + builder.addAll( + recvEdges.stream() + .map( + edge -> + Utils.lispStringBuilder("enabled") + .add(edge.getSync().get()) + .body() + .addAll(edge.getGuards()))); + + builder.addAll( + nonRecvEdges.stream() + .flatMap( + edges -> + edges.stream() + .map( + edge -> + Utils.lispStringBuilder( + "disabled") + .add( + edge.getSync() + .get()) + .body() + .addAll( + edge + .getGuards())))); builder.addAll(emitEdge.getUpdates()) .addAll(recvEdges.stream().flatMap(e -> e.getUpdates().stream())); @@ -470,18 +510,18 @@ public String toString() { } } - private static void addClocksNonNegative(final ImmutableList.Builder builder, - final Collection> clocks) { + private static void addClocksNonNegative( + final ImmutableList.Builder builder, final Collection> clocks) { clocks.forEach(c -> builder.add(Assume(Geq(c.getRef(), Rat(0, 1))))); } - private static void addInvariants(final ImmutableList.Builder builder, - final List locs) { + private static void addInvariants( + final ImmutableList.Builder builder, final List locs) { locs.forEach(l -> l.getInvars().forEach(i -> builder.add(Assume(i.toExpr())))); } - private static void addSync(final Builder builder, final Edge emitEdge, - final Edge recvEdge) { + private static void addSync( + final Builder builder, final Edge emitEdge, final Edge recvEdge) { final Stream> emitArgs = emitEdge.getSync().get().getArgs().stream(); final Stream> recvArgs = recvEdge.getSync().get().getArgs().stream(); zip(emitArgs, recvArgs, (e, r) -> Assume(Eq(e, r))).forEach(builder::add); @@ -491,29 +531,30 @@ private static void addGuards(final ImmutableList.Builder builder, final E edge.getGuards().forEach(g -> builder.add(Assume(g.toExpr()))); } - - private static void addNonRecvSyncAndGuards(final ImmutableList.Builder builder, - final Edge emitEdge, final Edge nonRecvEdge) { + private static void addNonRecvSyncAndGuards( + final ImmutableList.Builder builder, + final Edge emitEdge, + final Edge nonRecvEdge) { final Stream> emitArgs = emitEdge.getSync().get().getArgs().stream(); final Stream> nonRecvArgs = nonRecvEdge.getSync().get().getArgs().stream(); - final Stream> notEqExprs = zip(emitArgs, nonRecvArgs, - (e, r) -> Not(Eq(e, r))); - final Stream> notGuards = nonRecvEdge.getGuards().stream() - .filter(Guard::isDataGuard) - .map(Guard::toExpr) - .map(SmartBoolExprs::Not); - final List> exprs = Streams.concat(notEqExprs, notGuards) - .collect(toImmutableList()); + final Stream> notEqExprs = + zip(emitArgs, nonRecvArgs, (e, r) -> Not(Eq(e, r))); + final Stream> notGuards = + nonRecvEdge.getGuards().stream() + .filter(Guard::isDataGuard) + .map(Guard::toExpr) + .map(SmartBoolExprs::Not); + final List> exprs = + Streams.concat(notEqExprs, notGuards).collect(toImmutableList()); builder.add(Assume(Or(exprs))); } - private static void addUpdates(final ImmutableList.Builder builder, final Edge edge) { edge.getUpdates().forEach(u -> builder.add(u.toStmt())); } - private static void addDelay(final ImmutableList.Builder builder, - final Collection> clocks) { + private static void addDelay( + final ImmutableList.Builder builder, final Collection> clocks) { builder.add(Havoc(DELAY)); builder.add(Assume(Geq(DELAY.getRef(), Rat(0, 1)))); clocks.forEach(c -> builder.add(Assign(c, Add(c.getRef(), DELAY.getRef())))); @@ -522,5 +563,4 @@ private static void addDelay(final ImmutableList.Builder builder, private static boolean shouldApplyDelay(final List locs) { return locs.stream().allMatch(l -> l.getKind() == LocKind.NORMAL); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAnalysis.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAnalysis.java index 448170b7d3..747ef26d59 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAnalysis.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,22 +18,22 @@ import static com.google.common.base.Preconditions.checkNotNull; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.xta.XtaSystem; -public final class XtaAnalysis implements - Analysis, XtaAction, P> { +public final class XtaAnalysis + implements Analysis, XtaAction, P> { private final PartialOrd> partialOrd; private final InitFunc, P> initFunc; private final TransFunc, XtaAction, P> transFunc; - private XtaAnalysis(final XtaSystem system, - final Analysis analysis) { + private XtaAnalysis( + final XtaSystem system, final Analysis analysis) { checkNotNull(system); checkNotNull(analysis); partialOrd = XtaOrd.create(analysis.getPartialOrd()); @@ -41,8 +41,8 @@ private XtaAnalysis(final XtaSystem system, transFunc = XtaTransFunc.create(analysis.getTransFunc()); } - public static XtaAnalysis create(final XtaSystem system, - final Analysis analysis) { + public static XtaAnalysis create( + final XtaSystem system, final Analysis analysis) { return new XtaAnalysis<>(system, analysis); } @@ -60,5 +60,4 @@ public InitFunc, P> getInitFunc() { public TransFunc, XtaAction, P> getTransFunc() { return transFunc; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaInitFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaInitFunc.java index efa4213c5c..6d8031ce8d 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaInitFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.List; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; -import hu.bme.mit.theta.xta.XtaSystem; import hu.bme.mit.theta.xta.XtaProcess.Loc; +import hu.bme.mit.theta.xta.XtaSystem; +import java.util.Collection; +import java.util.List; final class XtaInitFunc implements InitFunc, P> { @@ -36,8 +35,8 @@ private XtaInitFunc(final XtaSystem system, final InitFunc initFun this.initFunc = checkNotNull(initFunc); } - public static XtaInitFunc create(final XtaSystem system, - final InitFunc initFunc) { + public static XtaInitFunc create( + final XtaSystem system, final InitFunc initFunc) { return new XtaInitFunc<>(system, initFunc); } @@ -48,5 +47,4 @@ public Collection> getInitStates(final P prec) { final Collection initStates = initFunc.getInitStates(prec); return XtaState.collectionOf(initLocs, initStates); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaLts.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaLts.java index b46a30f88c..67fd765bcd 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaLts.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,13 @@ */ package hu.bme.mit.theta.xta.analysis; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.common.Utils.head; +import static hu.bme.mit.theta.common.Utils.tail; +import static hu.bme.mit.theta.xta.Sync.Kind.EMIT; +import static hu.bme.mit.theta.xta.XtaProcess.LocKind.COMMITTED; +import static java.util.stream.Collectors.toList; + import hu.bme.mit.theta.analysis.LTS; import hu.bme.mit.theta.xta.Label; import hu.bme.mit.theta.xta.Sync; @@ -22,18 +29,10 @@ import hu.bme.mit.theta.xta.XtaProcess.Edge; import hu.bme.mit.theta.xta.XtaProcess.Loc; import hu.bme.mit.theta.xta.XtaSystem; - import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.common.Utils.head; -import static hu.bme.mit.theta.common.Utils.tail; -import static hu.bme.mit.theta.xta.Sync.Kind.EMIT; -import static hu.bme.mit.theta.xta.XtaProcess.LocKind.COMMITTED; -import static java.util.stream.Collectors.toList; - public final class XtaLts implements LTS, XtaAction> { private final XtaSystem system; @@ -57,9 +56,11 @@ public Collection getEnabledActionsFor(final XtaState state) { return result; } - private static void addActionsForEdge(final Collection result, - final XtaSystem system, - final XtaState state, final Edge edge) { + private static void addActionsForEdge( + final Collection result, + final XtaSystem system, + final XtaState state, + final Edge edge) { if (edge.getSync().isPresent()) { final Sync sync = edge.getSync().get(); if (sync.getKind() == EMIT) { @@ -74,9 +75,12 @@ private static void addActionsForEdge(final Collection result, } } - private static void addBroadcastActionsForEdge(final Collection result, - final XtaSystem system, - final XtaState state, final Edge emitEdge, final Sync emitSync) { + private static void addBroadcastActionsForEdge( + final Collection result, + final XtaSystem system, + final XtaState state, + final Edge emitEdge, + final Sync emitSync) { assert emitEdge.getSync().isPresent(); assert emitEdge.getSync().get().equals(emitSync); assert emitSync.getKind().equals(EMIT); @@ -84,15 +88,22 @@ private static void addBroadcastActionsForEdge(final Collection resul final Collection> initialRecvEdgeColls = new ArrayList<>(); initialRecvEdgeColls.add(new ArrayList<>()); - Collection> recvEdgeColls = recvEdgesForEmitEdge(emitEdge, emitSync, - state.getLocs(), initialRecvEdgeColls); + Collection> recvEdgeColls = + recvEdgesForEmitEdge(emitEdge, emitSync, state.getLocs(), initialRecvEdgeColls); // filter out all non well-formed actions if the state is committed final Loc emitLoc = emitEdge.getSource(); if (state.isCommitted() && emitLoc.getKind() != COMMITTED) { - recvEdgeColls = recvEdgeColls.stream().filter(edges -> - edges.stream().anyMatch(edge -> - edge.getSource().getKind() == COMMITTED)).collect(toList()); + recvEdgeColls = + recvEdgeColls.stream() + .filter( + edges -> + edges.stream() + .anyMatch( + edge -> + edge.getSource().getKind() + == COMMITTED)) + .collect(toList()); } for (List recvEdges : recvEdgeColls) { @@ -100,10 +111,11 @@ private static void addBroadcastActionsForEdge(final Collection resul } } - private static Collection> recvEdgesForEmitEdge(final Edge emitEdge, - final Sync emitSync, - final List remainingLocs, - final Collection> accumulator) { + private static Collection> recvEdgesForEmitEdge( + final Edge emitEdge, + final Sync emitSync, + final List remainingLocs, + final Collection> accumulator) { assert emitEdge.getSync().isPresent(); assert emitEdge.getSync().get().equals(emitSync); assert emitSync.getKind().equals(EMIT); @@ -147,10 +159,12 @@ private static Collection> recvEdgesForEmitEdge(final Edge emitEdge, } } - - private static void addBinaryActionsForEdge(final Collection result, - final XtaSystem system, - final XtaState state, final Edge emitEdge, final Sync emitSync) { + private static void addBinaryActionsForEdge( + final Collection result, + final XtaSystem system, + final XtaState state, + final Edge emitEdge, + final Sync emitSync) { assert emitEdge.getSync().isPresent(); assert emitEdge.getSync().get().equals(emitSync); assert emitSync.getKind().equals(EMIT); @@ -164,7 +178,8 @@ private static void addBinaryActionsForEdge(final Collection result, continue; } - if (state.isCommitted() && emitLoc.getKind() != COMMITTED + if (state.isCommitted() + && emitLoc.getKind() != COMMITTED && recvLoc.getKind() != COMMITTED) { continue; } @@ -182,17 +197,19 @@ private static void addBinaryActionsForEdge(final Collection result, final Label recvLabel = recvSync.getLabel(); if (emitLabel.equals(recvLabel)) { - final XtaAction action = XtaAction.binary(system, state.getLocs(), emitEdge, - recvEdge); + final XtaAction action = + XtaAction.binary(system, state.getLocs(), emitEdge, recvEdge); result.add(action); } } } } - private static void addBasicActionsForEdge(final Collection result, - final XtaSystem system, - final XtaState state, final Edge edge) { + private static void addBasicActionsForEdge( + final Collection result, + final XtaSystem system, + final XtaState state, + final Edge edge) { final Loc loc = edge.getSource(); if (state.isCommitted() && loc.getKind() != COMMITTED) { return; @@ -200,5 +217,4 @@ private static void addBasicActionsForEdge(final Collection result, final XtaAction action = XtaAction.basic(system, state.getLocs(), edge); result.add(action); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaOrd.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaOrd.java index c447504155..acd729f2aa 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaOrd.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -36,8 +36,7 @@ public static XtaOrd create(final PartialOrd partialOrd) public boolean isLeq(final XtaState state1, final XtaState state2) { checkNotNull(state1); checkNotNull(state2); - return state1.getLocs().equals(state2.getLocs()) && partialOrd.isLeq(state1.getState(), - state2.getState()); + return state1.getLocs().equals(state2.getLocs()) + && partialOrd.isLeq(state1.getState(), state2.getState()); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaState.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaState.java index 7d3716de69..5a1ed2c231 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaState.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.xta.analysis; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.expr.ExprState; @@ -23,13 +25,10 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.xta.XtaProcess.Loc; import hu.bme.mit.theta.xta.XtaProcess.LocKind; - import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - public final class XtaState implements ExprState { private static final int HASH_SEED = 8291; @@ -70,8 +69,8 @@ public static XtaState of(final List locs, final S sta return new XtaState<>(locs, state); } - public static Collection> collectionOf(final List locs, - final Collection states) { + public static Collection> collectionOf( + final List locs, final Collection states) { final Collection> result = new ArrayList<>(); for (final S state : states) { final XtaState initXtaState = XtaState.of(locs, state); @@ -142,9 +141,8 @@ public boolean equals(final Object obj) { @Override public String toString() { final String prefix = getClass().getSimpleName(); - final String locString = Utils.lispStringBuilder().addAll(locs.stream().map(Loc::getName)) - .toString(); + final String locString = + Utils.lispStringBuilder().addAll(locs.stream().map(Loc::getName)).toString(); return Utils.lispStringBuilder(prefix).add(locString).body().add(state).toString(); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaTransFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaTransFunc.java index 5dcd0c2da5..d1663a687e 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaTransFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/XtaTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,16 +18,15 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.List; - import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.xta.XtaProcess.Loc; +import java.util.Collection; +import java.util.List; -final class XtaTransFunc implements - TransFunc, XtaAction, P> { +final class XtaTransFunc + implements TransFunc, XtaAction, P> { private final TransFunc transFunc; @@ -41,17 +40,16 @@ public static XtaTransFunc create( } @Override - public Collection> getSuccStates(final XtaState state, final XtaAction action, - final P prec) { + public Collection> getSuccStates( + final XtaState state, final XtaAction action, final P prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); checkArgument(state.getLocs().equals(action.getSourceLocs())); final List succLocs = action.getTargetLocs(); final S subState = state.getState(); - final Collection succSubStates = transFunc.getSuccStates(subState, action, - prec); + final Collection succSubStates = + transFunc.getSuccStates(subState, action, prec); return XtaState.collectionOf(succLocs, succSubStates); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplAnalysis.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplAnalysis.java index 032b54def3..fb0bab6d7d 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplAnalysis.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expl.ExplOrd; import hu.bme.mit.theta.analysis.expl.ExplState; @@ -56,5 +56,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplInitFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplInitFunc.java index 423d73e35d..97bfd227d5 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplInitFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.xta.analysis.expl; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Collections.singleton; + import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.unit.UnitPrec; import hu.bme.mit.theta.xta.XtaSystem; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.Collections.singleton; - final class XtaExplInitFunc implements InitFunc { private final XtaSystem system; @@ -43,5 +42,4 @@ public Collection getInitStates(final UnitPrec prec) { final ExplState initState = ExplState.of(system.getInitVal()); return singleton(initState); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplTransFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplTransFunc.java index 46bab23b1f..8d112b30dc 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplTransFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,13 +18,12 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; - import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.unit.UnitPrec; import hu.bme.mit.theta.xta.XtaSystem; import hu.bme.mit.theta.xta.analysis.XtaAction; +import java.util.Collection; final class XtaExplTransFunc implements TransFunc { @@ -38,12 +37,11 @@ public static XtaExplTransFunc create(final XtaSystem system) { } @Override - public Collection getSuccStates(final ExplState state, final XtaAction action, - final UnitPrec prec) { + public Collection getSuccStates( + final ExplState state, final XtaAction action, final UnitPrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); return singleton(XtaExplUtils.post(state, action)); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplUtils.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplUtils.java index d3f8363c34..5004c1b36b 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplUtils.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/XtaExplUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,15 @@ */ package hu.bme.mit.theta.xta.analysis.expl; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.common.collect.Streams.zip; +import static hu.bme.mit.theta.core.stmt.Stmts.Assume; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.*; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.Lists; import com.google.common.collect.Streams; import hu.bme.mit.theta.analysis.expl.ExplState; @@ -39,30 +48,19 @@ import hu.bme.mit.theta.xta.analysis.XtaAction.BasicXtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BinaryXtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BroadcastXtaAction; - import java.util.Collection; import java.util.List; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; -import static com.google.common.collect.Streams.zip; -import static hu.bme.mit.theta.core.stmt.Stmts.Assume; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.*; -import static java.util.stream.Collectors.toList; - - public final class XtaExplUtils { - private XtaExplUtils() { - } + private XtaExplUtils() {} public static Valuation interpolate(final Valuation valA, final Expr exprB) { - final Collection> vars = ExprUtils.getVars(exprB).stream() - .filter(valA.getDecls()::contains) - .collect(toList()); + final Collection> vars = + ExprUtils.getVars(exprB).stream() + .filter(valA.getDecls()::contains) + .collect(toList()); final MutableValuation valI = new MutableValuation(); for (final VarDecl var : vars) { final LitExpr val = valA.eval(var).get(); @@ -120,8 +118,8 @@ private static ExplState postForBasicAction(final Valuation val, final BasicXtaA return ExplState.of(succVal); } - private static ExplState postForBinaryAction(final Valuation val, - final BinaryXtaAction action) { + private static ExplState postForBinaryAction( + final Valuation val, final BinaryXtaAction action) { final Edge emitEdge = action.getEmitEdge(); final Edge recvEdge = action.getRecvEdge(); final List targetLocs = action.getTargetLocs(); @@ -149,15 +147,14 @@ private static ExplState postForBinaryAction(final Valuation val, return ExplState.of(succVal); } - private static ExplState postForBroadcastAction(final Valuation val, - final BroadcastXtaAction action) { + private static ExplState postForBroadcastAction( + final Valuation val, final BroadcastXtaAction action) { final Edge emitEdge = action.getEmitEdge(); final List recvEdges = action.getRecvEdges(); final List> nonRecvEdges = action.getNonRecvEdges(); final List targetLocs = action.getTargetLocs(); - if (recvEdges.stream().anyMatch(recvEdge -> - !checkSync(emitEdge, recvEdge, val))) { + if (recvEdges.stream().anyMatch(recvEdge -> !checkSync(emitEdge, recvEdge, val))) { return ExplState.bottom(); } @@ -165,13 +162,18 @@ private static ExplState postForBroadcastAction(final Valuation val, return ExplState.bottom(); } - if (recvEdges.stream().anyMatch(recvEdge -> - !checkGuards(recvEdge, val))) { + if (recvEdges.stream().anyMatch(recvEdge -> !checkGuards(recvEdge, val))) { return ExplState.bottom(); } - if (nonRecvEdges.stream().anyMatch(c -> c.stream().anyMatch(nonRecvEdge -> - nonRecvEdgeDefinitelyEnabled(emitEdge, nonRecvEdge, val)))) { + if (nonRecvEdges.stream() + .anyMatch( + c -> + c.stream() + .anyMatch( + nonRecvEdge -> + nonRecvEdgeDefinitelyEnabled( + emitEdge, nonRecvEdge, val)))) { return ExplState.bottom(); } @@ -187,8 +189,8 @@ private static ExplState postForBroadcastAction(final Valuation val, return ExplState.of(succVal); } - private static boolean nonRecvEdgeDefinitelyEnabled(final Edge emitEdge, final Edge nonRecvEdge, - final Valuation val) { + private static boolean nonRecvEdgeDefinitelyEnabled( + final Edge emitEdge, final Edge nonRecvEdge, final Valuation val) { for (final Guard guard : nonRecvEdge.getGuards()) { if (guard.isDataGuard()) { final DataGuard dataGuard = guard.asDataGuard(); @@ -201,20 +203,20 @@ private static boolean nonRecvEdgeDefinitelyEnabled(final Edge emitEdge, final E final List> emitArgs = emitEdge.getSync().get().getArgs(); final List> recvArgs = nonRecvEdge.getSync().get().getArgs(); - if (zip(emitArgs.stream(), recvArgs.stream(), - (e, r) -> !e.eval(val).equals(r.eval(val))).anyMatch(x -> x)) { + if (zip(emitArgs.stream(), recvArgs.stream(), (e, r) -> !e.eval(val).equals(r.eval(val))) + .anyMatch(x -> x)) { return false; } return true; } - private static boolean checkSync(final Edge emitEdge, final Edge recvEdge, - final Valuation val) { + private static boolean checkSync( + final Edge emitEdge, final Edge recvEdge, final Valuation val) { final List> emitArgs = emitEdge.getSync().get().getArgs(); final List> recvArgs = recvEdge.getSync().get().getArgs(); - return zip(emitArgs.stream(), recvArgs.stream(), - (e, r) -> e.eval(val).equals(r.eval(val))).allMatch(x -> x); + return zip(emitArgs.stream(), recvArgs.stream(), (e, r) -> e.eval(val).equals(r.eval(val))) + .allMatch(x -> x); } private static boolean checkGuards(final Edge edge, final Valuation val) { @@ -239,8 +241,8 @@ private static boolean checkDataInvariants(final List locs, final Valuation final Collection invars = loc.getInvars(); for (final Guard invar : invars) { if (invar.isDataGuard()) { - final Expr expr = ExprUtils.simplify(invar.asDataGuard().toExpr(), - val); + final Expr expr = + ExprUtils.simplify(invar.asDataGuard().toExpr(), val); if (expr instanceof FalseExpr) { return false; } @@ -284,8 +286,8 @@ public static Expr pre(final Expr expr, final XtaAction acti } } - private static Expr preForBasicAction(final Expr expr, - final BasicXtaAction action) { + private static Expr preForBasicAction( + final Expr expr, final BasicXtaAction action) { final Edge edge = action.getEdge(); final WpState wp0 = WpState.of(expr); final WpState wp1 = applyInverseUpdates(wp0, edge); @@ -293,8 +295,8 @@ private static Expr preForBasicAction(final Expr expr, return wp2.getExpr(); } - private static Expr preForBinaryAction(final Expr expr, - final BinaryXtaAction action) { + private static Expr preForBinaryAction( + final Expr expr, final BinaryXtaAction action) { final Edge emitEdge = action.getEmitEdge(); final Edge recvEdge = action.getRecvEdge(); final WpState wp0 = WpState.of(expr); @@ -306,8 +308,8 @@ private static Expr preForBinaryAction(final Expr expr, return wp5.getExpr(); } - private static Expr preForBroadcastAction(final Expr expr, - final BroadcastXtaAction action) { + private static Expr preForBroadcastAction( + final Expr expr, final BroadcastXtaAction action) { final Edge emitEdge = action.getEmitEdge(); final List recvEdges = action.getRecvEdges(); final List reverseRecvEdges = Lists.reverse(recvEdges); @@ -362,29 +364,30 @@ private static WpState applyGuards(final WpState state, final Edge edge) { return res; } - private static WpState applySync(final WpState state, final Edge emitEdge, - final Edge recvEdge) { + private static WpState applySync( + final WpState state, final Edge emitEdge, final Edge recvEdge) { final Stream> emitArgs = emitEdge.getSync().get().getArgs().stream(); final Stream> recvArgs = recvEdge.getSync().get().getArgs().stream(); - final List> exprs = zip(emitArgs, recvArgs, - (e, r) -> (Expr) Eq(e, r)) - .collect(toImmutableList()); + final List> exprs = + zip(emitArgs, recvArgs, (e, r) -> (Expr) Eq(e, r)) + .collect(toImmutableList()); final Expr andExpr = And(exprs); return state.wep(Assume(andExpr)); } - private static WpState applyNonRecvEdge(final WpState state, final Edge emitEdge, - final Edge nonRecvEdge) { + private static WpState applyNonRecvEdge( + final WpState state, final Edge emitEdge, final Edge nonRecvEdge) { final Stream> emitArgs = emitEdge.getSync().get().getArgs().stream(); final Stream> nonRecvArgs = nonRecvEdge.getSync().get().getArgs().stream(); - final Stream> notEqExprs = zip(emitArgs, nonRecvArgs, - (e, r) -> Not(Eq(e, r))); - final Stream> notGuards = nonRecvEdge.getGuards().stream() - .filter(Guard::isDataGuard) - .map(Guard::toExpr) - .map(SmartBoolExprs::Not); - final List> exprs = Streams.concat(notEqExprs, notGuards) - .collect(toImmutableList()); + final Stream> notEqExprs = + zip(emitArgs, nonRecvArgs, (e, r) -> Not(Eq(e, r))); + final Stream> notGuards = + nonRecvEdge.getGuards().stream() + .filter(Guard::isDataGuard) + .map(Guard::toExpr) + .map(SmartBoolExprs::Not); + final List> exprs = + Streams.concat(notEqExprs, notGuards).collect(toImmutableList()); return state.wep(Assume(Or(exprs))); } } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplAnalysis.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplAnalysis.java index 7844f33c8c..8b6c5b73fe 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplAnalysis.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,8 +25,8 @@ import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.unit.UnitPrec; -public final class ItpExplAnalysis implements - Analysis { +public final class ItpExplAnalysis + implements Analysis { private final InitFunc initFunc; private final TransFunc transFunc; @@ -56,5 +56,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplInitFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplInitFunc.java index 9f29f0b6e3..747879ce1a 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplInitFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,12 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.unit.UnitPrec; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; final class ItpExplInitFunc implements InitFunc { @@ -55,5 +54,4 @@ public Collection getInitStates(final UnitPrec prec) { return result; } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplOrd.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplOrd.java index ef6e67c49a..5ca79cfe36 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplOrd.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,7 @@ final class ItpExplOrd implements PartialOrd { - private ItpExplOrd() { - } + private ItpExplOrd() {} private static final class LazyHolder { @@ -41,5 +40,4 @@ public boolean isLeq(final ItpExplState state1, final ItpExplState state2) { return state1.getAbstrState().isLeq(state2.getAbstrState()); } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplState.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplState.java index 72e4c95b65..dcb336606f 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplState.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.xta.analysis.expl.itp; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - public final class ItpExplState implements ExprState { private final ExplState concrState; @@ -90,8 +90,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ItpExplState that = (ItpExplState) obj; - return this.concrState.equals(that.concrState) && this.abstrState.equals( - that.abstrState); + return this.concrState.equals(that.concrState) + && this.abstrState.equals(that.abstrState); } else { return false; } @@ -99,8 +99,10 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).body().add(concrState) - .add(abstrState).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .body() + .add(concrState) + .add(abstrState) + .toString(); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplTransFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplTransFunc.java index 84e3ed3dc4..1c0a83ec65 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplTransFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/expl/itp/ItpExplTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.unit.UnitPrec; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; final class ItpExplTransFunc implements TransFunc { @@ -40,15 +39,15 @@ public static final ItpExplTransFunc create( } @Override - public Collection getSuccStates(final ItpExplState state, final A action, - final UnitPrec prec) { + public Collection getSuccStates( + final ItpExplState state, final A action, final UnitPrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); final ExplState subState = state.getConcrState(); - final Collection subSuccStates = transFunc.getSuccStates(subState, - action, prec); + final Collection subSuccStates = + transFunc.getSuccStates(subState, action, prec); if (subSuccStates.isEmpty()) { final ItpExplState succState = ItpExplState.of(ExplState.bottom(), ExplState.top()); @@ -62,5 +61,4 @@ public Collection getSuccStates(final ItpExplState state, final A return result; } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/AlgorithmStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/AlgorithmStrategy.java index 2234b5f49b..1d45f5af6c 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/AlgorithmStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/AlgorithmStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.xta.analysis.lazy; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; import hu.bme.mit.theta.analysis.unit.UnitPrec; import hu.bme.mit.theta.xta.analysis.XtaAction; import hu.bme.mit.theta.xta.analysis.lazy.LazyXtaStatistics.Builder; +import java.util.Collection; +import java.util.function.Function; interface AlgorithmStrategy { @@ -33,10 +32,16 @@ interface AlgorithmStrategy { boolean mightCover(final ArgNode coveree, ArgNode coverer); - void cover(ArgNode coveree, ArgNode coverer, - Collection> uncoveredNodes, final Builder stats); - - void block(ArgNode node, final XtaAction action, final S1 succState, - Collection> uncoveredNodes, final Builder stats); - + void cover( + ArgNode coveree, + ArgNode coverer, + Collection> uncoveredNodes, + final Builder stats); + + void block( + ArgNode node, + final XtaAction action, + final S1 succState, + Collection> uncoveredNodes, + final Builder stats); } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/BwItpExplStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/BwItpExplStrategy.java index 32a8f28b7c..595820fe4d 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/BwItpExplStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/BwItpExplStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,8 +17,6 @@ import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; -import java.util.Collection; - import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgEdge; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -33,6 +31,7 @@ import hu.bme.mit.theta.xta.analysis.expl.XtaExplUtils; import hu.bme.mit.theta.xta.analysis.expl.itp.ItpExplState; import hu.bme.mit.theta.xta.analysis.lazy.LazyXtaStatistics.Builder; +import java.util.Collection; final class BwItpExplStrategy extends ItpExplStrategy { @@ -41,8 +40,11 @@ public BwItpExplStrategy(final XtaSystem system, final Lens len } @Override - protected Valuation blockExpl(final ArgNode node, final Expr expr, - final Collection> uncoveredNodes, final Builder stats) { + protected Valuation blockExpl( + final ArgNode node, + final Expr expr, + final Collection> uncoveredNodes, + final Builder stats) { assert !node.getState().isBottom(); final ExplState abstractExpl = getLens().get(node.getState()).getAbstrState(); @@ -70,5 +72,4 @@ protected Valuation blockExpl(final ArgNode node, final Expr extends ItpZoneStrategy { @@ -33,8 +32,11 @@ public BwItpZoneStrategy(final XtaSystem system, final Lens len } @Override - protected ZoneState blockZone(final ArgNode node, final ZoneState zone, - final Collection> uncoveredNodes, final Builder stats) { + protected ZoneState blockZone( + final ArgNode node, + final ZoneState zone, + final Collection> uncoveredNodes, + final Builder stats) { final ZoneState abstrState = getLens().get(node.getState()).getAbstrState(); if (abstrState.isConsistentWith(zone)) { stats.refineZone(); @@ -61,5 +63,4 @@ protected ZoneState blockZone(final ArgNode node, final ZoneState return abstrState; } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategies.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategies.java index 9ae3372de5..e9066d0adb 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategies.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategies.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,25 +24,28 @@ final class ClockStrategies { - private ClockStrategies() { - } + private ClockStrategies() {} - public static AlgorithmStrategy>, LuZoneState> createLuStrategy( - final XtaSystem system) { + public static + AlgorithmStrategy>, LuZoneState> createLuStrategy( + final XtaSystem system) { return new LuZoneStrategy<>(system, createRightLens()); } - public static AlgorithmStrategy>, ItpZoneState> createFwItpStrategy( - final XtaSystem system) { + public static + AlgorithmStrategy>, ItpZoneState> + createFwItpStrategy(final XtaSystem system) { return new FwItpZoneStrategy<>(system, createRightLens()); } - public static AlgorithmStrategy>, ItpZoneState> createBwItpStrategy( - final XtaSystem system) { + public static + AlgorithmStrategy>, ItpZoneState> + createBwItpStrategy(final XtaSystem system) { return new BwItpZoneStrategy<>(system, createRightLens()); } - private static Lens>, S2> createRightLens() { + private static + Lens>, S2> createRightLens() { return new Lens>, S2>() { @Override public S2 get(final XtaState> state) { @@ -50,8 +53,8 @@ public S2 get(final XtaState> state) { } @Override - public XtaState> set(final XtaState> state, - final S2 s2) { + public XtaState> set( + final XtaState> state, final S2 s2) { final Prod2State prodState = state.getState(); final Prod2State newProdState = prodState.with2(s2); final XtaState> newState = state.withState(newProdState); @@ -59,5 +62,4 @@ public XtaState> set(final XtaState> state } }; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategy.java index 3412d55f40..c6f0050ad4 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ClockStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.xta.analysis.lazy; public enum ClockStrategy { - LU, FWITP, BWITP; + LU, + FWITP, + BWITP; } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/CombinedStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/CombinedStrategy.java index a24622cd08..c969f0ae30 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/CombinedStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/CombinedStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -34,6 +31,8 @@ import hu.bme.mit.theta.xta.analysis.XtaAnalysis; import hu.bme.mit.theta.xta.analysis.XtaState; import hu.bme.mit.theta.xta.analysis.lazy.LazyXtaStatistics.Builder; +import java.util.Collection; +import java.util.function.Function; final class CombinedStrategy implements AlgorithmStrategy>, XtaState>> { @@ -43,14 +42,19 @@ final class CombinedStrategy private final Analysis>, XtaAction, UnitPrec> analysis; private final Function>, ?> projection; - public CombinedStrategy(final XtaSystem system, - final AlgorithmStrategy>, S1> strategy1, - final AlgorithmStrategy>, S2> strategy2) { + public CombinedStrategy( + final XtaSystem system, + final AlgorithmStrategy>, S1> strategy1, + final AlgorithmStrategy>, S2> strategy2) { this.strategy1 = checkNotNull(strategy1); this.strategy2 = checkNotNull(strategy2); this.analysis = createAnalysis(system); - projection = s -> Tuple3.of(strategy1.getProjection().apply(s.getState().getState1()), - strategy2.getProjection().apply(s.getState().getState2()), s.getLocs()); + projection = + s -> + Tuple3.of( + strategy1.getProjection().apply(s.getState().getState1()), + strategy2.getProjection().apply(s.getState().getState2()), + s.getLocs()); } @Override @@ -64,18 +68,20 @@ public Analysis>, XtaAction, UnitPrec> getAnalysis() } @Override - public boolean mightCover(final ArgNode>, XtaAction> coveree, - final ArgNode>, XtaAction> coverer) { + public boolean mightCover( + final ArgNode>, XtaAction> coveree, + final ArgNode>, XtaAction> coverer) { return strategy1.mightCover(coveree, coverer) && strategy2.mightCover(coveree, coverer); } @Override - public void cover(final ArgNode>, XtaAction> coveree, - final ArgNode>, XtaAction> coverer, - final Collection>, XtaAction>> uncoveredNodes, - final Builder stats) { - assert coveree.getCoveringNode().isPresent() && coveree.getCoveringNode().get() - .equals(coverer); + public void cover( + final ArgNode>, XtaAction> coveree, + final ArgNode>, XtaAction> coverer, + final Collection>, XtaAction>> uncoveredNodes, + final Builder stats) { + assert coveree.getCoveringNode().isPresent() + && coveree.getCoveringNode().get().equals(coverer); strategy1.cover(coveree, coverer, uncoveredNodes, stats); if (coveree.isCovered()) { assert (!uncoveredNodes.contains(coveree)); @@ -84,11 +90,12 @@ public void cover(final ArgNode>, XtaAction> coveree } @Override - public void block(final ArgNode>, XtaAction> node, - final XtaAction action, - final XtaState> succState, - final Collection>, XtaAction>> uncoveredNodes, - final Builder stats) { + public void block( + final ArgNode>, XtaAction> node, + final XtaAction action, + final XtaState> succState, + final Collection>, XtaAction>> uncoveredNodes, + final Builder stats) { assert succState.isBottom(); if (succState.getState().isBottom1()) { strategy1.block(node, action, succState, uncoveredNodes, stats); @@ -105,15 +112,14 @@ private Analysis>, XtaAction, UnitPrec> createAnalys final XtaSystem system) { final Analysis analysis1 = strategy1.getAnalysis(); final Analysis analysis2 = strategy2.getAnalysis(); - final Analysis, XtaAction, Prod2Prec> prodAnalysis = Prod2Analysis - .create(analysis1, analysis2); - final Analysis>, XtaAction, Prod2Prec> xtaAnalysis = XtaAnalysis - .create(system, prodAnalysis); - final Prod2Prec prec = Prod2Prec.of(UnitPrec.getInstance(), - UnitPrec.getInstance()); - final Analysis>, XtaAction, UnitPrec> analysis = PrecMappingAnalysis - .create(xtaAnalysis, p -> prec); + final Analysis, XtaAction, Prod2Prec> prodAnalysis = + Prod2Analysis.create(analysis1, analysis2); + final Analysis>, XtaAction, Prod2Prec> + xtaAnalysis = XtaAnalysis.create(system, prodAnalysis); + final Prod2Prec prec = + Prod2Prec.of(UnitPrec.getInstance(), UnitPrec.getInstance()); + final Analysis>, XtaAction, UnitPrec> analysis = + PrecMappingAnalysis.create(xtaAnalysis, p -> prec); return analysis; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategies.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategies.java index 202042c2c5..541e1e54fd 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategies.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategies.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,25 +24,28 @@ final class DataStrategies { - private DataStrategies() { - } + private DataStrategies() {} - public static AlgorithmStrategy>, ExplState> createExplStrategy( - final XtaSystem system) { + public static + AlgorithmStrategy>, ExplState> createExplStrategy( + final XtaSystem system) { return new ExplStrategy<>(system, createLeftLens()); } - public static AlgorithmStrategy>, ItpExplState> createFwItpStrategy( - final XtaSystem system) { + public static + AlgorithmStrategy>, ItpExplState> + createFwItpStrategy(final XtaSystem system) { return new FwItpExplStrategy<>(system, createLeftLens()); } - public static AlgorithmStrategy>, ItpExplState> createBwItpStrategy( - final XtaSystem system) { + public static + AlgorithmStrategy>, ItpExplState> + createBwItpStrategy(final XtaSystem system) { return new BwItpExplStrategy<>(system, createLeftLens()); } - private static Lens>, S1> createLeftLens() { + private static + Lens>, S1> createLeftLens() { return new Lens>, S1>() { @Override public S1 get(final XtaState> state) { @@ -50,8 +53,8 @@ public S1 get(final XtaState> state) { } @Override - public XtaState> set(final XtaState> state, - final S1 s1) { + public XtaState> set( + final XtaState> state, final S1 s1) { final Prod2State prodState = state.getState(); final Prod2State newProdState = prodState.with1(s1); final XtaState> newState = state.withState(newProdState); diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategy.java index 16d552c028..62f5fd53c4 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/DataStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.xta.analysis.lazy; public enum DataStrategy { - NONE, FWITP, BWITP + NONE, + FWITP, + BWITP } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ExplStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ExplStrategy.java index 7da372b46d..6a6ffbb8f4 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ExplStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ExplStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -29,6 +26,8 @@ import hu.bme.mit.theta.xta.analysis.XtaAction; import hu.bme.mit.theta.xta.analysis.expl.XtaExplAnalysis; import hu.bme.mit.theta.xta.analysis.lazy.LazyXtaStatistics.Builder; +import java.util.Collection; +import java.util.function.Function; final class ExplStrategy implements AlgorithmStrategy { @@ -54,21 +53,26 @@ public Analysis getAnalysis() { } @Override - public boolean mightCover(final ArgNode coveree, - final ArgNode coverer) { + public boolean mightCover( + final ArgNode coveree, final ArgNode coverer) { assert lens.get(coveree.getState()).equals(lens.get(coverer.getState())); return true; } @Override - public void cover(final ArgNode coveree, final ArgNode coverer, - final Collection> uncoveredNodes, final Builder stats) { - } + public void cover( + final ArgNode coveree, + final ArgNode coverer, + final Collection> uncoveredNodes, + final Builder stats) {} @Override - public void block(final ArgNode node, final XtaAction action, final S succState, - final Collection> uncoveredNodes, final Builder stats) { + public void block( + final ArgNode node, + final XtaAction action, + final S succState, + final Collection> uncoveredNodes, + final Builder stats) { assert lens.get(succState).isBottom(); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/FwItpExplStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/FwItpExplStrategy.java index 9f728ebc9c..d18de03e94 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/FwItpExplStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/FwItpExplStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,8 +15,6 @@ */ package hu.bme.mit.theta.xta.analysis.lazy; -import java.util.Collection; - import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgEdge; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -31,6 +29,7 @@ import hu.bme.mit.theta.xta.analysis.expl.XtaExplUtils; import hu.bme.mit.theta.xta.analysis.expl.itp.ItpExplState; import hu.bme.mit.theta.xta.analysis.lazy.LazyXtaStatistics.Builder; +import java.util.Collection; final class FwItpExplStrategy extends ItpExplStrategy { @@ -39,8 +38,11 @@ public FwItpExplStrategy(final XtaSystem system, final Lens len } @Override - protected Valuation blockExpl(final ArgNode node, final Expr expr, - final Collection> uncoveredNodes, final Builder stats) { + protected Valuation blockExpl( + final ArgNode node, + final Expr expr, + final Collection> uncoveredNodes, + final Builder stats) { final ExplState abstrState = getLens().get(node.getState()).getAbstrState(); final Expr simplifiedExpr = ExprUtils.simplify(expr, abstrState); @@ -78,5 +80,4 @@ protected Valuation blockExpl(final ArgNode node, final Expr extends ItpZoneStrategy { @@ -33,8 +32,11 @@ public FwItpZoneStrategy(final XtaSystem system, final Lens len } @Override - protected ZoneState blockZone(final ArgNode node, final ZoneState zone, - final Collection> uncoveredNodes, final Builder stats) { + protected ZoneState blockZone( + final ArgNode node, + final ZoneState zone, + final Collection> uncoveredNodes, + final Builder stats) { final ZoneState abstrState = getLens().get(node.getState()).getAbstrState(); if (abstrState.isConsistentWith(zone)) { stats.refineZone(); @@ -69,5 +71,4 @@ protected ZoneState blockZone(final ArgNode node, final ZoneState return abstrState; } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpExplStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpExplStrategy.java index 7be0ced1a0..5bc5ad2b5a 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpExplStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpExplStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,17 +21,12 @@ import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; import static java.util.stream.Collectors.toList; -import java.util.Collection; - -import hu.bme.mit.theta.common.container.Containers; - -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.unit.UnitPrec; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; @@ -44,6 +39,8 @@ import hu.bme.mit.theta.xta.analysis.expl.itp.ItpExplAnalysis; import hu.bme.mit.theta.xta.analysis.expl.itp.ItpExplState; import hu.bme.mit.theta.xta.analysis.lazy.LazyXtaStatistics.Builder; +import java.util.Collection; +import java.util.function.Function; abstract class ItpExplStrategy implements AlgorithmStrategy { @@ -68,17 +65,19 @@ public final Analysis getAnalysis() { } @Override - public final boolean mightCover(final ArgNode coveree, - final ArgNode coverer) { + public final boolean mightCover( + final ArgNode coveree, final ArgNode coverer) { final ExplState covereeExpl = lens.get(coveree.getState()).getConcrState(); final ExplState covererExpl = lens.get(coverer.getState()).getAbstrState(); return covereeExpl.isLeq(covererExpl); } @Override - public final void cover(final ArgNode coveree, - final ArgNode coverer, - final Collection> uncoveredNodes, final Builder stats) { + public final void cover( + final ArgNode coveree, + final ArgNode coverer, + final Collection> uncoveredNodes, + final Builder stats) { stats.startCloseExplRefinement(); final ItpExplState covererState = lens.get(coverer.getState()); blockExpl(coveree, Not(covererState.toExpr()), uncoveredNodes, stats); @@ -86,9 +85,12 @@ public final void cover(final ArgNode coveree, } @Override - public final void block(final ArgNode node, final XtaAction action, - final S succState, - final Collection> uncoveredNodes, final Builder stats) { + public final void block( + final ArgNode node, + final XtaAction action, + final S succState, + final Collection> uncoveredNodes, + final Builder stats) { assert lens.get(succState).isBottom(); stats.startExpandExplRefinement(); final Expr preImage = XtaExplUtils.pre(True(), action); @@ -98,9 +100,11 @@ public final void block(final ArgNode node, final XtaAction action //// - protected abstract Valuation blockExpl(final ArgNode node, - final Expr expr, - final Collection> uncoveredNodes, final Builder stats); + protected abstract Valuation blockExpl( + final ArgNode node, + final Expr expr, + final Collection> uncoveredNodes, + final Builder stats); protected final Lens getLens() { return lens; @@ -127,19 +131,21 @@ protected final void strengthen(final ArgNode node, final Valuatio node.setState(newState); } - protected final void maintainCoverage(final ArgNode node, - final Valuation interpolant, - final Collection> uncoveredNodes) { - final Collection> uncovered = node.getCoveredNodes() - .filter(covered -> shouldUncover(covered, interpolant)).collect(toList()); + protected final void maintainCoverage( + final ArgNode node, + final Valuation interpolant, + final Collection> uncoveredNodes) { + final Collection> uncovered = + node.getCoveredNodes() + .filter(covered -> shouldUncover(covered, interpolant)) + .collect(toList()); uncoveredNodes.addAll(uncovered); uncovered.forEach(ArgNode::unsetCoveringNode); } - private boolean shouldUncover(final ArgNode covered, - final Valuation interpolant) { + private boolean shouldUncover( + final ArgNode covered, final Valuation interpolant) { final ItpExplState coveredExpl = lens.get(covered.getState()); return !coveredExpl.getAbstrState().isLeq(interpolant); } - -} \ No newline at end of file +} diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpZoneStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpZoneStrategy.java index 7b404308cc..8e6a0a21dc 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpZoneStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/ItpZoneStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,6 @@ import static hu.bme.mit.theta.common.Unit.unit; import static java.util.stream.Collectors.toList; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; @@ -36,6 +33,8 @@ import hu.bme.mit.theta.xta.analysis.zone.XtaZoneUtils; import hu.bme.mit.theta.xta.analysis.zone.itp.ItpZoneAnalysis; import hu.bme.mit.theta.xta.analysis.zone.itp.ItpZoneState; +import java.util.Collection; +import java.util.function.Function; abstract class ItpZoneStrategy implements AlgorithmStrategy { @@ -48,8 +47,9 @@ public ItpZoneStrategy(final XtaSystem system, final Lens lens) checkNotNull(system); this.lens = checkNotNull(lens); prec = ZonePrec.of(system.getClockVars()); - analysis = PrecMappingAnalysis.create(ItpZoneAnalysis.create(XtaZoneAnalysis.getInstance()), - p -> prec); + analysis = + PrecMappingAnalysis.create( + ItpZoneAnalysis.create(XtaZoneAnalysis.getInstance()), p -> prec); projection = s -> unit(); } @@ -64,17 +64,19 @@ public final Analysis getAnalysis() { } @Override - public final boolean mightCover(final ArgNode coveree, - final ArgNode coverer) { + public final boolean mightCover( + final ArgNode coveree, final ArgNode coverer) { final ZoneState covereeZone = lens.get(coveree.getState()).getConcrState(); final ZoneState covererZone = lens.get(coverer.getState()).getAbstrState(); return covereeZone.isLeq(covererZone); } @Override - public final void cover(final ArgNode coveree, - final ArgNode coverer, - final Collection> uncoveredNodes, final Builder stats) { + public final void cover( + final ArgNode coveree, + final ArgNode coverer, + final Collection> uncoveredNodes, + final Builder stats) { stats.startCloseZoneRefinement(); final ItpZoneState covererState = lens.get(coverer.getState()); final Collection complementZones = covererState.getAbstrState().complement(); @@ -85,9 +87,12 @@ public final void cover(final ArgNode coveree, } @Override - public final void block(final ArgNode node, final XtaAction action, - final S succState, - final Collection> uncoveredNodes, final Builder stats) { + public final void block( + final ArgNode node, + final XtaAction action, + final S succState, + final Collection> uncoveredNodes, + final Builder stats) { assert lens.get(succState).isBottom(); stats.startExpandZoneRefinement(); final ZoneState preImage = pre(ZoneState.top(), action); @@ -97,8 +102,11 @@ public final void block(final ArgNode node, final XtaAction action //// - protected abstract ZoneState blockZone(final ArgNode node, final ZoneState zone, - final Collection> uncoveredNodes, final Builder stats); + protected abstract ZoneState blockZone( + final ArgNode node, + final ZoneState zone, + final Collection> uncoveredNodes, + final Builder stats); protected final Lens getLens() { return lens; @@ -122,19 +130,21 @@ protected final void strengthen(final ArgNode node, final ZoneStat node.setState(newState); } - protected final void maintainCoverage(final ArgNode node, - final ZoneState interpolant, - final Collection> uncoveredNodes) { - final Collection> uncovered = node.getCoveredNodes() - .filter(covered -> shouldUncover(covered, interpolant)).collect(toList()); + protected final void maintainCoverage( + final ArgNode node, + final ZoneState interpolant, + final Collection> uncoveredNodes) { + final Collection> uncovered = + node.getCoveredNodes() + .filter(covered -> shouldUncover(covered, interpolant)) + .collect(toList()); uncoveredNodes.addAll(uncovered); uncovered.forEach(ArgNode::unsetCoveringNode); } - private boolean shouldUncover(final ArgNode covered, - final ZoneState interpolant) { + private boolean shouldUncover( + final ArgNode covered, final ZoneState interpolant) { final ItpZoneState coveredState = lens.get(covered.getState()); return !coveredState.getAbstrState().isLeq(interpolant); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaChecker.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaChecker.java index 8b1c390b0e..ecc7b5547b 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaChecker.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,17 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; - import com.google.common.collect.Lists; - import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.Trace; +import hu.bme.mit.theta.analysis.algorithm.SafetyChecker; import hu.bme.mit.theta.analysis.algorithm.SafetyResult; import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; -import hu.bme.mit.theta.analysis.algorithm.SafetyChecker; import hu.bme.mit.theta.analysis.algorithm.arg.SearchStrategy; import hu.bme.mit.theta.analysis.reachedset.Partition; import hu.bme.mit.theta.analysis.unit.UnitPrec; @@ -36,31 +32,37 @@ import hu.bme.mit.theta.xta.analysis.XtaAction; import hu.bme.mit.theta.xta.analysis.XtaLts; import hu.bme.mit.theta.xta.analysis.XtaState; +import java.util.ArrayList; +import java.util.Collection; -final class LazyXtaChecker implements - SafetyChecker, XtaAction>, Trace, XtaAction>, UnitPrec> { +final class LazyXtaChecker + implements SafetyChecker< + ARG, XtaAction>, Trace, XtaAction>, UnitPrec> { private final XtaLts lts; private final AlgorithmStrategy, XtaState> algorithmStrategy; private final SearchStrategy searchStrategy; - private LazyXtaChecker(final XtaSystem system, - final AlgorithmStrategy, XtaState> algorithmStrategy, - final SearchStrategy searchStrategy) { + private LazyXtaChecker( + final XtaSystem system, + final AlgorithmStrategy, XtaState> algorithmStrategy, + final SearchStrategy searchStrategy) { checkNotNull(system); lts = XtaLts.create(system); this.algorithmStrategy = checkNotNull(algorithmStrategy); this.searchStrategy = checkNotNull(searchStrategy); } - public static LazyXtaChecker create(final XtaSystem system, - final AlgorithmStrategy, XtaState> algorithmStrategy, - final SearchStrategy searchStrategy) { + public static LazyXtaChecker create( + final XtaSystem system, + final AlgorithmStrategy, XtaState> algorithmStrategy, + final SearchStrategy searchStrategy) { return new LazyXtaChecker<>(system, algorithmStrategy, searchStrategy); } @Override - public SafetyResult, XtaAction>, Trace, XtaAction>> check(final UnitPrec prec) { + public SafetyResult, XtaAction>, Trace, XtaAction>> check( + final UnitPrec prec) { return new CheckMethod().run(); } @@ -95,22 +97,25 @@ public SafetyResult, XtaAction>, Trace, XtaAction>> stats.stopAlgorithm(); final LazyXtaStatistics statistics = stats.build(); - final SafetyResult, XtaAction>, Trace, XtaAction>> result = SafetyResult.safe(arg, statistics); + final SafetyResult, XtaAction>, Trace, XtaAction>> result = + SafetyResult.safe(arg, statistics); return result; } private void init() { - final Collection> initStates = algorithmStrategy.getAnalysis() - .getInitFunc() - .getInitStates(UnitPrec.getInstance()); + final Collection> initStates = + algorithmStrategy + .getAnalysis() + .getInitFunc() + .getInitStates(UnitPrec.getInstance()); initStates.forEach(s -> arg.createInitNode(s, false)); } private void close(final ArgNode, XtaAction> coveree) { stats.startClosing(); - final Iterable, XtaAction>> candidates = Lists.reverse( - passed.get(coveree)); + final Iterable, XtaAction>> candidates = + Lists.reverse(passed.get(coveree)); for (final ArgNode, XtaAction> coverer : candidates) { stats.checkCoverage(); @@ -119,7 +124,8 @@ private void close(final ArgNode, XtaAction> coveree) { stats.attemptCoverage(); coveree.setCoveringNode(coverer); - final Collection, XtaAction>> uncoveredNodes = new ArrayList<>(); + final Collection, XtaAction>> uncoveredNodes = + new ArrayList<>(); algorithmStrategy.cover(coveree, coverer, uncoveredNodes, stats); waiting.addAll(uncoveredNodes.stream().filter(n -> !n.equals(coveree))); @@ -140,19 +146,21 @@ private void expand(final ArgNode, XtaAction> node) { final XtaState state = node.getState(); for (final XtaAction action : lts.getEnabledActionsFor(state)) { - final Collection> succStates = algorithmStrategy.getAnalysis() - .getTransFunc() - .getSuccStates(state, action, UnitPrec.getInstance()); + final Collection> succStates = + algorithmStrategy + .getAnalysis() + .getTransFunc() + .getSuccStates(state, action, UnitPrec.getInstance()); for (final XtaState succState : succStates) { if (succState.isBottom()) { - final Collection, XtaAction>> uncoveredNodes = new ArrayList<>(); + final Collection, XtaAction>> uncoveredNodes = + new ArrayList<>(); algorithmStrategy.block(node, action, succState, uncoveredNodes, stats); waiting.addAll(uncoveredNodes); } else { - final ArgNode, XtaAction> succNode = arg.createSuccNode(node, - action, succState, - false); + final ArgNode, XtaAction> succNode = + arg.createSuccNode(node, action, succState, false); waiting.add(succNode); } } @@ -162,5 +170,4 @@ private void expand(final ArgNode, XtaAction> node) { stats.stopExpanding(); } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaCheckerFactory.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaCheckerFactory.java index be93400c1e..3af6f9b817 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaCheckerFactory.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaCheckerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -26,36 +26,48 @@ public final class LazyXtaCheckerFactory { - private LazyXtaCheckerFactory() { - } + private LazyXtaCheckerFactory() {} - public static SafetyChecker, XtaAction>, ? extends Trace, XtaAction>, UnitPrec> create(final XtaSystem system, - final DataStrategy dataStrategy, final ClockStrategy clockStrategy, final SearchStrategy searchStrategy) { - final CombinedStrategy algorithmStrategy = combineStrategies(system, dataStrategy, clockStrategy); - final SafetyChecker, XtaAction>, ? extends Trace, XtaAction>, UnitPrec> checker = LazyXtaChecker.create( - system, - algorithmStrategy, searchStrategy); + public static SafetyChecker< + ? extends ARG, XtaAction>, + ? extends Trace, XtaAction>, + UnitPrec> + create( + final XtaSystem system, + final DataStrategy dataStrategy, + final ClockStrategy clockStrategy, + final SearchStrategy searchStrategy) { + final CombinedStrategy algorithmStrategy = + combineStrategies(system, dataStrategy, clockStrategy); + final SafetyChecker< + ? extends ARG, XtaAction>, + ? extends Trace, XtaAction>, + UnitPrec> + checker = LazyXtaChecker.create(system, algorithmStrategy, searchStrategy); return checker; } - private static CombinedStrategy combineStrategies(final XtaSystem system, - final DataStrategy dataStrategy, - final ClockStrategy clockStrategy) { + private static CombinedStrategy combineStrategies( + final XtaSystem system, + final DataStrategy dataStrategy, + final ClockStrategy clockStrategy) { switch (dataStrategy) { case BWITP: - switch (clockStrategy) { case BWITP: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createBwItpStrategy(system), ClockStrategies.createBwItpStrategy(system)); case FWITP: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createBwItpStrategy(system), ClockStrategies.createFwItpStrategy(system)); case LU: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createBwItpStrategy(system), ClockStrategies.createLuStrategy(system)); default: @@ -63,18 +75,20 @@ private LazyXtaCheckerFactory() { } case FWITP: - switch (clockStrategy) { case BWITP: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createFwItpStrategy(system), ClockStrategies.createBwItpStrategy(system)); case FWITP: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createFwItpStrategy(system), ClockStrategies.createFwItpStrategy(system)); case LU: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createFwItpStrategy(system), ClockStrategies.createLuStrategy(system)); default: @@ -82,18 +96,20 @@ private LazyXtaCheckerFactory() { } case NONE: - switch (clockStrategy) { case BWITP: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createExplStrategy(system), ClockStrategies.createBwItpStrategy(system)); case FWITP: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createExplStrategy(system), ClockStrategies.createFwItpStrategy(system)); case LU: - return new CombinedStrategy<>(system, + return new CombinedStrategy<>( + system, DataStrategies.createExplStrategy(system), ClockStrategies.createLuStrategy(system)); default: diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaStatistics.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaStatistics.java index f5cfbf5b53..9f71e34f3d 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaStatistics.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LazyXtaStatistics.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,9 +20,8 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS; import com.google.common.base.Stopwatch; - -import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.analysis.algorithm.Statistics; +import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.common.table.TableWriter; public final class LazyXtaStatistics extends Statistics { @@ -182,7 +181,16 @@ public void writeData(final TableWriter writer) { public static final class Builder { private enum State { - CREATED, RUNNING, EXPANDING, CLOSING, EXPAND_EXPL_REFINING, EXPAND_ZONE_REFINING, CLOSE_EXPL_REFINING, CLOSE_ZONE_REFINING, STOPPED, BUILT + CREATED, + RUNNING, + EXPANDING, + CLOSING, + EXPAND_EXPL_REFINING, + EXPAND_ZONE_REFINING, + CLOSE_EXPL_REFINING, + CLOSE_ZONE_REFINING, + STOPPED, + BUILT } private State state; @@ -332,6 +340,5 @@ public LazyXtaStatistics build() { state = State.BUILT; return new LazyXtaStatistics(this); } - } } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/Lens.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/Lens.java index 863e42bdd7..1408b78a42 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/Lens.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/Lens.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,5 +20,4 @@ public interface Lens { E get(T t); T set(T t, E e); - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LuZoneStrategy.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LuZoneStrategy.java index 3a02990343..5da3d893f3 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LuZoneStrategy.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/lazy/LuZoneStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,6 @@ import static hu.bme.mit.theta.common.Unit.unit; import static java.util.stream.Collectors.toList; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgEdge; @@ -37,6 +34,8 @@ import hu.bme.mit.theta.xta.analysis.zone.XtaZoneAnalysis; import hu.bme.mit.theta.xta.analysis.zone.lu.LuZoneAnalysis; import hu.bme.mit.theta.xta.analysis.zone.lu.LuZoneState; +import java.util.Collection; +import java.util.function.Function; final class LuZoneStrategy implements AlgorithmStrategy { @@ -48,8 +47,9 @@ public LuZoneStrategy(final XtaSystem system, final Lens lens) { checkNotNull(system); this.lens = checkNotNull(lens); final ZonePrec zonePrec = ZonePrec.of(system.getClockVars()); - analysis = PrecMappingAnalysis.create(LuZoneAnalysis.create(XtaZoneAnalysis.getInstance()), - p -> zonePrec); + analysis = + PrecMappingAnalysis.create( + LuZoneAnalysis.create(XtaZoneAnalysis.getInstance()), p -> zonePrec); projection = s -> unit(); } @@ -64,16 +64,19 @@ public Analysis getAnalysis() { } @Override - public boolean mightCover(final ArgNode coveree, - final ArgNode coverer) { + public boolean mightCover( + final ArgNode coveree, final ArgNode coverer) { final LuZoneState covereeState = lens.get(coveree.getState()); final LuZoneState covererState = lens.get(coverer.getState()); return covereeState.getZone().isLeq(covererState.getZone(), covererState.getBoundFunc()); } @Override - public void cover(final ArgNode coveree, final ArgNode coverer, - final Collection> uncoveredNodes, final Builder stats) { + public void cover( + final ArgNode coveree, + final ArgNode coverer, + final Collection> uncoveredNodes, + final Builder stats) { stats.startCloseZoneRefinement(); final LuZoneState covererState = lens.get(coverer.getState()); final BoundFunc boundFunc = covererState.getBoundFunc(); @@ -82,8 +85,12 @@ public void cover(final ArgNode coveree, final ArgNode node, final XtaAction action, final S succState, - final Collection> uncoveredNodes, final Builder stats) { + public void block( + final ArgNode node, + final XtaAction action, + final S succState, + final Collection> uncoveredNodes, + final Builder stats) { assert lens.get(succState).isBottom(); stats.startExpandZoneRefinement(); final BoundFunc preImage = XtaLuZoneUtils.pre(BoundFunc.top(), action); @@ -93,8 +100,11 @@ public void block(final ArgNode node, final XtaAction action, fina //// - private void propagateBounds(final ArgNode node, final BoundFunc boundFunc, - final Collection> uncoveredNodes, final Builder stats) { + private void propagateBounds( + final ArgNode node, + final BoundFunc boundFunc, + final Collection> uncoveredNodes, + final Builder stats) { final LuZoneState oldState = lens.get(node.getState()); final BoundFunc oldBoundFunc = oldState.getBoundFunc(); if (!boundFunc.isLeq(oldBoundFunc)) { @@ -123,22 +133,26 @@ private void strengthen(final ArgNode node, final BoundFunc boundF node.setState(newState); } - private void maintainCoverage(final ArgNode node, final BoundFunc interpolant, - final Collection> uncoveredNodes) { + private void maintainCoverage( + final ArgNode node, + final BoundFunc interpolant, + final Collection> uncoveredNodes) { final LuZoneState covererState = lens.get(node.getState()); - final Collection> uncovered = node.getCoveredNodes() - .filter(covered -> shouldUncover(covered, covererState, interpolant)).collect(toList()); + final Collection> uncovered = + node.getCoveredNodes() + .filter(covered -> shouldUncover(covered, covererState, interpolant)) + .collect(toList()); uncoveredNodes.addAll(uncovered); uncovered.forEach(ArgNode::unsetCoveringNode); } - private boolean shouldUncover(final ArgNode covered, - final LuZoneState covererState, - final BoundFunc interpolant) { + private boolean shouldUncover( + final ArgNode covered, + final LuZoneState covererState, + final BoundFunc interpolant) { final LuZoneState coveredState = lens.get(covered.getState()); return !interpolant.isLeq(coveredState.getBoundFunc()) || !coveredState.getZone().isLeq(covererState.getZone(), interpolant); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaActZoneUtils.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaActZoneUtils.java index 20b62a879e..ecee1e22a0 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaActZoneUtils.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaActZoneUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,13 +15,7 @@ */ package hu.bme.mit.theta.xta.analysis.zone; -import java.util.Collection; - import hu.bme.mit.theta.common.container.Containers; - -import java.util.List; -import java.util.Set; - import hu.bme.mit.theta.core.clock.op.ResetOp; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.rattype.RatType; @@ -32,14 +26,16 @@ import hu.bme.mit.theta.xta.analysis.XtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BasicXtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BinaryXtaAction; +import java.util.Collection; +import java.util.List; +import java.util.Set; public final class XtaActZoneUtils { - private XtaActZoneUtils() { - } + private XtaActZoneUtils() {} - public static Set> pre(final Set> activeVars, - final XtaAction action) { + public static Set> pre( + final Set> activeVars, final XtaAction action) { final Set> result = Containers.createSet(); final List sourceLocs = action.getSourceLocs(); @@ -137,5 +133,4 @@ public static Set> pre(final Set> activeVars, return result; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaLuZoneUtils.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaLuZoneUtils.java index 317f482d98..0c8eb21ede 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaLuZoneUtils.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaLuZoneUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,8 +15,6 @@ */ package hu.bme.mit.theta.xta.analysis.zone; -import java.util.List; - import hu.bme.mit.theta.analysis.zone.BoundFunc; import hu.bme.mit.theta.core.clock.op.ResetOp; import hu.bme.mit.theta.core.decl.VarDecl; @@ -28,11 +26,11 @@ import hu.bme.mit.theta.xta.analysis.XtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BasicXtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BinaryXtaAction; +import java.util.List; public final class XtaLuZoneUtils { - private XtaLuZoneUtils() { - } + private XtaLuZoneUtils() {} public static BoundFunc pre(final BoundFunc boundFunction, final XtaAction action) { if (action.isBasic()) { @@ -46,8 +44,8 @@ public static BoundFunc pre(final BoundFunc boundFunction, final XtaAction actio //// - private static BoundFunc preForBasicAction(final BoundFunc boundFunction, - final BasicXtaAction action) { + private static BoundFunc preForBasicAction( + final BoundFunc boundFunction, final BasicXtaAction action) { final BoundFunc.Builder succStateBuilder = boundFunction.transform(); final List sourceLocs = action.getSourceLocs(); @@ -61,8 +59,8 @@ private static BoundFunc preForBasicAction(final BoundFunc boundFunction, return succStateBuilder.build(); } - private static BoundFunc preForBinaryAction(final BoundFunc boundFunction, - final BinaryXtaAction action) { + private static BoundFunc preForBinaryAction( + final BoundFunc boundFunction, final BinaryXtaAction action) { final BoundFunc.Builder succStateBuilder = boundFunction.transform(); final List sourceLocs = action.getSourceLocs(); @@ -81,8 +79,8 @@ private static BoundFunc preForBinaryAction(final BoundFunc boundFunction, //// - private static void applyInverseUpdates(final BoundFunc.Builder succStateBuilder, - final Edge edge) { + private static void applyInverseUpdates( + final BoundFunc.Builder succStateBuilder, final Edge edge) { for (final Update update : edge.getUpdates()) { if (update.isClockUpdate()) { final ResetOp op = (ResetOp) update.asClockUpdate().getClockOp(); @@ -100,8 +98,8 @@ private static void applyGuards(final BoundFunc.Builder succStateBuilder, final } } - private static void applyInvariants(final BoundFunc.Builder succStateBuilder, - final List targetLocs) { + private static void applyInvariants( + final BoundFunc.Builder succStateBuilder, final List targetLocs) { for (final Loc loc : targetLocs) { for (final Guard invar : loc.getInvars()) { if (invar.isClockGuard()) { @@ -110,5 +108,4 @@ private static void applyInvariants(final BoundFunc.Builder succStateBuilder, } } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneAnalysis.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneAnalysis.java index a37f0363cd..0ad0c3e508 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneAnalysis.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,8 +16,8 @@ package hu.bme.mit.theta.xta.analysis.zone; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.zone.ZoneOrd; import hu.bme.mit.theta.analysis.zone.ZonePrec; @@ -28,8 +28,7 @@ public final class XtaZoneAnalysis implements Analysis getInitFunc() { public TransFunc getTransFunc() { return XtaZoneTransFunc.getInstance(); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneInitFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneInitFunc.java index 78eb8c546d..b3555d2a4c 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneInitFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,19 +17,17 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; +import java.util.Collection; +import java.util.Collections; final class XtaZoneInitFunc implements InitFunc { private static final XtaZoneInitFunc INSTANCE = new XtaZoneInitFunc(); - private XtaZoneInitFunc() { - } + private XtaZoneInitFunc() {} static XtaZoneInitFunc getInstance() { return INSTANCE; @@ -40,5 +38,4 @@ public Collection getInitStates(final ZonePrec prec) { checkNotNull(prec); return Collections.singleton(ZoneState.zero(prec.getVars()).transform().up().build()); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneTransFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneTransFunc.java index 7514c44670..ec7146af7c 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneTransFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,31 +15,27 @@ */ package hu.bme.mit.theta.xta.analysis.zone; -import java.util.Collection; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; import hu.bme.mit.theta.xta.analysis.XtaAction; +import java.util.Collection; final class XtaZoneTransFunc implements TransFunc { - private final static XtaZoneTransFunc INSTANCE = new XtaZoneTransFunc(); + private static final XtaZoneTransFunc INSTANCE = new XtaZoneTransFunc(); - private XtaZoneTransFunc() { - } + private XtaZoneTransFunc() {} static XtaZoneTransFunc getInstance() { return INSTANCE; } @Override - public Collection getSuccStates(final ZoneState state, final XtaAction action, - final ZonePrec prec) { + public Collection getSuccStates( + final ZoneState state, final XtaAction action, final ZonePrec prec) { final ZoneState succState = XtaZoneUtils.post(state, action, prec); return ImmutableList.of(succState); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneUtils.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneUtils.java index 7aa5481721..864c1e7fc5 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneUtils.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/XtaZoneUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.xta.analysis.zone; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Eq; + import com.google.common.collect.Lists; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; @@ -30,20 +33,15 @@ import hu.bme.mit.theta.xta.analysis.XtaAction.BasicXtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BinaryXtaAction; import hu.bme.mit.theta.xta.analysis.XtaAction.BroadcastXtaAction; - import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.clock.constr.ClockConstrs.Eq; - public final class XtaZoneUtils { - private XtaZoneUtils() { - } + private XtaZoneUtils() {} - public static ZoneState post(final ZoneState state, final XtaAction action, - final ZonePrec prec) { + public static ZoneState post( + final ZoneState state, final XtaAction action, final ZonePrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); @@ -59,8 +57,8 @@ public static ZoneState post(final ZoneState state, final XtaAction action, } } - private static ZoneState postForBasicAction(final ZoneState state, final BasicXtaAction action, - final ZonePrec prec) { + private static ZoneState postForBasicAction( + final ZoneState state, final BasicXtaAction action, final ZonePrec prec) { final ZoneState.Builder succStateBuilder = state.project(prec.getVars()); final List sourceLocs = action.getSourceLocs(); @@ -79,9 +77,8 @@ private static ZoneState postForBasicAction(final ZoneState state, final BasicXt return succState; } - private static ZoneState postForBinaryAction(final ZoneState state, - final BinaryXtaAction action, - final ZonePrec prec) { + private static ZoneState postForBinaryAction( + final ZoneState state, final BinaryXtaAction action, final ZonePrec prec) { final ZoneState.Builder succStateBuilder = state.project(prec.getVars()); final List sourceLocs = action.getSourceLocs(); @@ -104,9 +101,8 @@ private static ZoneState postForBinaryAction(final ZoneState state, return succState; } - private static ZoneState postForBroadcastAction(final ZoneState state, - final BroadcastXtaAction action, - final ZonePrec prec) { + private static ZoneState postForBroadcastAction( + final ZoneState state, final BroadcastXtaAction action, final ZonePrec prec) { final ZoneState.Builder succStateBuilder = state.project(prec.getVars()); final List sourceLocs = action.getSourceLocs(); @@ -120,13 +116,15 @@ private static ZoneState postForBroadcastAction(final ZoneState state, if (recvEdges.stream().anyMatch(XtaZoneUtils::hasClockGuards)) { throw new UnsupportedOperationException( - "Clock guards on edges with broadcast synchronization labels are not supported."); + "Clock guards on edges with broadcast synchronization labels are not" + + " supported."); } if (nonRecvEdgeCols.stream() .anyMatch(c -> c.stream().anyMatch(XtaZoneUtils::hasClockGuards))) { throw new UnsupportedOperationException( - "Clock guards on edges with broadcast synchronization labels are not supported."); + "Clock guards on edges with broadcast synchronization labels are not" + + " supported."); } applyUpdates(succStateBuilder, emitEdge); @@ -147,8 +145,8 @@ private static boolean hasClockGuards(Edge edge) { //// - public static ZoneState pre(final ZoneState state, final XtaAction action, - final ZonePrec prec) { + public static ZoneState pre( + final ZoneState state, final XtaAction action, final ZonePrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); @@ -164,8 +162,8 @@ public static ZoneState pre(final ZoneState state, final XtaAction action, } } - private static ZoneState preForBasicAction(final ZoneState state, final BasicXtaAction action, - final ZonePrec prec) { + private static ZoneState preForBasicAction( + final ZoneState state, final BasicXtaAction action, final ZonePrec prec) { final ZoneState.Builder preStateBuilder = state.project(prec.getVars()); final List sourceLocs = action.getSourceLocs(); @@ -184,8 +182,8 @@ private static ZoneState preForBasicAction(final ZoneState state, final BasicXta return preState; } - private static ZoneState preForBinaryAction(final ZoneState state, final BinaryXtaAction action, - final ZonePrec prec) { + private static ZoneState preForBinaryAction( + final ZoneState state, final BinaryXtaAction action, final ZonePrec prec) { final ZoneState.Builder preStateBuilder = state.project(prec.getVars()); final List sourceLocs = action.getSourceLocs(); @@ -207,9 +205,8 @@ private static ZoneState preForBinaryAction(final ZoneState state, final BinaryX return succState; } - private static ZoneState preForBroadcastAction(final ZoneState state, - final BroadcastXtaAction action, - final ZonePrec prec) { + private static ZoneState preForBroadcastAction( + final ZoneState state, final BroadcastXtaAction action, final ZonePrec prec) { final ZoneState.Builder preStateBuilder = state.project(prec.getVars()); final List sourceLocs = action.getSourceLocs(); @@ -229,12 +226,14 @@ private static ZoneState preForBroadcastAction(final ZoneState state, if (nonRecvEdgeCols.stream() .anyMatch(c -> c.stream().anyMatch(XtaZoneUtils::hasClockGuards))) { throw new UnsupportedOperationException( - "Clock guards on edges with broadcast synchronization labels are not supported."); + "Clock guards on edges with broadcast synchronization labels are not" + + " supported."); } if (reverseRecvEdges.stream().anyMatch(XtaZoneUtils::hasClockGuards)) { throw new UnsupportedOperationException( - "Clock guards on edges with broadcast synchronization labels are not supported."); + "Clock guards on edges with broadcast synchronization labels are not" + + " supported."); } applyGuards(preStateBuilder, emitEdge); @@ -260,8 +259,8 @@ private static void applyInverseDelay(final ZoneState.Builder builder) { builder.nonnegative(); } - private static void applyInvariants(final ZoneState.Builder builder, - final Collection locs) { + private static void applyInvariants( + final ZoneState.Builder builder, final Collection locs) { for (final Loc target : locs) { for (final Guard invar : target.getInvars()) { if (invar.isClockGuard()) { @@ -301,5 +300,4 @@ private static void applyGuards(final ZoneState.Builder builder, final Edge edge } } } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneAnalysis.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneAnalysis.java index 34e8c5595f..285daa259c 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneAnalysis.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,14 +19,14 @@ import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; -public final class ItpZoneAnalysis implements - Analysis { +public final class ItpZoneAnalysis + implements Analysis { private final InitFunc initFunc; private final TransFunc transFunc; @@ -58,5 +58,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneInitFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneInitFunc.java index b4747c2a9f..3e62840680 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneInitFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,12 +17,11 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; +import java.util.ArrayList; +import java.util.Collection; final class ItpZoneInitFunc implements InitFunc { @@ -49,5 +48,4 @@ public Collection getInitStates(final ZonePrec prec) { } return result; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneOrd.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneOrd.java index 25d613f3d1..013f7aeb10 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneOrd.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,8 +21,7 @@ public final class ItpZoneOrd implements PartialOrd { private static final ItpZoneOrd INSTANCE = new ItpZoneOrd(); - private ItpZoneOrd() { - } + private ItpZoneOrd() {} public static ItpZoneOrd getInstance() { return INSTANCE; @@ -34,5 +33,4 @@ public static ItpZoneOrd getInstance() { public boolean isLeq(final ItpZoneState state1, final ItpZoneState state2) { return state1.isLeq(state2); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneState.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneState.java index c88ad48948..ed95d4a42f 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneState.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.xta.analysis.zone.itp; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.analysis.zone.ZoneState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - public final class ItpZoneState implements ExprState { private final ZoneState concrState; @@ -104,8 +104,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final ItpZoneState that = (ItpZoneState) obj; - return this.concrState.equals(that.concrState) && this.abstrState.equals( - that.abstrState); + return this.concrState.equals(that.concrState) + && this.abstrState.equals(that.abstrState); } else { return false; } @@ -113,8 +113,10 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).body().add(concrState) - .add(abstrState).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .body() + .add(concrState) + .add(abstrState) + .toString(); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneTransFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneTransFunc.java index a384d2fb96..a58ebe9410 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneTransFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/itp/ItpZoneTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; final class ItpZoneTransFunc implements TransFunc { @@ -42,15 +41,15 @@ public static ItpZoneTransFunc create( //// @Override - public Collection getSuccStates(final ItpZoneState state, final A action, - final ZonePrec prec) { + public Collection getSuccStates( + final ItpZoneState state, final A action, final ZonePrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); final ZoneState subState = state.getConcrState(); - final Collection subSuccStates = transFunc.getSuccStates(subState, - action, prec); + final Collection subSuccStates = + transFunc.getSuccStates(subState, action, prec); if (subSuccStates.isEmpty()) { final ItpZoneState succState = ItpZoneState.of(ZoneState.bottom(), ZoneState.top()); diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneAnalysis.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneAnalysis.java index 86d1513e14..acd9778d28 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneAnalysis.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,8 @@ import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; @@ -55,5 +55,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneInitFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneInitFunc.java index c257c2da42..228e9ff0d0 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneInitFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,13 +17,12 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.zone.BoundFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; +import java.util.ArrayList; +import java.util.Collection; final class LuZoneInitFunc implements InitFunc { @@ -50,5 +49,4 @@ public Collection getInitStates(final ZonePrec prec) { } return result; } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneOrd.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneOrd.java index fc77f41489..db2efeeb14 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneOrd.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,8 +21,7 @@ public final class LuZoneOrd implements PartialOrd { private static final LuZoneOrd INSTANCE = new LuZoneOrd(); - private LuZoneOrd() { - } + private LuZoneOrd() {} public static LuZoneOrd getInstance() { return INSTANCE; @@ -32,5 +31,4 @@ public static LuZoneOrd getInstance() { public boolean isLeq(final LuZoneState state1, final LuZoneState state2) { return state1.isLeq(state2); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneState.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneState.java index 861766be81..5d44e48e7a 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneState.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,15 @@ */ package hu.bme.mit.theta.xta.analysis.zone.lu; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Lt; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; + import com.google.common.collect.Lists; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.analysis.zone.BoundFunc; @@ -26,22 +35,12 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.ArrayList; import java.util.Collection; import java.util.Map; import java.util.Optional; import java.util.StringJoiner; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Gt; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Lt; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; - public final class LuZoneState implements ExprState { private static final int HASH_SEED = 5261; @@ -95,10 +94,11 @@ public Expr toExpr() { final Collection> vars = mapping.keySet(); for (final VarDecl vx : vars) { - @SuppressWarnings("unchecked") final VarDecl dx = (VarDecl) vx; + @SuppressWarnings("unchecked") + final VarDecl dx = (VarDecl) vx; - @SuppressWarnings("unchecked") final ParamDecl dxp = (ParamDecl) mapping.get( - dx); + @SuppressWarnings("unchecked") + final ParamDecl dxp = (ParamDecl) mapping.get(dx); final Expr x = dx.getRef(); final Expr xp = dxp.getRef(); @@ -163,15 +163,16 @@ public String toString() { sj.add(zone.toString()); if (!boundFunc.getLowerVars().isEmpty()) { sj.add("L:"); - boundFunc.getLowerVars() + boundFunc + .getLowerVars() .forEach(c -> sj.add(c.getName() + " <- " + boundFunc.getLower(c).get())); } if (!boundFunc.getUpperVars().isEmpty()) { sj.add("U:"); - boundFunc.getUpperVars() + boundFunc + .getUpperVars() .forEach(c -> sj.add(c.getName() + " <- " + boundFunc.getUpper(c).get())); } return sj.toString(); } - } diff --git a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneTransFunc.java b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneTransFunc.java index e9f5b3cd4d..1777d18dce 100644 --- a/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneTransFunc.java +++ b/subprojects/xta/xta-analysis/src/main/java/hu/bme/mit/theta/xta/analysis/zone/lu/LuZoneTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,15 +17,14 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.zone.BoundFunc; import hu.bme.mit.theta.analysis.zone.ZonePrec; import hu.bme.mit.theta.analysis.zone.ZoneState; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; final class LuZoneTransFunc implements TransFunc { @@ -41,15 +40,15 @@ public static LuZoneTransFunc create( } @Override - public Collection getSuccStates(final LuZoneState state, final A action, - final ZonePrec prec) { + public Collection getSuccStates( + final LuZoneState state, final A action, final ZonePrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); final ZoneState subState = state.getZone(); - final Collection subSuccStates = transFunc.getSuccStates(subState, - action, prec); + final Collection subSuccStates = + transFunc.getSuccStates(subState, action, prec); if (subSuccStates.isEmpty()) { final LuZoneState succState = LuZoneState.of(ZoneState.bottom(), BoundFunc.top()); @@ -63,5 +62,4 @@ public Collection getSuccStates(final LuZoneState state, final A ac return result; } } - } diff --git a/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/LazyXtaCheckerTest.java b/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/LazyXtaCheckerTest.java index eefc740ce6..e64a1f49e9 100644 --- a/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/LazyXtaCheckerTest.java +++ b/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/LazyXtaCheckerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaAnalysisTest.java b/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaAnalysisTest.java index aabfaa25e3..540bbcbe34 100644 --- a/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaAnalysisTest.java +++ b/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaAnalysisTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaZoneAnalysisTest.java b/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaZoneAnalysisTest.java index 1c1e6fa56e..5b330c8274 100644 --- a/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaZoneAnalysisTest.java +++ b/subprojects/xta/xta-analysis/src/test/java/hu/bme/mit/theta/xta/analysis/XtaZoneAnalysisTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta-cli/build.gradle.kts b/subprojects/xta/xta-cli/build.gradle.kts index 5e0a67ed33..a038ccd347 100644 --- a/subprojects/xta/xta-cli/build.gradle.kts +++ b/subprojects/xta/xta-cli/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta-cli/src/main/java/hu/bme/mit/theta/xta/cli/XtaCli.java b/subprojects/xta/xta-cli/src/main/java/hu/bme/mit/theta/xta/cli/XtaCli.java index 7f5185f6fb..3bd7e34e87 100644 --- a/subprojects/xta/xta-cli/src/main/java/hu/bme/mit/theta/xta/cli/XtaCli.java +++ b/subprojects/xta/xta-cli/src/main/java/hu/bme/mit/theta/xta/cli/XtaCli.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta/build.gradle.kts b/subprojects/xta/xta/build.gradle.kts index 195f997dbe..16bef82fdb 100644 --- a/subprojects/xta/xta/build.gradle.kts +++ b/subprojects/xta/xta/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Guard.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Guard.java index 6d0fabba3f..26896420be 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Guard.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Guard.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,8 +24,7 @@ public abstract class Guard { - private Guard() { - } + private Guard() {} static DataGuard dataGuard(final Expr expr) { return new DataGuard(expr); @@ -125,7 +124,5 @@ public ClockGuard asClockGuard() { public String toString() { return clockConstr.toString(); } - } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Label.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Label.java index 617a2a684e..f32a0d3cac 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Label.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Label.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,11 +17,9 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.List; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.core.type.Type; +import java.util.List; public final class Label { @@ -32,15 +30,15 @@ public final class Label { private final List paramTypes; private final boolean broadcast; - private Label(final String name, final List paramTypes, - final boolean broadcast) { + private Label( + final String name, final List paramTypes, final boolean broadcast) { this.name = checkNotNull(name); this.paramTypes = ImmutableList.copyOf(checkNotNull(paramTypes)); this.broadcast = broadcast; } - public static Label of(final String name, final List paramTypes, - final boolean broadcast) { + public static Label of( + final String name, final List paramTypes, final boolean broadcast) { return new Label(name, paramTypes, broadcast); } @@ -78,5 +76,4 @@ public boolean equals(final Object obj) { public String toString() { return name; } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Sync.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Sync.java index 210646e328..803b78c67b 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Sync.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Sync.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.xta; -import com.google.common.collect.ImmutableList; -import hu.bme.mit.theta.common.Utils; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.Type; - -import java.util.List; - import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.Streams.zip; import static hu.bme.mit.theta.xta.Sync.Kind.EMIT; import static hu.bme.mit.theta.xta.Sync.Kind.RECV; +import com.google.common.collect.ImmutableList; +import hu.bme.mit.theta.common.Utils; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.Type; +import java.util.List; + public final class Sync { private static final int HASH_SEED = 6547; @@ -35,7 +34,8 @@ public final class Sync { private volatile int hashCode = 0; public enum Kind { - EMIT, RECV + EMIT, + RECV } private final Label label; @@ -99,8 +99,9 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Sync that = (Sync) obj; - return this.label.equals(that.label) && this.kind.equals(that.kind) && this.args.equals( - that.args); + return this.label.equals(that.label) + && this.kind.equals(that.kind) + && this.args.equals(that.args); } else { return false; } @@ -108,8 +109,9 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(label.getName()).add(kind == EMIT ? "!" : "?").addAll(args) + return Utils.lispStringBuilder(label.getName()) + .add(kind == EMIT ? "!" : "?") + .addAll(args) .toString(); } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Update.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Update.java index fc359ba16e..746e5917d2 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Update.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/Update.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,8 +23,7 @@ public abstract class Update { - private Update() { - } + private Update() {} static DataUpdate dataUpdate(final Stmt stmt) { return new DataUpdate(stmt); @@ -81,7 +80,6 @@ public ClockUpdate asClockUpdate() { public String toString() { return stmt.toString(); } - } public static final class ClockUpdate extends Update { @@ -125,7 +123,5 @@ public ClockUpdate asClockUpdate() { public String toString() { return clockOp.toString(); } - } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaProcess.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaProcess.java index b8ded80b20..83561388f0 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaProcess.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaProcess.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.xta; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.container.Containers; @@ -24,12 +27,8 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; import hu.bme.mit.theta.core.utils.StmtUtils; - import java.util.*; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - public final class XtaProcess { private final String name; @@ -88,16 +87,19 @@ public void setInitLoc(final Loc loc) { this.initLoc = loc; } - public Loc createLoc(final String name, final LocKind kind, - final Collection> invars) { + public Loc createLoc( + final String name, final LocKind kind, final Collection> invars) { final Loc loc = new Loc(name, kind, invars); locs.add(loc); return loc; } - public Edge createEdge(final Loc source, final Loc target, - final Collection> guards, - final Optional sync, final List updates) { + public Edge createEdge( + final Loc source, + final Loc target, + final Collection> guards, + final Optional sync, + final List updates) { checkArgument(locs.contains(source)); checkArgument(locs.contains(target)); final Edge edge = new Edge(source, target, guards, sync, updates); @@ -174,7 +176,9 @@ private List createUpdates(final List stmts) { //// public enum LocKind { - NORMAL, URGENT, COMMITTED; + NORMAL, + URGENT, + COMMITTED; } public final class Loc { @@ -188,8 +192,8 @@ public final class Loc { private final Collection unmodInEdges; private final Collection unmodOutEdges; - private Loc(final String name, final LocKind kind, - final Collection> invars) { + private Loc( + final String name, final LocKind kind, final Collection> invars) { inEdges = new ArrayList<>(); outEdges = new ArrayList<>(); this.name = checkNotNull(name); @@ -236,8 +240,12 @@ public final class Edge { private final Optional sync; private final List updates; - private Edge(final Loc source, final Loc target, final Collection> guards, - final Optional sync, final List updates) { + private Edge( + final Loc source, + final Loc target, + final Collection> guards, + final Optional sync, + final List updates) { this.source = checkNotNull(source); this.target = checkNotNull(target); this.guards = createGuards(guards); @@ -265,5 +273,4 @@ public List getUpdates() { return updates; } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaSystem.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaSystem.java index abbe17bd15..fd4ffa6bc2 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaSystem.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaSystem.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.xta; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ImmutableList.toImmutableList; + import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.model.MutableValuation; @@ -22,13 +26,8 @@ import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.rattype.RatType; import hu.bme.mit.theta.xta.XtaProcess.Loc; - import java.util.*; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.toImmutableList; - public final class XtaSystem { private final List processes; diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaVisualizer.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaVisualizer.java index a32ab4da23..67034b5327 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaVisualizer.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/XtaVisualizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,16 @@ */ package hu.bme.mit.theta.xta; -import java.awt.Color; - import hu.bme.mit.theta.common.container.Containers; - -import java.util.Map; -import java.util.StringJoiner; - import hu.bme.mit.theta.common.visualization.EdgeAttributes; import hu.bme.mit.theta.common.visualization.Graph; import hu.bme.mit.theta.common.visualization.LineStyle; import hu.bme.mit.theta.common.visualization.NodeAttributes; import hu.bme.mit.theta.xta.XtaProcess.Edge; import hu.bme.mit.theta.xta.XtaProcess.Loc; +import java.awt.Color; +import java.util.Map; +import java.util.StringJoiner; public final class XtaVisualizer { @@ -41,8 +38,7 @@ public final class XtaVisualizer { private static final LineStyle EDGE_LINE_STYLE = LineStyle.NORMAL; private static final int LOC_PERIPHERIES = 1; - private XtaVisualizer() { - } + private XtaVisualizer() {} public static Graph visualize(final XtaSystem system) { final Graph graph = new Graph("System", XTA_LABEL); @@ -60,39 +56,55 @@ public static Graph visualize(final XtaProcess process) { return graph; } - private static void traverseProcess(final XtaProcess process, final Graph graph, - final Map ids) { + private static void traverseProcess( + final XtaProcess process, final Graph graph, final Map ids) { addProcess(process, graph, ids); traverse(graph, process.getInitLoc(), ids.get(process), ids); addPhantomInit(process, graph, ids); } - private static void addProcess(final XtaProcess process, final Graph graph, - final Map ids) { + private static void addProcess( + final XtaProcess process, final Graph graph, final Map ids) { final String id = PROC_ID_PREFIX + ids.size(); ids.put(process, id); - final NodeAttributes nAttrs = NodeAttributes.builder().label(process.getName()) - .fillColor(FILL_COLOR) - .lineColor(LINE_COLOR).lineStyle(LOC_LINE_STYLE).peripheries(LOC_PERIPHERIES).build(); + final NodeAttributes nAttrs = + NodeAttributes.builder() + .label(process.getName()) + .fillColor(FILL_COLOR) + .lineColor(LINE_COLOR) + .lineStyle(LOC_LINE_STYLE) + .peripheries(LOC_PERIPHERIES) + .build(); graph.addCompositeNode(id, nAttrs); } - private static void addPhantomInit(final XtaProcess process, final Graph graph, - final Map ids) { + private static void addPhantomInit( + final XtaProcess process, final Graph graph, final Map ids) { final String id = PHANTOM_INIT_ID + ids.get(process); - final NodeAttributes nAttrs = NodeAttributes.builder().label("").fillColor(FILL_COLOR) - .lineColor(FILL_COLOR) - .lineStyle(LOC_LINE_STYLE).peripheries(LOC_PERIPHERIES).build(); + final NodeAttributes nAttrs = + NodeAttributes.builder() + .label("") + .fillColor(FILL_COLOR) + .lineColor(FILL_COLOR) + .lineStyle(LOC_LINE_STYLE) + .peripheries(LOC_PERIPHERIES) + .build(); graph.addNode(id, nAttrs); graph.setChild(ids.get(process), id); - final EdgeAttributes eAttrs = EdgeAttributes.builder().label("").color(LINE_COLOR) - .lineStyle(EDGE_LINE_STYLE) - .build(); + final EdgeAttributes eAttrs = + EdgeAttributes.builder() + .label("") + .color(LINE_COLOR) + .lineStyle(EDGE_LINE_STYLE) + .build(); graph.addEdge(id, ids.get(process.getInitLoc()), eAttrs); } - private static void traverse(final Graph graph, final Loc loc, final String parentNodeId, - final Map ids) { + private static void traverse( + final Graph graph, + final Loc loc, + final String parentNodeId, + final Map ids) { if (!ids.containsKey(loc)) { addLocation(graph, loc, parentNodeId, ids); for (final Edge outEdge : loc.getOutEdges()) { @@ -103,30 +115,40 @@ private static void traverse(final Graph graph, final Loc loc, final String pare } } - private static void addLocation(final Graph graph, final Loc loc, final String parentNodeId, - final Map ids) { + private static void addLocation( + final Graph graph, + final Loc loc, + final String parentNodeId, + final Map ids) { final String id = LOC_ID_PREFIX + ids.size(); ids.put(loc, id); final StringJoiner locLabel = new StringJoiner("\n", loc.getName() + "\n", ""); loc.getInvars().forEach(expr -> locLabel.add(expr.toString())); - final NodeAttributes attrs = NodeAttributes.builder().label(locLabel.toString()) - .fillColor(FILL_COLOR) - .lineColor(LINE_COLOR).lineStyle(LOC_LINE_STYLE).peripheries(LOC_PERIPHERIES).build(); + final NodeAttributes attrs = + NodeAttributes.builder() + .label(locLabel.toString()) + .fillColor(FILL_COLOR) + .lineColor(LINE_COLOR) + .lineStyle(LOC_LINE_STYLE) + .peripheries(LOC_PERIPHERIES) + .build(); graph.addNode(id, attrs); graph.setChild(parentNodeId, id); } - private static void addEdge(final Graph graph, final Map ids, - final Edge outEdge) { + private static void addEdge( + final Graph graph, final Map ids, final Edge outEdge) { final StringJoiner edgeLabel = new StringJoiner("\n"); outEdge.getSync().ifPresent(sync -> edgeLabel.add(sync.toString())); outEdge.getGuards().stream() .forEach(expr -> edgeLabel.add("\\[" + expr.toString() + "\\]")); outEdge.getUpdates().stream().forEach(stmt -> edgeLabel.add(stmt.toString())); - final EdgeAttributes attrs = EdgeAttributes.builder().label(edgeLabel.toString()) - .color(LINE_COLOR) - .lineStyle(EDGE_LINE_STYLE).build(); + final EdgeAttributes attrs = + EdgeAttributes.builder() + .label(edgeLabel.toString()) + .color(LINE_COLOR) + .lineStyle(EDGE_LINE_STYLE) + .build(); graph.addEdge(ids.get(outEdge.getSource()), ids.get(outEdge.getTarget()), attrs); } - -} \ No newline at end of file +} diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaDslManager.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaDslManager.java index 2ba951ae84..a2c8f8601c 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaDslManager.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaDslManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,28 +15,25 @@ */ package hu.bme.mit.theta.xta.dsl; +import hu.bme.mit.theta.xta.XtaSystem; +import hu.bme.mit.theta.xta.dsl.gen.XtaDslLexer; +import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser; +import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.XtaContext; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; - import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; -import hu.bme.mit.theta.xta.XtaSystem; -import hu.bme.mit.theta.xta.dsl.gen.XtaDslLexer; -import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser; -import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.XtaContext; - public final class XtaDslManager { - private XtaDslManager() { - } + private XtaDslManager() {} public static XtaSystem createSystem(final String inputString) throws IOException { - final InputStream stream = new ByteArrayInputStream( - inputString.getBytes(StandardCharsets.UTF_8.name())); + final InputStream stream = + new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8.name())); return createSystem(stream); } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaExpression.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaExpression.java index b7aed70c8e..c5b52b4fca 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaExpression.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,25 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.*; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add; +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.Gt; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Lt; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Mul; +import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neg; +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.arraytype.ArrayExprs.Read; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Div; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.common.dsl.Env; @@ -31,8 +50,8 @@ import hu.bme.mit.theta.core.type.arraytype.ArrayType; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; -import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.inttype.IntModExpr; +import hu.bme.mit.theta.core.type.inttype.IntType; import hu.bme.mit.theta.core.type.rattype.RatLitExpr; import hu.bme.mit.theta.core.utils.ExprUtils; import hu.bme.mit.theta.core.utils.TypeUtils; @@ -40,7 +59,6 @@ import hu.bme.mit.theta.xta.dsl.gen.XtaDslBaseVisitor; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.*; import hu.bme.mit.theta.xta.utils.LabelExpr; - import java.math.BigInteger; import java.util.Collection; import java.util.List; @@ -48,25 +66,6 @@ import java.util.Optional; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Add; -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.Gt; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Leq; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Lt; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Mul; -import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neg; -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.arraytype.ArrayExprs.Read; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Div; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.*; -import static java.util.stream.Collectors.toList; - final class XtaExpression { private final Scope scope; @@ -78,8 +77,8 @@ public XtaExpression(final Scope scope, final ExpressionContext context) { } public Expr instantiate(final Env env) { - final ExpressionInstantiationVisitor visitor = new ExpressionInstantiationVisitor(scope, - env); + final ExpressionInstantiationVisitor visitor = + new ExpressionInstantiationVisitor(scope, env); final Expr expr = context.accept(visitor); final Expr simplifiedExpr = ExprUtils.simplify(expr); return simplifiedExpr; @@ -145,8 +144,9 @@ public Expr visitIdExpression(final IdExpressionContext ctx) { // A constant, whose value is not yet defined, as this is its first occurrence final XtaVariableSymbol variableSymbol = (XtaVariableSymbol) symbol; assert variableSymbol.isConstant(); - final Object value = env.compute(variableSymbol, - v -> v.instantiate("", env).asConstant().getExpr()); + final Object value = + env.compute( + variableSymbol, v -> v.instantiate("", env).asConstant().getExpr()); final LitExpr expr = (LitExpr) value; return expr; } @@ -167,9 +167,10 @@ public Expr visitAdditiveExpression(final AdditiveExpressionContext ctx) { } } - private Expr createAdditiveExpr(final Expr opsHead, - final List> opsTail, - final List opers) { + private Expr createAdditiveExpr( + final Expr opsHead, + final List> opsTail, + final List opers) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -187,8 +188,8 @@ private Expr createAdditiveExpr(final Expr opsHead, } } - private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightOp, - final AdditiveOpContext oper) { + private Expr createAdditiveSubExpr( + final Expr leftOp, final Expr rightOp, final AdditiveOpContext oper) { if (oper.fAddOp != null) { return createAddExpr(leftOp, rightOp); } else if (oper.fSubOp != null) { @@ -201,9 +202,11 @@ private Expr createAdditiveSubExpr(final Expr leftOp, final Expr rightO private AddExpr createAddExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof AddExpr) { final AddExpr addLeftOp = (AddExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Add(ops); } else { return Add(leftOp, rightOp); @@ -231,9 +234,10 @@ public Expr visitMultiplicativeExpression(final MultiplicativeExpressionConte } } - private Expr createMutliplicativeExpr(final Expr opsHead, - final List> opsTail, - final List opers) { + private Expr createMutliplicativeExpr( + final Expr opsHead, + final List> opsTail, + final List opers) { checkArgument(opsTail.size() == opers.size()); if (opsTail.isEmpty()) { @@ -251,8 +255,8 @@ private Expr createMutliplicativeExpr(final Expr opsHead, } } - private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr rightOp, - final MultiplicativeOpContext oper) { + private Expr createMultiplicativeSubExpr( + final Expr leftOp, final Expr rightOp, final MultiplicativeOpContext oper) { if (oper.fMulOp != null) { return createMulExpr(leftOp, rightOp); } else if (oper.fDivOp != null) { @@ -267,9 +271,11 @@ private Expr createMultiplicativeSubExpr(final Expr leftOp, final Expr private MulExpr createMulExpr(final Expr leftOp, final Expr rightOp) { if (leftOp instanceof MulExpr) { final MulExpr addLeftOp = (MulExpr) leftOp; - final List> ops = ImmutableList.>builder() - .addAll(addLeftOp.getOps()).add(rightOp) - .build(); + final List> ops = + ImmutableList.>builder() + .addAll(addLeftOp.getOps()) + .add(rightOp) + .build(); return Mul(ops); } else { return Mul(leftOp, rightOp); @@ -358,7 +364,6 @@ public Expr visitPrefixExpression(final PrefixExpressionContext ctx) { // TODO Auto-generated method stub throw new UnsupportedOperationException("TODO: auto-generated method stub"); } - } } @@ -385,8 +390,8 @@ public Expr visitLogicalAndExpression(final LogicalAndExpressionContext ctx) if (ctx.fOps.size() == 1) { return checkNotNull(visitChildren(ctx)); } else { - final Stream> opStream = ctx.fOps.stream() - .map(op -> TypeUtils.cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.fOps.stream().map(op -> TypeUtils.cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return And(ops); } @@ -397,8 +402,8 @@ public Expr visitLogicalOrExpression(final LogicalOrExpressionContext ctx) { if (ctx.fOps.size() == 1) { return checkNotNull(visitChildren(ctx)); } else { - final Stream> opStream = ctx.fOps.stream() - .map(op -> TypeUtils.cast(op.accept(this), Bool())); + final Stream> opStream = + ctx.fOps.stream().map(op -> TypeUtils.cast(op.accept(this), Bool())); final Collection> ops = opStream.collect(toList()); return Or(ops); } @@ -507,5 +512,4 @@ public Expr visitBitwiseXorExpression(final BitwiseXorExpressionContext ctx) } } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaFunctionSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaFunctionSymbol.java index 80610bfc2a..b2d443fd3a 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaFunctionSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaFunctionSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,5 +29,4 @@ public String getName() { // TODO Auto-generated method stub throw new UnsupportedOperationException("TODO: auto-generated method stub"); } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInitialiser.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInitialiser.java index c0f3c02616..9c7a18edc7 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInitialiser.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInitialiser.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.core.type.Expr; @@ -24,9 +27,6 @@ import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.InitialiserContext; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.SimpleInitialiserContext; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - final class XtaInitialiser { private final Scope scope; @@ -64,7 +64,5 @@ public Expr visitCompoundInitialiser(final CompoundInitialiserContext ctx) { // TODO Auto-generated method stub throw new UnsupportedOperationException("TODO: auto-generated method stub"); } - } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInstantiationSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInstantiationSymbol.java index 34b3844f78..4e9b287c48 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInstantiationSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaInstantiationSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.stream.Collectors.toList; + import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.InstantiationContext; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.stream.Collectors.toList; - final class XtaInstantiationSymbol implements Symbol { private final Scope scope; @@ -46,11 +45,14 @@ public String getProcName() { } public List> getArgumentList(final Env env) { - final List> argumentList = context.fArgList.fExpressions.stream().map(e -> { - final XtaExpression expression = new XtaExpression(scope, e); - return expression.instantiate(env); - }).collect(toList()); + final List> argumentList = + context.fArgList.fExpressions.stream() + .map( + e -> { + final XtaExpression expression = new XtaExpression(scope, e); + return expression.instantiate(env); + }) + .collect(toList()); return argumentList; } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaIteratorSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaIteratorSymbol.java index 6366b294f7..2bab99f1ee 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaIteratorSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaIteratorSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,15 +17,15 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; - import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.IteratorDeclContext; +import java.util.Collections; final class XtaIteratorSymbol implements Symbol { private final String name; + @SuppressWarnings("unused") private final XtaType type; @@ -39,5 +39,4 @@ public XtaIteratorSymbol(final Scope scope, final IteratorDeclContext context) { public String getName() { return name; } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaParameterSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaParameterSymbol.java index 5b89d44033..318b9e0fe4 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaParameterSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaParameterSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,9 +20,6 @@ import static com.google.common.base.Preconditions.checkState; import static java.util.stream.Collectors.toCollection; -import java.util.LinkedHashSet; -import java.util.Set; - import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; @@ -31,6 +28,8 @@ import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.ParameterIdContext; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.TypeContext; import hu.bme.mit.theta.xta.utils.RangeType; +import java.util.LinkedHashSet; +import java.util.Set; final class XtaParameterSymbol implements Symbol { @@ -40,8 +39,10 @@ final class XtaParameterSymbol implements Symbol { private final XtaType type; - public XtaParameterSymbol(final Scope scope, final TypeContext typeContext, - final ParameterIdContext parameterIdContext) { + public XtaParameterSymbol( + final Scope scope, + final TypeContext typeContext, + final ParameterIdContext parameterIdContext) { checkNotNull(typeContext); checkNotNull(parameterIdContext); name = parameterIdContext.fArrayId.fId.getText(); @@ -78,5 +79,4 @@ public Set> instantiateValues(final Env env) { final Set> values = rangeType.values().collect(toCollection(LinkedHashSet::new)); return values; } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaProcessSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaProcessSymbol.java index bb7331b392..18d8bdcc1e 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaProcessSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaProcessSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.Sets; import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; @@ -30,16 +34,11 @@ import hu.bme.mit.theta.xta.XtaSystem; import hu.bme.mit.theta.xta.dsl.XtaVariableSymbol.InstantiateResult; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.*; - import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Set; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.stream.Collectors.toList; - final class XtaProcessSymbol implements Symbol, Scope { private final XtaSpecification scope; @@ -63,15 +62,18 @@ public XtaProcessSymbol(final XtaSpecification scope, final ProcessDeclContext c parameters = new ArrayList<>(); variables = new ArrayList<>(); states = new ArrayList<>(); - transitions = context.fProcessBody.fTransitions.fTransitions.stream() - .map(t -> new XtaTransition(this, t)) - .collect(toList()); + transitions = + context.fProcessBody.fTransitions.fTransitions.stream() + .map(t -> new XtaTransition(this, t)) + .collect(toList()); declareAllParameters(context.fParameterList.fParameterDecls); declareAllTypes(context.fProcessBody.fTypeDecls); declareAllVariables(context.fProcessBody.fVariableDecls); declareAllFunctions(context.fProcessBody.fFunctionDecls); - declareAllStates(context.fProcessBody.fStates.fStateDecls, context.fProcessBody.fUrgent, + declareAllStates( + context.fProcessBody.fStates.fStateDecls, + context.fProcessBody.fUrgent, context.fProcessBody.fCommit); } @@ -81,17 +83,19 @@ public String getName() { } public Set>> getArgumentLists(final Env env) { - final List>> argumentValues = parameters.stream() - .map(p -> p.instantiateValues(env)) - .collect(toList()); + final List>> argumentValues = + parameters.stream().map(p -> p.instantiateValues(env)).collect(toList()); final Set>> argumentLists = Sets.cartesianProduct(argumentValues); return argumentLists; } //// - public XtaProcess instantiate(final XtaSystem system, final String name, - final List> arguments, final Env env) { + public XtaProcess instantiate( + final XtaSystem system, + final String name, + final List> arguments, + final Env env) { checkArgument(arguments.size() == parameters.size()); checkArgument(argumentTypesMatch(arguments)); @@ -121,14 +125,14 @@ private void createAllLocalVariables(final XtaProcess process, final Env env) { if (variable.isConstant()) { // do nothing; will be defined lazily on first occurrence } else { - final InstantiateResult instantiateResult = variable.instantiate( - process.getName() + "_", env); + final InstantiateResult instantiateResult = + variable.instantiate(process.getName() + "_", env); if (instantiateResult.isChannel()) { final Label label = instantiateResult.asChannel().getLabel(); env.define(variable, label); } else if (instantiateResult.isClockVariable()) { - final VarDecl varDecl = instantiateResult.asClockVariable() - .getVarDecl(); + final VarDecl varDecl = + instantiateResult.asClockVariable().getVarDecl(); env.define(variable, varDecl); process.getSystem().addClockVar(varDecl); } else if (instantiateResult.isDataVariable()) { @@ -173,8 +177,8 @@ private void declareAllParameters(final List contexts) { private void declare(final ParameterDeclContext context) { final TypeContext typeContext = context.fType; for (final ParameterIdContext parameterIdContext : context.fparameterIds) { - final XtaParameterSymbol parameterSymbol = new XtaParameterSymbol(this, typeContext, - parameterIdContext); + final XtaParameterSymbol parameterSymbol = + new XtaParameterSymbol(this, typeContext, parameterIdContext); parameters.add(parameterSymbol); symbolTable.add(parameterSymbol); } @@ -203,8 +207,8 @@ private void declareAllVariables(final List contexts) { private void declare(final VariableDeclContext context) { final TypeContext typeContext = context.fType; for (final VariableIdContext variableIdContext : context.fVariableIds) { - final XtaVariableSymbol variableSymbol = new XtaVariableSymbol(this, typeContext, - variableIdContext); + final XtaVariableSymbol variableSymbol = + new XtaVariableSymbol(this, typeContext, variableIdContext); variables.add(variableSymbol); symbolTable.add(variableSymbol); } @@ -223,13 +227,17 @@ private void declare(final FunctionDeclContext context) { //// - private void declareAllStates(final List contexts, final UrgentContext urgent, - final CommitContext commit) { + private void declareAllStates( + final List contexts, + final UrgentContext urgent, + final CommitContext commit) { contexts.forEach(s -> declare(s, urgent, commit)); } - private void declare(final StateDeclContext context, final UrgentContext urgent, - final CommitContext commit) { + private void declare( + final StateDeclContext context, + final UrgentContext urgent, + final CommitContext commit) { final XtaStateSymbol stateSymbol = new XtaStateSymbol(this, context, urgent, commit); states.add(stateSymbol); symbolTable.add(stateSymbol); @@ -251,5 +259,4 @@ public Optional resolve(final String name) { return scope.resolve(name); } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSpecification.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSpecification.java index 098ac17471..a4556d02cc 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSpecification.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSpecification.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,9 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.stream.Collectors.toList; + import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; @@ -26,12 +29,8 @@ import hu.bme.mit.theta.xta.Label; import hu.bme.mit.theta.xta.XtaSystem; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.*; -import org.antlr.v4.runtime.Token; - import java.util.*; - -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.stream.Collectors.toList; +import org.antlr.v4.runtime.Token; final class XtaSpecification implements Scope { @@ -114,8 +113,8 @@ private XtaSystem instantiate() { return system; } - private static String createName(final XtaProcessSymbol processSymbol, - final List> argumentList) { + private static String createName( + final XtaProcessSymbol processSymbol, final List> argumentList) { final StringBuilder sb = new StringBuilder(); sb.append(processSymbol.getName()); argumentList.forEach(a -> sb.append("_" + a.toString())); @@ -135,14 +134,14 @@ private void createAllGlobalVariables(final XtaSystem system, final Env env) { if (variable.isConstant()) { // do nothing; will be defined lazily on first occurrence } else { - final XtaVariableSymbol.InstantiateResult instantiateResult = variable.instantiate( - "", env); + final XtaVariableSymbol.InstantiateResult instantiateResult = + variable.instantiate("", env); if (instantiateResult.isChannel()) { final Label label = instantiateResult.asChannel().getLabel(); env.define(variable, label); } else if (instantiateResult.isClockVariable()) { - final VarDecl varDecl = instantiateResult.asClockVariable() - .getVarDecl(); + final VarDecl varDecl = + instantiateResult.asClockVariable().getVarDecl(); env.define(variable, varDecl); system.addClockVar(varDecl); } else if (instantiateResult.isDataVariable()) { @@ -181,8 +180,8 @@ private void declareAllVariables(final List contexts) { private void declare(final VariableDeclContext context) { final TypeContext typeContext = context.fType; for (final VariableIdContext variableIdContext : context.fVariableIds) { - final XtaVariableSymbol variableSymbol = new XtaVariableSymbol(this, typeContext, - variableIdContext); + final XtaVariableSymbol variableSymbol = + new XtaVariableSymbol(this, typeContext, variableIdContext); variables.add(variableSymbol); symbolTable.add(variableSymbol); } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaStateSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaStateSymbol.java index 0ffc6f7326..c6c172a8dc 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaStateSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaStateSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,6 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; import static java.util.stream.Collectors.toList; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Symbol; import hu.bme.mit.theta.core.type.Expr; @@ -34,6 +31,8 @@ import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.CommitContext; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.StateDeclContext; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.UrgentContext; +import java.util.Collection; +import java.util.Collections; final class XtaStateSymbol implements Symbol { @@ -41,13 +40,17 @@ final class XtaStateSymbol implements Symbol { private final LocKind kind; private final XtaExpression expression; - public XtaStateSymbol(final XtaProcessSymbol scope, final StateDeclContext context, - final UrgentContext urgent, - final CommitContext commit) { + public XtaStateSymbol( + final XtaProcessSymbol scope, + final StateDeclContext context, + final UrgentContext urgent, + final CommitContext commit) { checkNotNull(context); name = context.fId.getText(); - kind = isCommited(name, commit) ? LocKind.COMMITTED - : isUrgent(name, urgent) ? LocKind.URGENT : LocKind.NORMAL; + kind = + isCommited(name, commit) + ? LocKind.COMMITTED + : isUrgent(name, urgent) ? LocKind.URGENT : LocKind.NORMAL; expression = context.fExpression != null ? new XtaExpression(scope, context.fExpression) : null; } @@ -58,7 +61,6 @@ private static boolean isUrgent(final String name, final UrgentContext urgent) { } else { return urgent.fStateList.fIds.stream().anyMatch(id -> id.getText().equals(name)); } - } private static boolean isCommited(final String name, final CommitContext commit) { @@ -88,5 +90,4 @@ public Loc instantiate(final XtaProcess process, final Env env) { final Loc loc = process.createLoc(process.getName() + "_" + name, kind, invars); return loc; } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSync.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSync.java index 4a830856a2..faa92daf43 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSync.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaSync.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.List; - import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.arraytype.ArrayReadExpr; @@ -29,6 +26,8 @@ import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.SyncContext; import hu.bme.mit.theta.xta.utils.ChanType; import hu.bme.mit.theta.xta.utils.LabelExpr; +import java.util.ArrayList; +import java.util.List; final class XtaSync { @@ -43,7 +42,8 @@ public XtaSync(final XtaTransition scope, final SyncContext context) { } public enum SyncKind { - EMIT, RECV + EMIT, + RECV } public Sync instantiate(final Env env) { @@ -76,5 +76,4 @@ private Label extractLabel(final Expr expr, final List> args) { throw new AssertionError(); } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTransition.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTransition.java index f3da55cdf6..aecd3adcb9 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTransition.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTransition.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,11 +21,6 @@ import static java.util.Collections.emptySet; import static java.util.stream.Collectors.toList; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; @@ -41,6 +36,10 @@ import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.IteratorDeclContext; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.SelectContext; import hu.bme.mit.theta.xta.dsl.gen.XtaDslParser.TransitionContext; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Optional; final class XtaTransition implements Scope { @@ -123,8 +122,8 @@ public void instantiate(final XtaProcess process, final Env env) { guards = emptySet(); } - final List assignments = updates.stream().map(u -> u.instantiate(env)) - .collect(toList()); + final List assignments = + updates.stream().map(u -> u.instantiate(env)).collect(toList()); final Optional label = sync.map(s -> s.instantiate(env)); process.createEdge(source, target, guards, label, assignments); @@ -147,5 +146,4 @@ public Optional resolve(final String name) { return scope.resolve(name); } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaType.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaType.java index 95d77a5dd6..5b5e1e9d16 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaType.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,12 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; + import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; import hu.bme.mit.theta.common.dsl.Symbol; @@ -27,15 +33,8 @@ import hu.bme.mit.theta.xta.utils.ChanType; import hu.bme.mit.theta.xta.utils.ClockType; import hu.bme.mit.theta.xta.utils.RangeType; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; - final class XtaType { private final Scope scope; @@ -43,8 +42,10 @@ final class XtaType { private final TypeContext typeContext; private final List arrayIndexContexts; - public XtaType(final Scope scope, final TypeContext typeContext, - final List arrayIndexContexts) { + public XtaType( + final Scope scope, + final TypeContext typeContext, + final List arrayIndexContexts) { this.scope = checkNotNull(scope); this.typeContext = checkNotNull(typeContext); this.arrayIndexContexts = checkNotNull(arrayIndexContexts); @@ -139,7 +140,6 @@ public Type visitRefType(final RefTypeContext ctx) { final Type result = (Type) value; return result; } - } private final class IndexTypeInstantiationVisitor extends XtaDslBaseVisitor { @@ -156,8 +156,9 @@ public Type visitIdIndex(final IdIndexContext ctx) { if (symbol instanceof XtaVariableSymbol) { final XtaVariableSymbol variableSymbol = (XtaVariableSymbol) symbol; assert variableSymbol.isConstant(); - final Object value = env.compute(variableSymbol, - v -> v.instantiate("", env).asConstant().getExpr()); + final Object value = + env.compute( + variableSymbol, v -> v.instantiate("", env).asConstant().getExpr()); final IntLitExpr elemCount = (IntLitExpr) value; final Type result = RangeType.Range(0, elemCount.getValue().intValue() - 1); @@ -181,7 +182,5 @@ public Type visitExpressionIndex(final ExpressionIndexContext ctx) { final Type result = RangeType.Range(0, elemCount.getValue().intValue() - 1); return result; } - } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTypeSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTypeSymbol.java index 472d3ae1f2..2703a14166 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTypeSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaTypeSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -29,8 +29,8 @@ final class XtaTypeSymbol implements Symbol { private final String name; private final XtaType type; - public XtaTypeSymbol(final Scope scope, final TypeContext typeContext, - final ArrayIdContext arrayIdContext) { + public XtaTypeSymbol( + final Scope scope, final TypeContext typeContext, final ArrayIdContext arrayIdContext) { checkNotNull(typeContext); checkNotNull(arrayIdContext); name = arrayIdContext.fId.getText(); @@ -45,5 +45,4 @@ public String getName() { public Type instantiate(final Env env) { return type.instantiate(env); } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaUpdate.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaUpdate.java index 043c0a7f45..1369ef6a6f 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaUpdate.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaUpdate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -68,11 +68,11 @@ public AssignStmt visitAssignmentExpression(final AssignmentExpressionContext if (ctx.fOper == null) { return visitChildren(ctx); } else { - @SuppressWarnings("unchecked") final RefExpr leftOp = (RefExpr) ctx.fLeftOp.accept( - visitor); + @SuppressWarnings("unchecked") + final RefExpr leftOp = (RefExpr) ctx.fLeftOp.accept(visitor); final VarDecl varDecl = (VarDecl) leftOp.getDecl(); - @SuppressWarnings("unchecked") final Expr rightOp = (Expr) ctx.fRightOp.accept( - visitor); + @SuppressWarnings("unchecked") + final Expr rightOp = (Expr) ctx.fRightOp.accept(visitor); final AssignmentOpContext op = ctx.fOper; if (op.fAssignOp != null) { @@ -105,5 +105,4 @@ public AssignStmt visitPostfixExpression(final PostfixExpressionContext ctx) } } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaVariableSymbol.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaVariableSymbol.java index b4453aac18..28b55ba44b 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaVariableSymbol.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/dsl/XtaVariableSymbol.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,13 @@ */ package hu.bme.mit.theta.xta.dsl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; +import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; +import static hu.bme.mit.theta.core.utils.TypeUtils.cast; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.common.dsl.Env; import hu.bme.mit.theta.common.dsl.Scope; @@ -34,16 +41,8 @@ import hu.bme.mit.theta.xta.utils.ChanType; import hu.bme.mit.theta.xta.utils.ClockType; import hu.bme.mit.theta.xta.utils.RangeType; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int; -import static hu.bme.mit.theta.core.type.rattype.RatExprs.Rat; -import static hu.bme.mit.theta.core.utils.TypeUtils.cast; - final class XtaVariableSymbol implements Symbol { private final String name; @@ -53,17 +52,20 @@ final class XtaVariableSymbol implements Symbol { private final XtaType type; private final XtaInitialiser initialiser; - public XtaVariableSymbol(final Scope scope, final TypeContext typeContext, - final VariableIdContext variableIdcontext) { + public XtaVariableSymbol( + final Scope scope, + final TypeContext typeContext, + final VariableIdContext variableIdcontext) { checkNotNull(typeContext); checkNotNull(variableIdcontext); name = variableIdcontext.fArrayId.fId.getText(); constant = (typeContext.fTypePrefix.fConst != null); broadcast = (typeContext.fTypePrefix.fBroadcast != null); type = new XtaType(scope, typeContext, variableIdcontext.fArrayId.fArrayIndexes); - initialiser = variableIdcontext.fInitialiser != null ? new XtaInitialiser(scope, - variableIdcontext.fInitialiser) - : null; + initialiser = + variableIdcontext.fInitialiser != null + ? new XtaInitialiser(scope, variableIdcontext.fInitialiser) + : null; } @Override @@ -184,19 +186,20 @@ private static List extractArgs(final Type type) { final Type newIndexType = (indexType instanceof RangeType) ? Int() : indexType; - final List result = ImmutableList.builder().add(newIndexType) - .addAll(extractArgs(elemType)) - .build(); + final List result = + ImmutableList.builder() + .add(newIndexType) + .addAll(extractArgs(elemType)) + .build(); return result; } else { throw new AssertionError(); } } - public static abstract class InstantiateResult { + public abstract static class InstantiateResult { - private InstantiateResult() { - } + private InstantiateResult() {} public static InstantiateResult constant(final LitExpr expr) { return new Constant(expr); @@ -206,8 +209,8 @@ public static InstantiateResult clockVariable(final VarDecl varDecl) { return new ClockVariable(varDecl); } - public static InstantiateResult dataVariable(final VarDecl varDecl, - final LitExpr initValue) { + public static InstantiateResult dataVariable( + final VarDecl varDecl, final LitExpr initValue) { return new DataVariable(varDecl, initValue); } @@ -248,7 +251,6 @@ public Channel asChannel() { } } - public static final class DataVariable extends InstantiateResult { private final VarDecl varDecl; @@ -347,5 +349,4 @@ public Label getLabel() { return label; } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ChanType.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ChanType.java index d6f5029a4e..7064ae7040 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ChanType.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ChanType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,8 +22,7 @@ public final class ChanType implements Type { private static final ChanType INSTANCE = new ChanType(); - private ChanType() { - } + private ChanType() {} public static ChanType getInstance() { return INSTANCE; diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ClockType.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ClockType.java index 5deb3f53d7..57f7a8100f 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ClockType.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/ClockType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,8 +22,7 @@ public final class ClockType implements Type { private static final ClockType INSTANCE = new ClockType(); - private ClockType() { - } + private ClockType() {} public static ClockType getInstance() { return INSTANCE; diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/LabelExpr.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/LabelExpr.java index 45b2f264da..c73985143a 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/LabelExpr.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/LabelExpr.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.xta.utils; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.common.Utils.head; +import static hu.bme.mit.theta.common.Utils.tail; +import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; import hu.bme.mit.theta.core.type.NullaryExpr; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.xta.Label; - import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.common.Utils.head; -import static hu.bme.mit.theta.common.Utils.tail; -import static hu.bme.mit.theta.core.type.arraytype.ArrayExprs.Array; - public final class LabelExpr extends NullaryExpr { private static final int HASH_SEED = 4703; @@ -101,5 +100,4 @@ private Type extractType(final List types) { return Array(head, extractType(tail)); } } - } diff --git a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/RangeType.java b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/RangeType.java index 7fc1c5ad39..309e601c6b 100644 --- a/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/RangeType.java +++ b/subprojects/xta/xta/src/main/java/hu/bme/mit/theta/xta/utils/RangeType.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.xta.utils; +import static com.google.common.base.Preconditions.checkArgument; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.DomainSize; import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.inttype.IntExprs; import hu.bme.mit.theta.core.type.inttype.IntLitExpr; - import java.util.stream.IntStream; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkArgument; - public final class RangeType implements Type { private static final int HASH_SEED = 5441; @@ -94,5 +93,4 @@ public String toString() { public DomainSize getDomainSize() { return DomainSize.of(upper - lower + 1); } - } diff --git a/subprojects/xta/xta/src/test/java/hu/bme/mit/theta/xta/dsl/XtaDslManagerTest.java b/subprojects/xta/xta/src/test/java/hu/bme/mit/theta/xta/dsl/XtaDslManagerTest.java index 1ab45c6cb8..cdd600d274 100644 --- a/subprojects/xta/xta/src/test/java/hu/bme/mit/theta/xta/dsl/XtaDslManagerTest.java +++ b/subprojects/xta/xta/src/test/java/hu/bme/mit/theta/xta/dsl/XtaDslManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,41 +15,34 @@ */ package hu.bme.mit.theta.xta.dsl; +import hu.bme.mit.theta.common.visualization.writer.GraphvizWriter; +import hu.bme.mit.theta.xta.XtaProcess; +import hu.bme.mit.theta.xta.XtaSystem; +import hu.bme.mit.theta.xta.XtaVisualizer; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -import hu.bme.mit.theta.common.visualization.writer.GraphvizWriter; -import hu.bme.mit.theta.xta.XtaProcess; -import hu.bme.mit.theta.xta.XtaSystem; -import hu.bme.mit.theta.xta.XtaVisualizer; - @RunWith(Parameterized.class) public final class XtaDslManagerTest { @Parameters(name = "{0}") public static Collection data() { - return Arrays.asList(new Object[][]{ - - {"/critical-4-25-50.xta"}, - - {"/csma-4.xta"}, - - {"/fddi-4.xta"}, - - {"/fischer-4-32-64.xta"}, - - {"/lynch-4-16.xta"} - - }); + return Arrays.asList( + new Object[][] { + {"/critical-4-25-50.xta"}, + {"/csma-4.xta"}, + {"/fddi-4.xta"}, + {"/fischer-4-32-64.xta"}, + {"/lynch-4-16.xta"} + }); } @Parameter(0) @@ -63,5 +56,4 @@ public void test() throws FileNotFoundException, IOException { System.out.println( GraphvizWriter.getInstance().writeString(XtaVisualizer.visualize(process))); } - }

We perform caching for the hash codes, but equals() checks will always traverse the ancestors + * of a node (and edge). However, this traversal only goes towards the root, rather than in all * directions. */ public final class ArgStructuralEquality { private static final Map hashCodeCache = new LinkedHashMap<>(); - private ArgStructuralEquality() { - } + private ArgStructuralEquality() {} - public static boolean equals(final ArgNode n1, - final ArgNode n2) { + public static boolean equals( + final ArgNode n1, + final ArgNode n2) { // if references are the same, the two nodes are equal if (n1 == n2) { @@ -74,8 +71,9 @@ public static boolean equals(final ArgNode n1 return true; } - public static boolean equals(final ArgEdge e1, - final ArgEdge e2) { + public static boolean equals( + final ArgEdge e1, + final ArgEdge e2) { // if references are the same, the two edges are equal if (e1 == e2) { @@ -87,7 +85,6 @@ public static boolean equals(final ArgEdge e1 return false; } - // if wrapped action is not same, edges are not equal if (!e1.getAction().equals(e2.getAction())) { return false; @@ -101,8 +98,9 @@ public static boolean equals(final ArgEdge e1 return true; } - public static boolean equals(final ARG a1, - final ARG a2) { + public static boolean equals( + final ARG a1, + final ARG a2) { // if references are the same, the two edges are equal if (a1 == a2) { @@ -114,8 +112,10 @@ public static boolean equals(final ARG a1, return false; } - Set> leaves1 = a1.getNodes().filter(ArgNode::isLeaf).collect(Collectors.toUnmodifiableSet()); - Set> leaves2 = a2.getNodes().filter(ArgNode::isLeaf).collect(Collectors.toUnmodifiableSet()); + Set> leaves1 = + a1.getNodes().filter(ArgNode::isLeaf).collect(Collectors.toUnmodifiableSet()); + Set> leaves2 = + a2.getNodes().filter(ArgNode::isLeaf).collect(Collectors.toUnmodifiableSet()); // if the two ARGs contain a different number of leaf nodes, they are not equal if (leaves1.size() != leaves2.size()) { @@ -135,13 +135,13 @@ public static boolean equals(final ARG a1, return true; } - public static boolean equals(final ArgTrace t1, - final ArgTrace t2) { + public static boolean equals( + final ArgTrace t1, + final ArgTrace t2) { return equal(t1.node(t1.length()), t2.node(t2.length())); } - public static int hashCode(final ArgNode n) { if (!hashCodeCache.containsKey(n)) { int hashcode = 0; @@ -173,7 +173,8 @@ public static int hashCode(final ArgEdge e) { public static int hashCode(final ARG a) { int hashcode = 0; - Set> leaves = a.getNodes().filter(ArgNode::isLeaf).collect(Collectors.toUnmodifiableSet()); + Set> leaves = + a.getNodes().filter(ArgNode::isLeaf).collect(Collectors.toUnmodifiableSet()); for (ArgNode leaf : leaves) { hashcode += hashCode(leaf); } @@ -188,5 +189,4 @@ public static int hashCode(final ArgTrace t) } return hashCodeCache.get(t); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgTrace.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgTrace.java index 6c21ce9bc8..9204d3609e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgTrace.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgTrace.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,12 @@ */ package hu.bme.mit.theta.analysis.algorithm.arg; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.stream.Collectors.toList; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.Trace; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -26,12 +28,7 @@ import java.util.List; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.stream.Collectors.toList; - -/** - * Represents a trace in the ARG, which is an alternating list of ArgNodes and ArgEdges. - */ +/** Represents a trace in the ARG, which is an alternating list of ArgNodes and ArgEdges. */ public final class ArgTrace implements Iterable> { private final List> nodes; @@ -71,9 +68,7 @@ public static ArgTrace to(final ArgNod //// - /** - * Gets the length of the trace, i.e., the number of edges. - */ + /** Gets the length of the trace, i.e., the number of edges. */ public int length() { return edges.size(); } @@ -112,5 +107,4 @@ public Trace toTrace() { public Iterator> iterator() { return nodes.iterator(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgUtils.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgUtils.java index d5471c2f5a..35a8b10dcc 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgUtils.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/ArgUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,13 +21,10 @@ public final class ArgUtils { - private ArgUtils() { - } + private ArgUtils() {} public static boolean isWellLabeled( - final ARG arg, - final Solver solver) { + final ARG arg, final Solver solver) { return ArgChecker.create(solver).isWellLabeled(arg); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/SearchStrategy.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/SearchStrategy.java index 2aed37ee5d..cb62f7ce8e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/SearchStrategy.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/SearchStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,20 +17,17 @@ import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; -import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; import hu.bme.mit.theta.analysis.waitlist.FifoWaitlist; import hu.bme.mit.theta.analysis.waitlist.LifoWaitlist; import hu.bme.mit.theta.analysis.waitlist.RandomWaitlist; import hu.bme.mit.theta.analysis.waitlist.Waitlist; public enum SearchStrategy { - BFS { @Override public Waitlist> createWaitlist() { return FifoWaitlist.create(); } - }, DFS { @@ -38,7 +35,6 @@ public Waitlist> createWaitlis public Waitlist> createWaitlist() { return LifoWaitlist.create(); } - }, RANDOM { @@ -46,9 +42,7 @@ public Waitlist> createWaitlis public Waitlist> createWaitlist() { return RandomWaitlist.create(); } - }; public abstract Waitlist> createWaitlist(); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/debug/ARGWebDebugger.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/debug/ARGWebDebugger.java index 7b6d100d5c..01de3f6d33 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/debug/ARGWebDebugger.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/arg/debug/ARGWebDebugger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm.arg.debug; import com.corundumstudio.socketio.Configuration; @@ -22,16 +21,13 @@ import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ArgEdge; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; - import java.util.LinkedList; import java.util.List; - /** * Use http://leventebajczi.com/theta-debugger/ to connect to Theta and see the ARG being built. * Modify the *debug* field below to true in order to enable the debugger. */ - public final class ARGWebDebugger { public static boolean on = false; private static final Integer PORT = 8080; @@ -41,12 +37,9 @@ public final class ARGWebDebugger { private static volatile boolean received; private static volatile boolean waiting; - private static final List replayLog = new LinkedList<>(); - - private ARGWebDebugger() { - } + private ARGWebDebugger() {} private static void startServer() { if (!on) return; @@ -54,19 +47,23 @@ private static void startServer() { config.setPort(PORT); server = new SocketIOServer(config); - server.addEventListener("continue", String.class, (client, data, ackSender) -> { - received = true; - synchronized (lock) { - lock.notifyAll(); - } - }); - server.addConnectListener(client -> { - for (String s : replayLog) { - System.err.println("Replaying " + s); - client.sendEvent("message", s); - } - if (waiting) client.sendEvent("message", "{\"method\": \"wait\"}"); - }); + server.addEventListener( + "continue", + String.class, + (client, data, ackSender) -> { + received = true; + synchronized (lock) { + lock.notifyAll(); + } + }); + server.addConnectListener( + client -> { + for (String s : replayLog) { + System.err.println("Replaying " + s); + client.sendEvent("message", s); + } + if (waiting) client.sendEvent("message", "{\"method\": \"wait\"}"); + }); server.start(); waitUntil(); } @@ -94,16 +91,38 @@ private static void waitUntil() { } } - private static String nodeToString(ArgNode node, A action) { - return "{\"name\": \"Node " + node.getId() + "\"," + - " \"attributes\": {" + - (action == null ? "" : "\"action\": \"" + action.toString().replaceAll("[\\n\\r\\t\"]", " ") + "\",") + - "\"state\": \"" + node.getState().toString().replaceAll("[\\n\\r\\t\"]", " ") + "\"" + "," + - "\"target\": \"" + node.isTarget() + "\"" + "}," + - " \"tooltip\": {" + - (action == null ? "" : "\"action\": \"" + action.toString().replaceAll("[\\n\\r\\t\"]", " ") + "\",") + - "\"state\": \"" + node.getState().toString().replaceAll("[\\n\\r\\t\"]", " ") + "\"" + "}," + - " \"id\": " + node.getId() + "}"; + private static String nodeToString( + ArgNode node, A action) { + return "{\"name\": \"Node " + + node.getId() + + "\"," + + " \"attributes\": {" + + (action == null + ? "" + : "\"action\": \"" + + action.toString().replaceAll("[\\n\\r\\t\"]", " ") + + "\",") + + "\"state\": \"" + + node.getState().toString().replaceAll("[\\n\\r\\t\"]", " ") + + "\"" + + "," + + "\"target\": \"" + + node.isTarget() + + "\"" + + "}," + + " \"tooltip\": {" + + (action == null + ? "" + : "\"action\": \"" + + action.toString().replaceAll("[\\n\\r\\t\"]", " ") + + "\",") + + "\"state\": \"" + + node.getState().toString().replaceAll("[\\n\\r\\t\"]", " ") + + "\"" + + "}," + + " \"id\": " + + node.getId() + + "}"; } public static void create(ArgNode initNode) { @@ -115,13 +134,20 @@ public static void create(ArgNode initNode) { waitUntil(); } - public static void add(ArgNode parent, - A action, - ArgNode child) { + public static void add( + ArgNode parent, + A action, + ArgNode child) { if (!on) { return; } - send("{\"method\": \"add\", \"parent\": " + parent.getId() + ", \"child\": " + nodeToString(child, action) + "}", true); + send( + "{\"method\": \"add\", \"parent\": " + + parent.getId() + + ", \"child\": " + + nodeToString(child, action) + + "}", + true); waitUntil(); } @@ -129,7 +155,13 @@ public static void remove(ArgEdge private final Refiner refiner; private final Logger logger; private final Pr proof; - public final ProofVisualizer proofVisualizer; + private final ProofVisualizer proofVisualizer; private CegarChecker( final Abstractor abstractor, diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/CegarStatistics.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/CegarStatistics.java index 119067b8be..5b22ec9b56 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/CegarStatistics.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/CegarStatistics.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,9 +17,7 @@ import hu.bme.mit.theta.analysis.algorithm.Statistics; -/** - * Represents statistics collected by the CegarChecker algorithm. - */ +/** Represents statistics collected by the CegarChecker algorithm. */ public final class CegarStatistics extends Statistics { private final long algorithmTimeMs; @@ -27,9 +25,11 @@ public final class CegarStatistics extends Statistics { private final long refinerTimeMs; private final int iterations; - public CegarStatistics(final long algorithmTimeMs, final long abstractorTimeMs, - final long refinerTimeMs, - final int iterations) { + public CegarStatistics( + final long algorithmTimeMs, + final long abstractorTimeMs, + final long refinerTimeMs, + final int iterations) { this.algorithmTimeMs = algorithmTimeMs; this.abstractorTimeMs = abstractorTimeMs; this.refinerTimeMs = refinerTimeMs; @@ -54,5 +54,4 @@ public long getRefinerTimeMs() { public int getIterations() { return iterations; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/Refiner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/Refiner.java index 819bd3c403..8f89752884 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/Refiner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/Refiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/RefinerResult.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/RefinerResult.java index 63011b7d08..9dc254efeb 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/RefinerResult.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/RefinerResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterion.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterion.java index fc5d1c00ed..2fed6f736d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterion.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterion.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,12 +19,9 @@ import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; - import java.util.Collection; -/** - * Interface for stopping criterions during abstraction. - */ +/** Interface for stopping criterions during abstraction. */ public interface StopCriterion { /** @@ -39,7 +36,7 @@ public interface StopCriterion { * Check if abstraction can stop based on the whole ARG or based on the new successor nodes * (optimization: the whole ARG might not be needed). * - * @param arg ARG + * @param arg ARG * @param newNodes New successor nodes * @return True if abstraction can stop */ diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterions.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterions.java index e8cdf50e57..fa772bf12e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterions.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/cegar/abstractor/StopCriterions.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,23 +15,19 @@ */ package hu.bme.mit.theta.analysis.algorithm.cegar.abstractor; +import static com.google.common.base.Preconditions.checkArgument; + import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.algorithm.arg.ARG; import hu.bme.mit.theta.analysis.algorithm.arg.ArgNode; import hu.bme.mit.theta.common.Utils; - import java.util.Collection; -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Implementations for different stop criterions. - */ +/** Implementations for different stop criterions. */ public final class StopCriterions { - private StopCriterions() { - } + private StopCriterions() {} /** * @return Criterion that stops at the first counterexample @@ -51,32 +47,38 @@ public static StopCriterion fullExplor * @param n Number of counterexamples to collect * @return Criterion that stops after a given number of counterexamples */ - public static StopCriterion atLeastNCexs(final int n) { + public static StopCriterion atLeastNCexs( + final int n) { return new AtLeastNCexs<>(n); } - private static final class FirstCex implements StopCriterion { + private static final class FirstCex + implements StopCriterion { @Override public boolean canStop(final ARG arg) { // TODO Move runtime check out to CegarChecker? (CexMonitor) - return arg.getUnsafeNodes().findAny().isPresent(); // && arg.getCexs().anyMatch(cex -> ArgCexCheckHandler.instance.checkIfCounterexampleNew(cex)); + return arg.getUnsafeNodes().findAny().isPresent(); // && arg.getCexs().anyMatch(cex -> + // ArgCexCheckHandler.instance.checkIfCounterexampleNew(cex)); } @Override public boolean canStop(ARG arg, Collection> newNodes) { // TODO Move runtime check out to CegarChecker? (CexMonitor) return (newNodes.stream().anyMatch(n -> n.isTarget() && !n.isExcluded())); - // && arg.getCexs().anyMatch(cex -> ArgCexCheckHandler.instance.checkIfCounterexampleNew(cex))); + // && arg.getCexs().anyMatch(cex -> + // ArgCexCheckHandler.instance.checkIfCounterexampleNew(cex))); } @Override public String toString() { - return Utils.lispStringBuilder(StopCriterion.class.getSimpleName()).add(getClass().getSimpleName()) + return Utils.lispStringBuilder(StopCriterion.class.getSimpleName()) + .add(getClass().getSimpleName()) .toString(); } } - private static final class FullExploration implements StopCriterion { + private static final class FullExploration + implements StopCriterion { @Override public boolean canStop(final ARG arg) { return false; @@ -89,12 +91,14 @@ public boolean canStop(ARG arg, Collection> newNodes) { @Override public String toString() { - return Utils.lispStringBuilder(StopCriterion.class.getSimpleName()).add(getClass().getSimpleName()) + return Utils.lispStringBuilder(StopCriterion.class.getSimpleName()) + .add(getClass().getSimpleName()) .toString(); } } - private static final class AtLeastNCexs implements StopCriterion { + private static final class AtLeastNCexs + implements StopCriterion { private final int n; private AtLeastNCexs(final int n) { @@ -116,8 +120,10 @@ public boolean canStop(ARG arg, Collection> newNodes) { @Override public String toString() { - return Utils.lispStringBuilder(StopCriterion.class.getSimpleName()).add(getClass().getSimpleName()) - .add("N = " + n).toString(); + return Utils.lispStringBuilder(StopCriterion.class.getSimpleName()) + .add(getClass().getSimpleName()) + .add("N = " + n) + .toString(); } } } 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 a52da53d51..56b62e3fde 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/AcceptancePredicate.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/AcceptancePredicate.kt index a0ff8bc98b..ebdd620691 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/AcceptancePredicate.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/AcceptancePredicate.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/ASGAbstractor.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/ASGAbstractor.kt index 1bfe96a05c..4638971c38 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/ASGAbstractor.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/ASGAbstractor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -32,7 +32,7 @@ class ASGAbstractor( private val analysis: Analysis, private val lts: LTS, private val acceptancePredicate: AcceptancePredicate, - private val searchStrategy: LoopcheckerSearchStrategy, + private val searchStrategy: LoopCheckerSearchStrategy, private val logger: Logger, ) : Abstractor> { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/GdfsSearchStrategies.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/GdfsSearchStrategies.kt index 7d09704af8..74d201ecfc 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/GdfsSearchStrategies.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/GdfsSearchStrategies.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,7 +28,7 @@ typealias BacktrackResult = Pair>?, List> fun combineLassos(results: Collection>) = Pair(setOf>(), results.flatMap { it.second ?: emptyList() }) -abstract class AbstractSearchStrategy : ILoopcheckerSearchStrategy { +abstract class AbstractSearchStrategy : ILoopCheckerSearchStrategy { internal fun expandFromInitNodeUntilTarget( initNode: ASGNode, diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/LoopcheckerSearchStrategy.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/LoopCheckerSearchStrategy.kt similarity index 90% rename from subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/LoopcheckerSearchStrategy.kt rename to subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/LoopCheckerSearchStrategy.kt index e3d3f35b9e..f4329a5816 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/LoopcheckerSearchStrategy.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/LoopCheckerSearchStrategy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,7 +27,7 @@ import hu.bme.mit.theta.common.logging.NullLogger typealias NodeExpander = (ASGNode) -> Collection> -enum class LoopcheckerSearchStrategy(private val strategy: ILoopcheckerSearchStrategy) { +enum class LoopCheckerSearchStrategy(private val strategy: ILoopCheckerSearchStrategy) { GDFS(GdfsSearchStrategy), NDFS(NdfsSearchStrategy), FULL(FullSearchStrategy); @@ -45,7 +45,7 @@ enum class LoopcheckerSearchStrategy(private val strategy: ILoopcheckerSearchStr ): Collection> = strategy.search(ASG.initNodes, target, expand, logger) } -interface ILoopcheckerSearchStrategy { +interface ILoopCheckerSearchStrategy { fun search( initNodes: Collection>, diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/NdfsSearchStrategy.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/NdfsSearchStrategy.kt index 52e58f653b..8171fab9bc 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/NdfsSearchStrategy.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/abstraction/NdfsSearchStrategy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,7 +23,7 @@ import hu.bme.mit.theta.analysis.expr.ExprAction import hu.bme.mit.theta.analysis.expr.ExprState import hu.bme.mit.theta.common.logging.Logger -object NdfsSearchStrategy : ILoopcheckerSearchStrategy { +object NdfsSearchStrategy : ILoopCheckerSearchStrategy { override fun search( initNodes: Collection>, diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/InvalidPathException.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/InvalidPathException.kt index 080d013855..d656d20530 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/InvalidPathException.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/InvalidPathException.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/TraceCheckingFailedException.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/TraceCheckingFailedException.kt index 3063ed43e0..c821d708d6 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/TraceCheckingFailedException.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/exception/TraceCheckingFailedException.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/ASGTraceCheckerStrategy.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/ASGTraceCheckerStrategy.kt index 3fd2f8f7be..2a70016c63 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/ASGTraceCheckerStrategy.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/ASGTraceCheckerStrategy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/BoundedUnrollingASGTraceCheckerStrategy.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/BoundedUnrollingASGTraceCheckerStrategy.kt index 8afff23418..abb31864f7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/BoundedUnrollingASGTraceCheckerStrategy.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/BoundedUnrollingASGTraceCheckerStrategy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/DirectRefinementASGTraceCheckerStrategy.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/DirectRefinementASGTraceCheckerStrategy.kt index e9382175b3..f63603d24d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/DirectRefinementASGTraceCheckerStrategy.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/DirectRefinementASGTraceCheckerStrategy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/SingleASGTraceRefiner.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/SingleASGTraceRefiner.kt index aefb9135ed..d7ded91c06 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/SingleASGTraceRefiner.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/refinement/SingleASGTraceRefiner.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/util/VarCollectorStmtVisitor.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/util/VarCollectorStmtVisitor.kt index 29fb6add20..45d7da0847 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/util/VarCollectorStmtVisitor.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/loopchecker/util/VarCollectorStmtVisitor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 6708288159..c99d0594fc 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/FiniteStateChecker.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/FiniteStateChecker.kt index b316300d9c..71116d0126 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/FiniteStateChecker.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/analysis/FiniteStateChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 f894815a7e..301bfd4926 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/interpreter/MemoryEventProvider.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/interpreter/MemoryEventProvider.kt index ae6bdacad5..358b040440 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/interpreter/MemoryEventProvider.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mcm/interpreter/MemoryEventProvider.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm.mcm.interpreter import hu.bme.mit.theta.analysis.Action @@ -22,5 +21,5 @@ import hu.bme.mit.theta.analysis.algorithm.mcm.MemoryEvent fun interface MemoryEventProvider { - operator fun get(a: A, p: P): MemoryEvent? -} \ No newline at end of file + operator fun get(a: A, p: P): MemoryEvent? +} diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddAnalysisStatistics.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddAnalysisStatistics.java index 2f3cc7978b..542f009975 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddAnalysisStatistics.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddAnalysisStatistics.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,8 +25,12 @@ public class MddAnalysisStatistics extends Statistics { private final Long queryCount; private final Long cacheSize; - - public MddAnalysisStatistics(Long violatingSize, Long stateSpaceSize, Long hitCount, Long queryCount, Long cacheSize) { + public MddAnalysisStatistics( + Long violatingSize, + Long stateSpaceSize, + Long hitCount, + Long queryCount, + Long cacheSize) { this.violatingSize = violatingSize; this.stateSpaceSize = stateSpaceSize; this.hitCount = hitCount; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCex.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCex.java index 0e5f51a40a..1595c8b73b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCex.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddCex.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddChecker.java index 02638bdc60..00304c379f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddProof.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddProof.java index 805a138399..9b47b4d9be 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddProof.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddProof.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddValuationCollector.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddValuationCollector.java index 71960a234f..6668a0e8fd 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddValuationCollector.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/MddValuationCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,13 +24,12 @@ import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; - import java.util.Set; import java.util.Stack; /** - * A utility class for collecting all vectors from a subtree represented by a symbolic node. - * Only works with finite diagrams, but can handle default edges. + * A utility class for collecting all vectors from a subtree represented by a symbolic node. Only + * works with finite diagrams, but can handle default edges. */ public class MddValuationCollector { @@ -61,7 +60,11 @@ public static Set collect(MddNode node) { return valuations; } - private static void collect(MddNode node, RecursiveIntObjCursor cursor, Stack assignments, Set valuations) { + private static void collect( + MddNode node, + RecursiveIntObjCursor cursor, + Stack assignments, + Set valuations) { if (node.isTerminal()) { valuations.add(toValuation(assignments)); } else { @@ -77,8 +80,13 @@ private static void collect(MddNode node, RecursiveIntObjCursor assignments) { assignments.stream().forEach(ass -> builder.put(ass.decl, ass.value)); return builder.build(); } - - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/AbstractNextStateDescriptor.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/AbstractNextStateDescriptor.java index 3e77238e48..e6b320ee12 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/AbstractNextStateDescriptor.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/AbstractNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/StateSpaceInfo.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/StateSpaceInfo.java index e610450c69..326e62ab41 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/StateSpaceInfo.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/StateSpaceInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,9 +19,8 @@ import hu.bme.mit.delta.java.mdd.MddNode; /** - * Represents a sub-state space of the system under analysis. Instances of this - * type have some sort of a decision diagram node underneath to represent the - * reachable substates. + * Represents a sub-state space of the system under analysis. Instances of this type have some sort + * of a decision diagram node underneath to represent the reachable substates. * * @author Vince Molnar */ @@ -38,22 +37,20 @@ default T getTraceInfo(Class typeToken) { } /** - * Returns true if the underlying component is known to have specific reachable states, - * false if its state space is undefined, that is, it can be in any state. + * Returns true if the underlying component is known to have specific reachable states, false if + * its state space is undefined, that is, it can be in any state. * - * @return True if the underlying component has specific reachable states, false - * if its state space is undefined. + * @return True if the underlying component has specific reachable states, false if its state + * space is undefined. */ public boolean hasInfiniteStates(); /** - * Gets the local states of the underlying component that are contained in the - * current sub-state space. Returns {@code null} if - * {@link #hasInfiniteStates()} returns false. + * Gets the local states of the underlying component that are contained in the current sub-state + * space. Returns {@code null} if {@link #hasInfiniteStates()} returns false. * - * @return The local states of the underlying component that are contained in - * the current sub-state space or {@code null} if the state space is - * undefined. + * @return The local states of the underlying component that are contained in the current + * sub-state space or {@code null} if the state space is undefined. */ public IntSetView getLocalStateSpace(); @@ -61,13 +58,12 @@ default T getTraceInfo(Class typeToken) { // the actual states instead of relying on the domain registry? /** - * Gets the local states of {@code someLowerComponent} that are contained in the - * current sub-state space. Returns {@code null} if - * the state space of {@code someLowerComponent} is undefined. + * Gets the local states of {@code someLowerComponent} that are contained in the current + * sub-state space. Returns {@code null} if the state space of {@code someLowerComponent} is + * undefined. * - * @return The local states of the underlying component that are contained in - * the current sub-state space or {@code null} if the state space is - * undefined. + * @return The local states of the underlying component that are contained in the current + * sub-state space or {@code null} if the state space is undefined. */ public StateSpaceInfo getLocalStateSpace(Object someLowerComponent); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/AnyNextStateDescriptor.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/AnyNextStateDescriptor.java index 9db4726d48..19023dc141 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/AnyNextStateDescriptor.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/AnyNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.analysis.algorithm.mdd.ansd.impl; -import java.util.Optional; - import hu.bme.mit.delta.collections.IntObjMapView; import hu.bme.mit.delta.collections.UniqueTable; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.StateSpaceInfo; +import java.util.Optional; public class AnyNextStateDescriptor implements AbstractNextStateDescriptor { - private static final UniqueTable uniqueTable = UniqueTable.newInstance(); + private static final UniqueTable uniqueTable = + UniqueTable.newInstance(); public static AbstractNextStateDescriptor withChild(AbstractNextStateDescriptor child) { return uniqueTable.checkIn(new AnyNextStateDescriptor(child)); @@ -56,5 +56,4 @@ public Optional> split() { // TODO: this might be a performance overhead return Optional.empty(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/EmptyNextStateDescriptor.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/EmptyNextStateDescriptor.java index 41c69d9c4a..a723d0c4ec 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/EmptyNextStateDescriptor.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/EmptyNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,13 @@ */ package hu.bme.mit.theta.analysis.algorithm.mdd.ansd.impl; -import java.util.Optional; - import hu.bme.mit.delta.collections.IntObjMapView; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.StateSpaceInfo; +import java.util.Optional; public final class EmptyNextStateDescriptor implements AbstractNextStateDescriptor { - private EmptyNextStateDescriptor() { - } + private EmptyNextStateDescriptor() {} public static final EmptyNextStateDescriptor INSTANCE = new EmptyNextStateDescriptor(); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/IdentityNextStateDescriptor.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/IdentityNextStateDescriptor.java index 9a1e4a93f7..632560997f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/IdentityNextStateDescriptor.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/IdentityNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,18 @@ */ package hu.bme.mit.theta.analysis.algorithm.mdd.ansd.impl; -import java.util.Optional; - import hu.bme.mit.delta.collections.IntObjMapView; import hu.bme.mit.delta.collections.UniqueTable; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.StateSpaceInfo; +import java.util.Optional; public final class IdentityNextStateDescriptor implements AbstractNextStateDescriptor { - private static final UniqueTable uniqueTable = UniqueTable.newInstance(); + private static final UniqueTable uniqueTable = + UniqueTable.newInstance(); - public static final AbstractNextStateDescriptor TERMINAL_IDENTITY = new IdentityNextStateDescriptor(); + public static final AbstractNextStateDescriptor TERMINAL_IDENTITY = + new IdentityNextStateDescriptor(); public static AbstractNextStateDescriptor withChild(AbstractNextStateDescriptor child) { return uniqueTable.checkIn(new IdentityNextStateDescriptor(child)); @@ -51,7 +52,8 @@ public IntObjMapView getDiagonal(StateSpaceInfo loc public IntObjMapView> getOffDiagonal( StateSpaceInfo localStateSpace) { // TODO: cache this instead of creating on demand - return IntObjMapView.empty(IntObjMapView.empty(AbstractNextStateDescriptor.terminalEmpty())); + return IntObjMapView.empty( + IntObjMapView.empty(AbstractNextStateDescriptor.terminalEmpty())); } @Override diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeInitializer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeInitializer.java index eca33182c3..560779d142 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeInitializer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeNextStateDescriptor.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeNextStateDescriptor.java index 543dec5082..f35b059a18 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeNextStateDescriptor.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/MddNodeNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/OrNextStateDescriptor.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/OrNextStateDescriptor.java index 3274bfbd6c..008424b8eb 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/OrNextStateDescriptor.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/ansd/impl/OrNextStateDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,7 +24,6 @@ import hu.bme.mit.delta.collections.impl.MapUniqueTable; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.StateSpaceInfo; - import java.util.*; import java.util.stream.Collectors; @@ -37,8 +36,11 @@ public static void clearUniqueTable() { private List operands; - private Map> diagonalCache = HashObjObjMaps.newUpdatableMap(); - //private IntObjMap> offDiagonalCache = HashIntObjMaps.newUpdatableMap(); + private Map> diagonalCache = + HashObjObjMaps.newUpdatableMap(); + + // private IntObjMap> offDiagonalCache = + // HashIntObjMaps.newUpdatableMap(); public static OrNextStateDescriptor create(final List operands) { final ArrayList ops = new ArrayList<>(operands); @@ -52,7 +54,8 @@ private OrNextStateDescriptor(final List operands) } @Override - public IntObjMapView getDiagonal(final StateSpaceInfo localStateSpace) { + public IntObjMapView getDiagonal( + final StateSpaceInfo localStateSpace) { class Diagonal implements IntObjMapView { private final StateSpaceInfo localStateSpace; List> diagonals = new ArrayList<>(); @@ -147,30 +150,32 @@ public AbstractNextStateDescriptor defaultValue() { public IntObjCursor cursor() { // TODO: Auto-generated method stub. throw new UnsupportedOperationException("Not (yet) implemented."); - //return 0; + // return 0; } @Override public int size() { // TODO: Auto-generated method stub. throw new UnsupportedOperationException("Not (yet) implemented."); - //return 0; + // return 0; } } ; - IntObjMapView ret = diagonalCache.computeIfAbsent(localStateSpace.getTraceInfo(), - (o) -> new Diagonal(operands, - localStateSpace)); + IntObjMapView ret = + diagonalCache.computeIfAbsent( + localStateSpace.getTraceInfo(), + (o) -> new Diagonal(operands, localStateSpace)); return ret; } @Override - public IntObjMapView> getOffDiagonal(final StateSpaceInfo localStateSpace) { + public IntObjMapView> getOffDiagonal( + final StateSpaceInfo localStateSpace) { // TODO: Auto-generated method stub. throw new UnsupportedOperationException("Not (yet) implemented."); - //return null; + // return null; } @Override @@ -210,7 +215,8 @@ public Cursor cursor(int from, StateSpaceInfo localStateSpace) { @Override public Cursor rootCursor() { - return RootOrCursor.of(operands.stream().map(AbstractNextStateDescriptor::rootCursor).toList()); + return RootOrCursor.of( + operands.stream().map(AbstractNextStateDescriptor::rootCursor).toList()); } public static class RootOrCursor implements AbstractNextStateDescriptor.Cursor { @@ -253,7 +259,8 @@ public boolean moveTo(int key) { @Override public Cursor valueCursor(int from, StateSpaceInfo localStateSpace) { - return OrCursor.of(cursors.stream().map(c -> c.valueCursor(from, localStateSpace)).toList()); + return OrCursor.of( + cursors.stream().map(c -> c.valueCursor(from, localStateSpace)).toList()); } @Override @@ -265,7 +272,6 @@ public void close() { public Optional> split() { return Optional.of(cursors); } - } public static class OrCursor implements AbstractNextStateDescriptor.Cursor { @@ -281,7 +287,8 @@ private OrCursor(final List cursors) { this.key = Optional.empty(); } - public static AbstractNextStateDescriptor.Cursor of(final List cursors) { + public static AbstractNextStateDescriptor.Cursor of( + final List cursors) { if (cursors.size() == 1) return cursors.get(0); else return new OrCursor(cursors); } @@ -300,7 +307,11 @@ public AbstractNextStateDescriptor value() { } else if (activeCursors.size() == 1) { ret = activeCursors.get(0).value(); } else { - ret = OrNextStateDescriptor.create(activeCursors.stream().map(AbstractNextStateDescriptor.Cursor::value).toList()); + ret = + OrNextStateDescriptor.create( + activeCursors.stream() + .map(AbstractNextStateDescriptor.Cursor::value) + .toList()); } return ret; } @@ -329,8 +340,10 @@ public boolean moveTo(int key) { } @Override - public AbstractNextStateDescriptor.Cursor valueCursor(int from, StateSpaceInfo localStateSpace) { - return OrCursor.of(activeCursors.stream().map(c -> c.valueCursor(from, localStateSpace)).toList()); + public AbstractNextStateDescriptor.Cursor valueCursor( + int from, StateSpaceInfo localStateSpace) { + return OrCursor.of( + activeCursors.stream().map(c -> c.valueCursor(from, localStateSpace)).toList()); } @Override diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/ExprLatticeDefinition.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/ExprLatticeDefinition.java index 7c67ea0d3a..75b6587ba0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/ExprLatticeDefinition.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/ExprLatticeDefinition.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.analysis.algorithm.mdd.expressionnode; -import hu.bme.mit.delta.mdd.LatticeDefinition; -import hu.bme.mit.theta.core.type.Expr; -import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; - import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; +import hu.bme.mit.delta.mdd.LatticeDefinition; +import hu.bme.mit.theta.core.type.Expr; +import hu.bme.mit.theta.core.type.booltype.SmartBoolExprs; public class ExprLatticeDefinition { @@ -34,8 +33,6 @@ public static LatticeDefinition forExpr() { True(), SmartBoolExprs::Or, SmartBoolExprs::And, - (a, b) -> And(a, Not(b)) - ); + (a, b) -> And(a, Not(b))); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/LitExprConverter.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/LitExprConverter.java index 34d32df077..4277bcc750 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/LitExprConverter.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/LitExprConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionRepresentation.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionRepresentation.java index 927c63e066..2b60ba09a5 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionRepresentation.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionRepresentation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionTemplate.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionTemplate.java index 97340dfbf4..2fa96ed660 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionTemplate.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/expressionnode/MddExpressionTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,15 +20,14 @@ import hu.bme.mit.delta.java.mdd.MddGraph; import hu.bme.mit.delta.java.mdd.MddNode; import hu.bme.mit.delta.java.mdd.MddVariable; -import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.booltype.FalseExpr; import hu.bme.mit.theta.core.utils.ExprUtils; import hu.bme.mit.theta.solver.Solver; +import hu.bme.mit.theta.solver.SolverPool; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.function.Function; public class MddExpressionTemplate implements MddNode.Template { @@ -49,32 +48,36 @@ private static boolean isSat(Expr expr, SolverPool solverPool) { return res; } - private MddExpressionTemplate(Expr expr, Function extractDecl, SolverPool solverPool) { + private MddExpressionTemplate( + Expr expr, Function extractDecl, SolverPool solverPool) { this.expr = expr; this.extractDecl = extractDecl; this.solverPool = solverPool; } - public static MddExpressionTemplate of(Expr expr, Function extractDecl, SolverPool solverPool) { + public static MddExpressionTemplate of( + Expr expr, Function extractDecl, SolverPool solverPool) { return new MddExpressionTemplate(expr, extractDecl, solverPool); } @Override - public RecursiveIntObjMapView toCanonicalRepresentation(MddVariable mddVariable, MddCanonizationStrategy mddCanonizationStrategy) { + public RecursiveIntObjMapView toCanonicalRepresentation( + MddVariable mddVariable, MddCanonizationStrategy mddCanonizationStrategy) { final Decl decl = extractDecl.apply(mddVariable.getTraceInfo()); final Expr canonizedExpr = ExprUtils.canonize(ExprUtils.simplify(expr)); -// // TODO: we might not need this -// // Check if terminal 1 -// if (ExprUtils.getConstants(canonizedExpr).isEmpty()) { -// if (canonizedExpr instanceof FalseExpr) { -// return mddVariable.getMddGraph().getTerminalZeroNode(); -// } /*else { -// final MddGraph mddGraph = (MddGraph) mddVariable.getMddGraph(); -// return mddGraph.getNodeFor(canonizedExpr); -// }*/ -// } + // // TODO: we might not need this + // // Check if terminal 1 + // if (ExprUtils.getConstants(canonizedExpr).isEmpty()) { + // if (canonizedExpr instanceof FalseExpr) { + // return mddVariable.getMddGraph().getTerminalZeroNode(); + // } /*else { + // final MddGraph mddGraph = (MddGraph) + // mddVariable.getMddGraph(); + // return mddGraph.getNodeFor(canonizedExpr); + // }*/ + // } // Check if terminal 0 if (canonizedExpr instanceof FalseExpr || !isSat(canonizedExpr, solverPool)) { @@ -82,18 +85,25 @@ public RecursiveIntObjMapView toCanonicalRepresentation(MddVa } // Check if default - if (mddVariable.getDomainSize() == 0 && !ExprUtils.getConstants(canonizedExpr).contains(decl)) { + if (mddVariable.getDomainSize() == 0 + && !ExprUtils.getConstants(canonizedExpr).contains(decl)) { final MddNode childNode; if (mddVariable.getLower().isPresent()) { - childNode = mddVariable.getLower().get().checkInNode(new MddExpressionTemplate(canonizedExpr, o -> (Decl) o, solverPool)); + childNode = + mddVariable + .getLower() + .get() + .checkInNode( + new MddExpressionTemplate( + canonizedExpr, o -> (Decl) o, solverPool)); } else { final MddGraph mddGraph = (MddGraph) mddVariable.getMddGraph(); childNode = mddGraph.getNodeFor(canonizedExpr); } - return MddExpressionRepresentation.ofDefault(canonizedExpr, decl, mddVariable, solverPool, childNode); + return MddExpressionRepresentation.ofDefault( + canonizedExpr, decl, mddVariable, solverPool, childNode); } return MddExpressionRepresentation.of(canonizedExpr, decl, mddVariable, solverPool); - } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/BfsProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/BfsProvider.java index 0cf6087fa3..37d83a62ef 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/BfsProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/BfsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import hu.bme.mit.delta.java.mdd.*; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; - import java.util.Optional; public final class BfsProvider implements StateSpaceEnumerationProvider { public static boolean verbose = false; - private final CacheManager> cacheManager = new CacheManager<>( - v -> new BinaryOperationCache<>()); + private final CacheManager> + cacheManager = new CacheManager<>(v -> new BinaryOperationCache<>()); private final MddVariableOrder variableOrder; private final RelationalProductProvider relProdProvider; @@ -32,7 +31,8 @@ public BfsProvider(final MddVariableOrder variableOrder) { this(variableOrder, new LegacyRelationalProductProvider(variableOrder)); } - public BfsProvider(final MddVariableOrder variableOrder, final RelationalProductProvider relProdProvider) { + public BfsProvider( + final MddVariableOrder variableOrder, final RelationalProductProvider relProdProvider) { this.variableOrder = variableOrder; this.relProdProvider = relProdProvider; this.variableOrder.getMddGraph().registerCleanupListener(this); @@ -41,10 +41,13 @@ public BfsProvider(final MddVariableOrder variableOrder, final RelationalProduct public MddHandle compute( AbstractNextStateDescriptor.Postcondition initializer, AbstractNextStateDescriptor nextStateRelation, - MddVariableHandle highestAffectedVariable - ) { + MddVariableHandle highestAffectedVariable) { - final MddHandle initialStates = relProdProvider.compute(variableOrder.getMddGraph().getHandleForTop(), initializer, highestAffectedVariable); + final MddHandle initialStates = + relProdProvider.compute( + variableOrder.getMddGraph().getHandleForTop(), + initializer, + highestAffectedVariable); MddNode result; @@ -52,11 +55,13 @@ public MddHandle compute( final MddVariable variable = highestAffectedVariable.getVariable().get(); result = this.compute(initialStates.getNode(), nextStateRelation, variable); } else { - result = this.computeTerminal(initialStates.getNode(), nextStateRelation, - highestAffectedVariable.getMddGraph()); + result = + this.computeTerminal( + initialStates.getNode(), + nextStateRelation, + highestAffectedVariable.getMddGraph()); } - return highestAffectedVariable.getHandleFor(result); } @@ -64,8 +69,7 @@ public MddHandle compute( public MddNode compute( final MddNode mddNode, final AbstractNextStateDescriptor nextStateRelation, - final MddVariable mddVariable - ) { + final MddVariable mddVariable) { MddNode res = variableOrder.getMddGraph().getTerminalZeroNode(); MddNode nextLayer = mddNode; @@ -78,19 +82,26 @@ public MddNode compute( // System.out.println(GraphvizSerializer.serialize(variableOrder.getDefaultSetSignature().getTopVariableHandle().getHandleFor(nextLayer))); } res = nextLayer; - final Optional> splitNS = nextStateRelation.split(); + final Optional> splitNS = + nextStateRelation.split(); if (splitNS.isPresent()) { for (AbstractNextStateDescriptor next : splitNS.get()) { if (verbose) { System.out.println("Applying transition: " + next); } - nextLayer = mddVariable.union(nextLayer, relProdProvider.compute(nextLayer, next, mddVariable)); + nextLayer = + mddVariable.union( + nextLayer, + relProdProvider.compute(nextLayer, next, mddVariable)); } } else { if (verbose) { System.out.println("Applying transition: " + nextStateRelation); } - nextLayer = mddVariable.union(nextLayer, relProdProvider.compute(nextLayer, nextStateRelation, mddVariable)); + nextLayer = + mddVariable.union( + nextLayer, + relProdProvider.compute(nextLayer, nextStateRelation, mddVariable)); } } @@ -99,16 +110,16 @@ public MddNode compute( @Override public MddNode computeTerminal( - final MddNode mddNode, final AbstractNextStateDescriptor nextStateRelation, final MddGraph mddGraph - ) { + final MddNode mddNode, + final AbstractNextStateDescriptor nextStateRelation, + final MddGraph mddGraph) { MddNode res = variableOrder.getMddGraph().getTerminalZeroNode(); MddNode nextLayer = mddNode; while (res != nextLayer) { - nextLayer = mddGraph.unionTerminal( - res, - relProdProvider.computeTerminal(res, nextStateRelation, mddGraph) - ); + nextLayer = + mddGraph.unionTerminal( + res, relProdProvider.computeTerminal(res, nextStateRelation, mddGraph)); } return res; @@ -126,10 +137,12 @@ public void clear() { @Override public void cleanup() { - this.cacheManager.forEachCache((cache) -> cache.clearSelectively((source, ns, result) -> source.getReferenceCount() == - 0 || - result.getReferenceCount() == - 0)); + this.cacheManager.forEachCache( + (cache) -> + cache.clearSelectively( + (source, ns, result) -> + source.getReferenceCount() == 0 + || result.getReferenceCount() == 0)); } public Cache getRelProdCache() { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorGeneralizedSaturationProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorGeneralizedSaturationProvider.java index faeb8e8dd4..475265c45d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorGeneralizedSaturationProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorGeneralizedSaturationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,18 +22,19 @@ import hu.bme.mit.delta.java.mdd.*; import hu.bme.mit.delta.java.mdd.impl.MddStructuralTemplate; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; - import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import java.util.function.ToLongFunction; -public final class CursorGeneralizedSaturationProvider implements MddTransformationProvider { +public final class CursorGeneralizedSaturationProvider + implements MddTransformationProvider { public static boolean verbose = false; private MddVariableOrder variableOrder; private RelationalProductProvider relProdProvider; - private final CacheManager cacheManager = new CacheManager<>(v -> new SaturationCache()); + private final CacheManager cacheManager = + new CacheManager<>(v -> new SaturationCache()); private MddNode terminalZeroNode; public CursorGeneralizedSaturationProvider(final MddVariableOrder variableOrder) { @@ -41,8 +42,7 @@ public CursorGeneralizedSaturationProvider(final MddVariableOrder variableOrder) } public CursorGeneralizedSaturationProvider( - final MddVariableOrder variableOrder, final RelationalProductProvider relProdProvider - ) { + final MddVariableOrder variableOrder, final RelationalProductProvider relProdProvider) { this.variableOrder = variableOrder; this.relProdProvider = relProdProvider; this.variableOrder.getMddGraph().registerCleanupListener(this); @@ -52,9 +52,12 @@ public CursorGeneralizedSaturationProvider( public MddHandle compute( AbstractNextStateDescriptor.Postcondition initializer, AbstractNextStateDescriptor nextStateRelation, - MddVariableHandle highestAffectedVariable - ) { - final MddHandle initialStates = relProdProvider.compute(variableOrder.getMddGraph().getHandleForTop(), initializer, highestAffectedVariable); + MddVariableHandle highestAffectedVariable) { + final MddHandle initialStates = + relProdProvider.compute( + variableOrder.getMddGraph().getHandleForTop(), + initializer, + highestAffectedVariable); MddNode result; @@ -62,10 +65,11 @@ public MddHandle compute( final MddVariable variable = highestAffectedVariable.getVariable().get(); result = this.compute(initialStates.getNode(), nextStateRelation, variable); } else { - result = this.computeTerminal(initialStates.getNode(), - nextStateRelation, - highestAffectedVariable.getMddGraph() - ); + result = + this.computeTerminal( + initialStates.getNode(), + nextStateRelation, + highestAffectedVariable.getMddGraph()); } return highestAffectedVariable.getHandleFor(result); @@ -75,8 +79,9 @@ private MddNode recurse( final MddNode mddNode, final AbstractNextStateDescriptor nextState, MddVariable currentVariable, - final CacheManager>.CacheHolder cache - ) { + final CacheManager> + .CacheHolder + cache) { if (currentVariable.getLower().isPresent()) { return compute(mddNode, nextState, currentVariable.getLower().get()); } else { @@ -85,8 +90,7 @@ private MddNode recurse( } private MddNode unionChildren( - final MddNode lhs, final MddNode rhs, MddVariable currentVariable - ) { + final MddNode lhs, final MddNode rhs, MddVariable currentVariable) { if (currentVariable.getLower().isPresent()) { return currentVariable.getLower().get().union(lhs, rhs); } else { @@ -96,11 +100,17 @@ private MddNode unionChildren( @Override public MddNode compute( - final MddNode mddNode, final AbstractNextStateDescriptor nextState, final MddVariable mddVariable - ) { + final MddNode mddNode, + final AbstractNextStateDescriptor nextState, + final MddVariable mddVariable) { try (var nextStateCursor = nextState.rootCursor()) { Preconditions.checkState(nextStateCursor.moveNext()); - return saturate(mddNode, nextState, nextStateCursor, mddVariable, cacheManager.getCacheFor(mddVariable)); + return saturate( + mddNode, + nextState, + nextStateCursor, + mddVariable, + cacheManager.getCacheFor(mddVariable)); } } @@ -109,11 +119,10 @@ private MddNode saturate( AbstractNextStateDescriptor d, AbstractNextStateDescriptor.Cursor dCursor, MddVariable variable, - CacheManager.CacheHolder cache - ) { - if (n.isTerminal() || - d == AbstractNextStateDescriptor.terminalIdentity() || - d == AbstractNextStateDescriptor.terminalEmpty()) { + CacheManager.CacheHolder cache) { + if (n.isTerminal() + || d == AbstractNextStateDescriptor.terminalIdentity() + || d == AbstractNextStateDescriptor.terminalEmpty()) { // TODO this does not handle level skips return n; } @@ -126,70 +135,75 @@ private MddNode saturate( if (verbose) { printIndent(); System.out.println("Saturating on level " + variable.getTraceInfo() + " with " + d); - } // indent++; final MddStateSpaceInfo stateSpaceInfo = new MddStateSpaceInfo(variable, n); -// IntObjMapView satTemplate = new IntObjMapViews.Transforming(n, -// (node, key) -> node == null ? null : terminalZeroToNull(saturate(node, -// d.getDiagonal(stateSpaceInfo).get(key), -// variable.getLower().orElse(null), -// cache.getLower() -// )) -// ); -// -// MddNode nsat = variable.checkInNode(MddStructuralTemplate.of(satTemplate)); + // IntObjMapView satTemplate = new IntObjMapViews.Transforming(n, + // (node, key) -> node == null ? null : terminalZeroToNull(saturate(node, + // d.getDiagonal(stateSpaceInfo).get(key), + // variable.getLower().orElse(null), + // cache.getLower() + // )) + // ); + // + // MddNode nsat = variable.checkInNode(MddStructuralTemplate.of(satTemplate)); - MddUnsafeTemplateBuilder templateBuilder = JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); + MddUnsafeTemplateBuilder templateBuilder = + JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); for (IntObjCursor cFrom = n.cursor(); cFrom.moveNext(); ) { try (var cTo = dCursor.valueCursor(cFrom.key(), stateSpaceInfo)) { - MddNode s = saturate(cFrom.value(), - cTo.moveTo(cFrom.key()) ? cTo.value() : AbstractNextStateDescriptor.terminalEmpty(), - cTo, - variable.getLower().orElse(null), - cache.getLower() - ); - - templateBuilder.set(cFrom.key(), - terminalZeroToNull(unionChildren(templateBuilder.get(cFrom.key()), s, variable)) - ); - + MddNode s = + saturate( + cFrom.value(), + cTo.moveTo(cFrom.key()) + ? cTo.value() + : AbstractNextStateDescriptor.terminalEmpty(), + cTo, + variable.getLower().orElse(null), + cache.getLower()); + + templateBuilder.set( + cFrom.key(), + terminalZeroToNull( + unionChildren(templateBuilder.get(cFrom.key()), s, variable))); } } - MddNode nsat = variable.checkInNode(MddStructuralTemplate.of(templateBuilder.buildAndReset())); + MddNode nsat = + variable.checkInNode(MddStructuralTemplate.of(templateBuilder.buildAndReset())); boolean changed; do { changed = false; -// final Optional> splitNS = d.split(); - final Optional> splitNSCursor = dCursor.split(); + // final Optional> splitNS = d.split(); + final Optional> splitNSCursor = + dCursor.split(); if (splitNSCursor.isPresent()) { for (AbstractNextStateDescriptor.Cursor dfireCursor : splitNSCursor.get()) { - //System.out.println("Applying transition: " + dfire); + // System.out.println("Applying transition: " + dfire); if (dfireCursor.value().isLocallyIdentity(stateSpaceInfo)) { continue; } - MddNode nfire = satFire(nsat, d, dfireCursor.value(), dfireCursor, variable, cache); + MddNode nfire = + satFire(nsat, d, dfireCursor.value(), dfireCursor, variable, cache); nfire = variable.union(nsat, nfire); if (nfire != nsat) { nsat = nfire; changed = true; } - - } } else if (!d.isLocallyIdentity(stateSpaceInfo)) { - //System.out.println("Applying transition: " + d); -// try(var dCursor = d.rootCursor()){ -// Preconditions.checkState(dCursor.moveNext()); + // System.out.println("Applying transition: " + d); + // try(var dCursor = d.rootCursor()){ + // Preconditions.checkState(dCursor.moveNext()); MddNode nfire = satFire(nsat, d, d, dCursor, variable, cache); nfire = variable.union(nsat, nfire); @@ -197,7 +211,7 @@ private MddNode saturate( nsat = nfire; changed = true; } -// } + // } } } while (changed); @@ -207,12 +221,17 @@ private MddNode saturate( if (verbose) { indent--; printIndent(); - System.out.println("Done Saturating on level " + variable.getTraceInfo() + " resulting in " + nsat); + System.out.println( + "Done Saturating on level " + + variable.getTraceInfo() + + " resulting in " + + nsat); } // indent--; // printIndent(); - // System.out.println("Saturated level " + variable.getTraceInfo() + ", domain size is " + variable.getDomainSize()); + // System.out.println("Saturated level " + variable.getTraceInfo() + ", domain size is " + + // variable.getDomainSize()); // return nsat; } @@ -223,8 +242,7 @@ private MddNode satFire( AbstractNextStateDescriptor dfire, AbstractNextStateDescriptor.Cursor dfireCursor, MddVariable variable, - CacheManager.CacheHolder cache - ) { + CacheManager.CacheHolder cache) { if (n == terminalZeroNode || dfire == AbstractNextStateDescriptor.terminalEmpty()) { return terminalZeroNode; } @@ -235,21 +253,23 @@ private MddNode satFire( if (verbose) { printIndent(); - System.out.println("SatFire on level " + - variable.getTraceInfo() + - " with dsat=" + - dsat + - "; dfire=" + - dfire); + System.out.println( + "SatFire on level " + + variable.getTraceInfo() + + " with dsat=" + + dsat + + "; dfire=" + + dfire); indent++; } - MddUnsafeTemplateBuilder templateBuilder = JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); + MddUnsafeTemplateBuilder templateBuilder = + JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); final var stateSpaceInfo = new MddStateSpaceInfo(variable, n); - final IntObjMapView> offDiagonal = dfire.getOffDiagonal( - stateSpaceInfo); + final IntObjMapView> offDiagonal = + dfire.getOffDiagonal(stateSpaceInfo); for (IntObjCursor cFrom = n.cursor(); cFrom.moveNext(); ) { try (var cTo = dfireCursor.valueCursor(cFrom.key(), stateSpaceInfo)) { @@ -265,31 +285,36 @@ private MddNode satFire( assert cFrom.value() != terminalZeroNode; assert cTo.value() != AbstractNextStateDescriptor.terminalEmpty(); - MddNode s = relProd(cFrom.value(), - dsat.getDiagonal(stateSpaceInfo).get(cTo.key()), - cTo.value(), - cTo, - variable.getLower().orElse(null), - cache.getLower() - ); + MddNode s = + relProd( + cFrom.value(), + dsat.getDiagonal(stateSpaceInfo).get(cTo.key()), + cTo.value(), + cTo, + variable.getLower().orElse(null), + cache.getLower()); if (s != terminalZeroNode) { confirm(variable, cTo.key()); - templateBuilder.set(cTo.key(), - terminalZeroToNull(unionChildren(templateBuilder.get(cTo.key()), s, variable)) - ); + templateBuilder.set( + cTo.key(), + terminalZeroToNull( + unionChildren( + templateBuilder.get(cTo.key()), s, variable))); } } } } - MddNode ret = variable.checkInNode(MddStructuralTemplate.of(templateBuilder.buildAndReset())); + MddNode ret = + variable.checkInNode(MddStructuralTemplate.of(templateBuilder.buildAndReset())); if (verbose) { indent--; printIndent(); - System.out.println("Done SatFire on level " + variable.getTraceInfo() + " resulting in " + ret); + System.out.println( + "Done SatFire on level " + variable.getTraceInfo() + " resulting in " + ret); } return ret; @@ -301,8 +326,7 @@ private MddNode relProd( AbstractNextStateDescriptor dfire, AbstractNextStateDescriptor.Cursor dfireCursor, MddVariable variable, - CacheManager.CacheHolder cache - ) { + CacheManager.CacheHolder cache) { if (n == terminalZeroNode || dfire == AbstractNextStateDescriptor.terminalEmpty()) { return terminalZeroNode; } @@ -324,48 +348,51 @@ private MddNode relProd( if (verbose) { printIndent(); - System.out.println("SatRelProd on level " + - variable.getTraceInfo() + - ", node=" + - n + - ", with dsat=" + - dsat + - "; dfire" + - "=" + - dfire); + System.out.println( + "SatRelProd on level " + + variable.getTraceInfo() + + ", node=" + + n + + ", with dsat=" + + dsat + + "; dfire" + + "=" + + dfire); indent++; } - MddUnsafeTemplateBuilder templateBuilder = JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); + MddUnsafeTemplateBuilder templateBuilder = + JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); - final IntObjMapView diagonal = dfire.getDiagonal(stateSpaceInfo); - final IntObjMapView> offDiagonal = dfire.getOffDiagonal( - stateSpaceInfo); + final IntObjMapView diagonal = + dfire.getDiagonal(stateSpaceInfo); + final IntObjMapView> offDiagonal = + dfire.getOffDiagonal(stateSpaceInfo); for (IntObjCursor cFrom = n.cursor(); cFrom.moveNext(); ) { // Identity step -// final AbstractNextStateDescriptor diagonalContinuation = diagonal.get(cFrom.key()); -// if (!AbstractNextStateDescriptor.isNullOrEmpty(diagonalContinuation)) { -// -// if (verbose) { -// System.out.println("Potential step: " + cFrom.key() + "->" + cFrom.key()); -// } -// -// MddNode s = relProd(cFrom.value(), -// dsat.getDiagonal(stateSpaceInfo).get(cFrom.key()), -// diagonalContinuation, -// variable.getLower().orElse(null), -// cache.getLower() -// ); -// -// if (s != terminalZeroNode) { -// // confirm(variable, cFrom.key()); -// -// templateBuilder.set(cFrom.key(), -// terminalZeroToNull(unionChildren(templateBuilder.get(cFrom.key()), s, variable)) -// ); -// } -// } + // final AbstractNextStateDescriptor diagonalContinuation = diagonal.get(cFrom.key()); + // if (!AbstractNextStateDescriptor.isNullOrEmpty(diagonalContinuation)) { + // + // if (verbose) { + // System.out.println("Potential step: " + cFrom.key() + "->" + cFrom.key()); + // } + // + // MddNode s = relProd(cFrom.value(), + // dsat.getDiagonal(stateSpaceInfo).get(cFrom.key()), + // diagonalContinuation, + // variable.getLower().orElse(null), + // cache.getLower() + // ); + // + // if (s != terminalZeroNode) { + // // confirm(variable, cFrom.key()); + // + // templateBuilder.set(cFrom.key(), + // terminalZeroToNull(unionChildren(templateBuilder.get(cFrom.key()), s, variable)) + // ); + // } + // } try (var cTo = dfireCursor.valueCursor(cFrom.key(), stateSpaceInfo)) { if (cTo.moveTo(cFrom.key())) { @@ -373,20 +400,23 @@ private MddNode relProd( System.out.println("Potential step: " + cFrom.key() + "->" + cFrom.key()); } - MddNode s = relProd(cFrom.value(), - dsat.getDiagonal(stateSpaceInfo).get(cFrom.key()), - cTo.value(), - cTo, - variable.getLower().orElse(null), - cache.getLower() - ); + MddNode s = + relProd( + cFrom.value(), + dsat.getDiagonal(stateSpaceInfo).get(cFrom.key()), + cTo.value(), + cTo, + variable.getLower().orElse(null), + cache.getLower()); if (s != terminalZeroNode) { // confirm(variable, cFrom.key()); - templateBuilder.set(cFrom.key(), - terminalZeroToNull(unionChildren(templateBuilder.get(cFrom.key()), s, variable)) - ); + templateBuilder.set( + cFrom.key(), + terminalZeroToNull( + unionChildren( + templateBuilder.get(cFrom.key()), s, variable))); } } } @@ -404,24 +434,26 @@ private MddNode relProd( assert cFrom.value() != terminalZeroNode; assert cTo.value() != AbstractNextStateDescriptor.terminalEmpty(); - MddNode s = relProd(cFrom.value(), - dsat.getDiagonal(stateSpaceInfo).get(cTo.key()), - cTo.value(), - cTo, - variable.getLower().orElse(null), - cache.getLower() - ); + MddNode s = + relProd( + cFrom.value(), + dsat.getDiagonal(stateSpaceInfo).get(cTo.key()), + cTo.value(), + cTo, + variable.getLower().orElse(null), + cache.getLower()); if (s != terminalZeroNode) { confirm(variable, cTo.key()); - templateBuilder.set(cTo.key(), - terminalZeroToNull(unionChildren(templateBuilder.get(cTo.key()), s, variable)) - ); + templateBuilder.set( + cTo.key(), + terminalZeroToNull( + unionChildren( + templateBuilder.get(cTo.key()), s, variable))); } } } - } ret = variable.checkInNode(MddStructuralTemplate.of(templateBuilder.buildAndReset())); @@ -436,20 +468,20 @@ private MddNode relProd( if (verbose) { indent--; printIndent(); - System.out.println("Done SatRelProd on level " + variable.getTraceInfo() + " resulting in " + ret); + System.out.println( + "Done SatRelProd on level " + variable.getTraceInfo() + " resulting in " + ret); } return ret; } - private void confirm(final MddVariable variable, final int key) { - - } + private void confirm(final MddVariable variable, final int key) {} @Override public MddNode computeTerminal( - final MddNode mddNode, final AbstractNextStateDescriptor nextState, final MddGraph mddGraph - ) { + final MddNode mddNode, + final AbstractNextStateDescriptor nextState, + final MddGraph mddGraph) { return mddNode; } @@ -477,12 +509,19 @@ public void clear() { @Override public void cleanup() { - this.cacheManager.forEachCache((cache) -> { - cache.getSaturateCache().clearSelectively((source, ns1, result) -> source.getReferenceCount() == 0 || - result.getReferenceCount() == 0); - cache.getRelProdCache().clearSelectively((source, ns1, ns2, result) -> source.getReferenceCount() == 0 || - result.getReferenceCount() == 0); - }); + this.cacheManager.forEachCache( + (cache) -> { + cache.getSaturateCache() + .clearSelectively( + (source, ns1, result) -> + source.getReferenceCount() == 0 + || result.getReferenceCount() == 0); + cache.getRelProdCache() + .clearSelectively( + (source, ns1, ns2, result) -> + source.getReferenceCount() == 0 + || result.getReferenceCount() == 0); + }); } private class Aggregator implements Consumer { @@ -540,10 +579,14 @@ public long getHitCount() { // TODO: HAXXXX DON'T DO THIS EVER AGAIN public Set getSaturatedNodes() { final Set ret = HashObjSets.newUpdatableSet(); - cacheManager.forEachCache((c) -> c.getSaturateCache().clearSelectively((source, ns, result) -> { - ret.add(result); - return false; - })); + cacheManager.forEachCache( + (c) -> + c.getSaturateCache() + .clearSelectively( + (source, ns, result) -> { + ret.add(result); + return false; + })); return ret; } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorRelationalProductProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorRelationalProductProvider.java index ce44869028..24de71022b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorRelationalProductProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/CursorRelationalProductProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,12 +21,12 @@ import hu.bme.mit.delta.java.mdd.*; import hu.bme.mit.delta.java.mdd.impl.MddStructuralTemplate; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; - import java.util.function.Consumer; import java.util.function.ToLongFunction; public final class CursorRelationalProductProvider implements RelationalProductProvider { - private final CacheManager> cacheManager = new CacheManager<>(v -> new BinaryOperationCache<>()); + private final CacheManager> + cacheManager = new CacheManager<>(v -> new BinaryOperationCache<>()); private final MddVariableOrder variableOrder; public CursorRelationalProductProvider(final MddVariableOrder variableOrder) { @@ -34,15 +34,28 @@ public CursorRelationalProductProvider(final MddVariableOrder variableOrder) { this.variableOrder.getMddGraph().registerCleanupListener(this); } - private MddNode recurse(final MddNode mddNode, final AbstractNextStateDescriptor nextState, final AbstractNextStateDescriptor.Cursor nextStateCursor, MddVariable currentVariable, final CacheManager>.CacheHolder currentCache) { + private MddNode recurse( + final MddNode mddNode, + final AbstractNextStateDescriptor nextState, + final AbstractNextStateDescriptor.Cursor nextStateCursor, + MddVariable currentVariable, + final CacheManager> + .CacheHolder + currentCache) { if (currentVariable.getLower().isPresent()) { - return doCompute(mddNode, nextState, nextStateCursor, currentVariable.getLower().get(), currentCache.getLower()); + return doCompute( + mddNode, + nextState, + nextStateCursor, + currentVariable.getLower().get(), + currentCache.getLower()); } else { return computeTerminal(mddNode, nextState, currentVariable.getMddGraph()); } } - private MddNode unionChildren(final MddNode lhs, final MddNode rhs, MddVariable currentVariable) { + private MddNode unionChildren( + final MddNode lhs, final MddNode rhs, MddVariable currentVariable) { if (currentVariable.getLower().isPresent()) { return currentVariable.getLower().get().union(lhs, rhs); } else { @@ -51,13 +64,31 @@ private MddNode unionChildren(final MddNode lhs, final MddNode rhs, MddVariable } @Override - public MddNode compute(final MddNode mddNode, final AbstractNextStateDescriptor abstractNextStateDescriptor, final MddVariable mddVariable) { - return doCompute(mddNode, abstractNextStateDescriptor, abstractNextStateDescriptor.rootCursor(), mddVariable, cacheManager.getCacheFor(mddVariable)); + public MddNode compute( + final MddNode mddNode, + final AbstractNextStateDescriptor abstractNextStateDescriptor, + final MddVariable mddVariable) { + return doCompute( + mddNode, + abstractNextStateDescriptor, + abstractNextStateDescriptor.rootCursor(), + mddVariable, + cacheManager.getCacheFor(mddVariable)); } - private MddNode doCompute(final MddNode lhs, final AbstractNextStateDescriptor nextState, final AbstractNextStateDescriptor.Cursor nextStateCursor, final MddVariable variable, final CacheManager>.CacheHolder cache) { - assert cache != null : "Invalid behavior for CacheManager: should have assigned a cache to every variable."; - if (variable.isNullOrZero(lhs) || nextState == AbstractNextStateDescriptor.terminalIdentity()) { + private MddNode doCompute( + final MddNode lhs, + final AbstractNextStateDescriptor nextState, + final AbstractNextStateDescriptor.Cursor nextStateCursor, + final MddVariable variable, + final CacheManager> + .CacheHolder + cache) { + assert cache != null + : "Invalid behavior for CacheManager: should have assigned a cache to every" + + " variable."; + if (variable.isNullOrZero(lhs) + || nextState == AbstractNextStateDescriptor.terminalIdentity()) { return lhs; } if (nextState == null || nextState == AbstractNextStateDescriptor.terminalEmpty()) { @@ -66,8 +97,11 @@ private MddNode doCompute(final MddNode lhs, final AbstractNextStateDescriptor n boolean lhsSkipped = !lhs.isOn(variable); - if ((lhsSkipped || !variable.isNullOrZero(lhs.defaultValue())) && !(lhs.isTerminal() && nextState instanceof AbstractNextStateDescriptor.Postcondition)) { - throw new UnsupportedOperationException("Default values are not yet supported in relational product."); + if ((lhsSkipped || !variable.isNullOrZero(lhs.defaultValue())) + && !(lhs.isTerminal() + && nextState instanceof AbstractNextStateDescriptor.Postcondition)) { + throw new UnsupportedOperationException( + "Default values are not yet supported in relational product."); } MddNode ret = cache.getCache().getOrNull(lhs, nextState); @@ -77,17 +111,34 @@ private MddNode doCompute(final MddNode lhs, final AbstractNextStateDescriptor n final MddStateSpaceInfo stateSpaceInfo = new MddStateSpaceInfo(variable, lhs); - final IntObjMapView diagonal = nextState.getDiagonal(stateSpaceInfo); - final IntObjMapView> offDiagonal = nextState.getOffDiagonal(stateSpaceInfo); + final IntObjMapView diagonal = + nextState.getDiagonal(stateSpaceInfo); + final IntObjMapView> offDiagonal = + nextState.getOffDiagonal(stateSpaceInfo); IntObjMapView template; // Patch to enable initializers if (lhs.isTerminal() && nextState instanceof AbstractNextStateDescriptor.Postcondition) { - template = new IntObjMapViews.Transforming(nextState.getDiagonal(stateSpaceInfo), ns -> ns == null ? null : terminalZeroToNull(recurse(lhs, ns, nextStateCursor, variable, cache), variable.getMddGraph().getTerminalZeroNode())); - // } else if (diagonal.isEmpty() && offDiagonal.isEmpty() && AbstractNextStateDescriptor.isNullOrEmpty( + template = + new IntObjMapViews.Transforming( + nextState.getDiagonal(stateSpaceInfo), + ns -> + ns == null + ? null + : terminalZeroToNull( + recurse( + lhs, + ns, + nextStateCursor, + variable, + cache), + variable.getMddGraph().getTerminalZeroNode())); + // } else if (diagonal.isEmpty() && offDiagonal.isEmpty() && + // AbstractNextStateDescriptor.isNullOrEmpty( // offDiagonal.defaultValue())) { - // // Either the ANSD does not affect this level or it is not fireable - will be evaluated in the next call + // // Either the ANSD does not affect this level or it is not fireable - will be + // evaluated in the next call // // TODO: THIS IS GONNA BE TERRIBLY SLOW // template = new IntObjMapViews.Transforming(lhs, // (child) -> child == null ? null : terminalZeroToNull( @@ -95,37 +146,54 @@ private MddNode doCompute(final MddNode lhs, final AbstractNextStateDescriptor n // variable.getMddGraph().getTerminalZeroNode() // )); } else { - MddUnsafeTemplateBuilder templateBuilder = JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); + MddUnsafeTemplateBuilder templateBuilder = + JavaMddFactory.getDefault().createUnsafeTemplateBuilder(); for (IntObjCursor c = lhs.cursor(); c.moveNext(); ) { // TODO we might not need this -// try(var valueCursor = nextStateCursor.valueCursor(c.key())) { -// valueCursor.moveTo(c.key()); -// final MddNode res = recurse(c.value(), diagonal.get(c.key()), valueCursor, variable, cache); -// final MddNode unioned = unionChildren(res, templateBuilder.get(c.key()), variable); -// -// templateBuilder.set(c.key(), terminalZeroToNull(unioned, variable.getMddGraph().getTerminalZeroNode())); -// } + // try(var valueCursor = nextStateCursor.valueCursor(c.key())) { + // valueCursor.moveTo(c.key()); + // final MddNode res = recurse(c.value(), diagonal.get(c.key()), + // valueCursor, variable, cache); + // final MddNode unioned = unionChildren(res, + // templateBuilder.get(c.key()), variable); + // + // templateBuilder.set(c.key(), terminalZeroToNull(unioned, + // variable.getMddGraph().getTerminalZeroNode())); + // } try (var valueCursor = nextStateCursor.valueCursor(c.key(), stateSpaceInfo)) { -// for (IntObjCursor next = offDiagonal.get(c.key()).cursor(); next.moveNext(); ) { + // for (IntObjCursor + // next = offDiagonal.get(c.key()).cursor(); next.moveNext(); ) { for (; valueCursor.moveNext(); ) { - final MddNode res1 = recurse(c.value(), valueCursor.value(), valueCursor, variable, cache); - final MddNode unioned1 = unionChildren(res1, templateBuilder.get(valueCursor.key()), variable); - - templateBuilder.set(valueCursor.key(), terminalZeroToNull(unioned1, variable.getMddGraph().getTerminalZeroNode())); + final MddNode res1 = + recurse( + c.value(), + valueCursor.value(), + valueCursor, + variable, + cache); + final MddNode unioned1 = + unionChildren( + res1, templateBuilder.get(valueCursor.key()), variable); + + templateBuilder.set( + valueCursor.key(), + terminalZeroToNull( + unioned1, variable.getMddGraph().getTerminalZeroNode())); } } - -// for (IntObjCursor next = offDiagonal.get(c.key()).cursor(); -// next.moveNext(); ) { -// final MddNode res1 = recurse(c.value(), next.value(), variable, cache); -// final MddNode unioned1 = unionChildren(res1, templateBuilder.get(next.key()), variable); -// -// templateBuilder.set(next.key(), -// terminalZeroToNull(unioned1, variable.getMddGraph().getTerminalZeroNode()) -// ); -// } + // for (IntObjCursor next = + // offDiagonal.get(c.key()).cursor(); + // next.moveNext(); ) { + // final MddNode res1 = recurse(c.value(), next.value(), variable, cache); + // final MddNode unioned1 = unionChildren(res1, templateBuilder.get(next.key()), + // variable); + // + // templateBuilder.set(next.key(), + // terminalZeroToNull(unioned1, variable.getMddGraph().getTerminalZeroNode()) + // ); + // } } template = templateBuilder.buildAndReset(); } @@ -138,7 +206,10 @@ private MddNode doCompute(final MddNode lhs, final AbstractNextStateDescriptor n } @Override - public MddNode computeTerminal(final MddNode mddNode, final AbstractNextStateDescriptor abstractNextStateDescriptor, final MddGraph mddGraph) { + public MddNode computeTerminal( + final MddNode mddNode, + final AbstractNextStateDescriptor abstractNextStateDescriptor, + final MddGraph mddGraph) { if (mddNode == mddGraph.getTerminalZeroNode() || !abstractNextStateDescriptor.evaluate()) { return mddGraph.getTerminalZeroNode(); } @@ -161,28 +232,47 @@ public void clear() { @Override public void cleanup() { - this.cacheManager.forEachCache((cache) -> cache.clearSelectively((source, ns, result) -> source.getReferenceCount() == 0 || result.getReferenceCount() == 0)); + this.cacheManager.forEachCache( + (cache) -> + cache.clearSelectively( + (source, ns, result) -> + source.getReferenceCount() == 0 + || result.getReferenceCount() == 0)); } - private class Aggregator implements Consumer> { + private class Aggregator + implements Consumer< + BinaryOperationCache> { public long result = 0; - private final ToLongFunction> extractor; - - private Aggregator(final ToLongFunction> extractor) { + private final ToLongFunction< + BinaryOperationCache> + extractor; + + private Aggregator( + final ToLongFunction< + BinaryOperationCache> + extractor) { this.extractor = extractor; } @Override - public void accept(final BinaryOperationCache cache) { + public void accept( + final BinaryOperationCache cache) { result += extractor.applyAsLong(cache); } } public Cache getRelProdCache() { class RelProdCache implements Cache { - private final CacheManager> cacheManager; - - RelProdCache(final CacheManager> cacheManager) { + private final CacheManager< + BinaryOperationCache> + cacheManager; + + RelProdCache( + final CacheManager< + BinaryOperationCache< + MddNode, AbstractNextStateDescriptor, MddNode>> + cacheManager) { this.cacheManager = cacheManager; } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/GeneralizedSaturationProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/GeneralizedSaturationProvider.java index b9e65d7c44..c5c8855634 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/GeneralizedSaturationProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/GeneralizedSaturationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/LegacyRelationalProductProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/LegacyRelationalProductProvider.java index c849b410f5..3b063f39c2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/LegacyRelationalProductProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/LegacyRelationalProductProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/MddStateSpaceInfo.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/MddStateSpaceInfo.java index a3dce0b2c1..6929cb4bca 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/MddStateSpaceInfo.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/MddStateSpaceInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/RelationalProductProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/RelationalProductProvider.java index ff92e29b71..5a01c2ced1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/RelationalProductProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/RelationalProductProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,8 @@ import hu.bme.mit.delta.java.mdd.MddTransformationProvider; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; -public interface RelationalProductProvider extends MddTransformationProvider { +public interface RelationalProductProvider + extends MddTransformationProvider { Cache getRelProdCache(); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SaturationCache.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SaturationCache.java index b36f6a68a6..7d4750e9a9 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SaturationCache.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SaturationCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,14 +22,19 @@ import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; public final class SaturationCache implements Cache { - private final BinaryOperationCache saturateCache = new BinaryOperationCache<>(); - private final TernaryOperationCache relProdCache = new TernaryOperationCache<>(); + private final BinaryOperationCache + saturateCache = new BinaryOperationCache<>(); + private final TernaryOperationCache< + MddNode, AbstractNextStateDescriptor, AbstractNextStateDescriptor, MddNode> + relProdCache = new TernaryOperationCache<>(); public BinaryOperationCache getSaturateCache() { return saturateCache; } - public TernaryOperationCache getRelProdCache() { + public TernaryOperationCache< + MddNode, AbstractNextStateDescriptor, AbstractNextStateDescriptor, MddNode> + getRelProdCache() { return relProdCache; } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SimpleSaturationProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SimpleSaturationProvider.java index 582972ca21..254139858f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SimpleSaturationProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/SimpleSaturationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/StateSpaceEnumerationProvider.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/StateSpaceEnumerationProvider.java index 73f4ec0578..47417e5949 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/StateSpaceEnumerationProvider.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/fixedpoint/StateSpaceEnumerationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.algorithm.mdd.fixedpoint; import hu.bme.mit.delta.java.mdd.MddTransformationProvider; import hu.bme.mit.theta.analysis.algorithm.mdd.ansd.AbstractNextStateDescriptor; -public interface StateSpaceEnumerationProvider extends MddTransformationProvider.Cached, MddTransformationProvider.Initializable { -} +public interface StateSpaceEnumerationProvider + extends MddTransformationProvider.Cached, + MddTransformationProvider.Initializable< + AbstractNextStateDescriptor, AbstractNextStateDescriptor.Postcondition> {} diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/varordering/ForceVarOrdering.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/varordering/ForceVarOrdering.kt index 97063feec4..3fc4be887a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/varordering/ForceVarOrdering.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/mdd/varordering/ForceVarOrdering.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/BasicOcChecker.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/BasicOcChecker.kt index 706db97b38..0ce5dd47ef 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/BasicOcChecker.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/BasicOcChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcChecker.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcChecker.kt index d5df1f83b9..3b13a2c976 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcChecker.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcTypes.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcTypes.kt index eb3d4870be..25a629aa55 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcTypes.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/OcTypes.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/UserPropagatorOcChecker.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/UserPropagatorOcChecker.kt index 5df28111e5..8aa309ac79 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/UserPropagatorOcChecker.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/algorithm/oc/UserPropagatorOcChecker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplAnalysis.java index 363096ba7f..a9a6964186 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,8 +18,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.core.type.Expr; @@ -38,7 +38,6 @@ private ExplAnalysis(final Solver solver, final Expr initExpr) { this.partialOrd = ExplOrd.getInstance(); this.initFunc = ExplInitFunc.create(solver, initExpr); this.transFunc = ExplTransFunc.create(solver); - } public static ExplAnalysis create(final Solver solver, final Expr initExpr) { @@ -59,5 +58,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplInitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplInitFunc.java index 049832fbe9..6d5c979246 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplInitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.analysis.expl; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.expr.ExprStates; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.Solver; - import java.util.Collection; import java.util.Collections; -import static com.google.common.base.Preconditions.checkNotNull; - public final class ExplInitFunc implements InitFunc { private final Solver solver; @@ -44,10 +43,9 @@ public static ExplInitFunc create(final Solver solver, final Expr init @Override public Collection getInitStates(final ExplPrec prec) { checkNotNull(prec); - final Collection initStates = ExprStates.createStatesForExpr(solver, initExpr, 0, - prec::createState, - VarIndexingFactory.indexing(0)); + final Collection initStates = + ExprStates.createStatesForExpr( + solver, initExpr, 0, prec::createState, VarIndexingFactory.indexing(0)); return initStates.isEmpty() ? Collections.singleton(ExplState.bottom()) : initStates; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplLattice.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplLattice.java index 66139b3875..8f7e24149b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplLattice.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplLattice.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,7 +20,6 @@ import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.type.LitExpr; - import java.util.Map; public final class ExplLattice implements Lattice { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplOrd.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplOrd.java index 352d4a8a05..00f373c3a1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplOrd.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,8 +24,7 @@ private static final class LazyHolder { private static final ExplOrd INSTANCE = new ExplOrd(); } - private ExplOrd() { - } + private ExplOrd() {} public static ExplOrd getInstance() { return LazyHolder.INSTANCE; @@ -35,5 +34,4 @@ public static ExplOrd getInstance() { public boolean isLeq(final ExplState state1, final ExplState state2) { return state1.isLeq(state2); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplPrec.java index ce552c0330..609001530c 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expl; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.common.Utils; @@ -22,21 +24,16 @@ import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.LitExpr; - import java.util.Collection; import java.util.Collections; import java.util.Optional; import java.util.Set; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Represents an immutable, simple explicit precision that is a set of variables. - */ +/** Represents an immutable, simple explicit precision that is a set of variables. */ public final class ExplPrec implements Prec { private final Set> vars; - private final static ExplPrec EMPTY = new ExplPrec(Collections.emptySet()); + private static final ExplPrec EMPTY = new ExplPrec(Collections.emptySet()); private ExplPrec(final Iterable> vars) { this.vars = ImmutableSet.copyOf(vars); @@ -61,9 +58,8 @@ public Set> getVars() { public ExplPrec join(final ExplPrec other) { checkNotNull(other); - final Collection> newVars = ImmutableSet.>builder().addAll(vars) - .addAll(other.vars) - .build(); + final Collection> newVars = + ImmutableSet.>builder().addAll(vars).addAll(other.vars).build(); // If no new variable was added, return same instance (immutable) if (newVars.size() == this.vars.size()) { return this; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplState.java index cfc2821bc0..0b25ee84a0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expl; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.Decl; @@ -25,19 +27,15 @@ import hu.bme.mit.theta.core.type.Type; import hu.bme.mit.theta.core.type.booltype.BoolExprs; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Map; import java.util.Optional; -import static com.google.common.base.Preconditions.checkNotNull; - public abstract class ExplState extends Valuation implements ExprState { - private ExplState() { - } + private ExplState() {} public static ExplState of(final Valuation val) { if (val.getDecls().isEmpty()) { @@ -128,9 +126,12 @@ public boolean isBottom() { @Override public String toString() { - return Utils.lispStringBuilder(ExplState.class.getSimpleName()).aligned() - .addAll(val.getDecls().stream().sorted(Comparator.comparing((Decl decl) -> decl.getName())) - .map(d -> String.format("(%s %s)", d.getName(), eval(d).get()))) + return Utils.lispStringBuilder(ExplState.class.getSimpleName()) + .aligned() + .addAll( + val.getDecls().stream() + .sorted(Comparator.comparing((Decl decl) -> decl.getName())) + .map(d -> String.format("(%s %s)", d.getName(), eval(d).get()))) .toString(); } } @@ -176,7 +177,8 @@ public boolean isBottom() { @Override public String toString() { - return Utils.lispStringBuilder(ExplState.class.getSimpleName()).add("Bottom") + return Utils.lispStringBuilder(ExplState.class.getSimpleName()) + .add("Bottom") .toString(); } } @@ -190,5 +192,4 @@ private static class TopLazyHolder { static final ExplState INSTANCE = new NonBottom(ImmutableValuation.empty()); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicate.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicate.java index 502f6b42f3..6660dc68a5 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicate.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStatePredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,8 +19,6 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import java.util.function.Predicate; - import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; @@ -28,6 +26,7 @@ import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.utils.WithPushPop; +import java.util.function.Predicate; public class ExplStatePredicate implements Predicate { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtAnalysis.java index c43443a696..c74f222a1b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -32,8 +32,8 @@ public final class ExplStmtAnalysis implements Analysis initFunc; private final TransFunc transFunc; - private ExplStmtAnalysis(final Solver solver, final Expr initExpr, - final int maxSuccToEnumerate) { + private ExplStmtAnalysis( + final Solver solver, final Expr initExpr, final int maxSuccToEnumerate) { checkNotNull(solver); checkNotNull(initExpr); this.partialOrd = ExplOrd.getInstance(); @@ -41,8 +41,8 @@ private ExplStmtAnalysis(final Solver solver, final Expr initExpr, this.transFunc = ExplStmtTransFunc.create(solver, maxSuccToEnumerate); } - public static ExplStmtAnalysis create(final Solver solver, final Expr initExpr, - final int maxSuccToEnumerate) { + public static ExplStmtAnalysis create( + final Solver solver, final Expr initExpr, final int maxSuccToEnumerate) { return new ExplStmtAnalysis(solver, initExpr, maxSuccToEnumerate); } @@ -64,5 +64,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtOptimizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtOptimizer.java index b790b12c05..2c65ed485a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtOptimizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,13 +16,12 @@ package hu.bme.mit.theta.analysis.expl; import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; -import hu.bme.mit.theta.core.utils.StmtSimplifier; import hu.bme.mit.theta.core.stmt.Stmt; +import hu.bme.mit.theta.core.utils.StmtSimplifier; public class ExplStmtOptimizer implements StmtOptimizer { - private ExplStmtOptimizer() { - } + private ExplStmtOptimizer() {} private static class LazyHolder { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFunc.java index b6da191fb5..b21466b55d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplStmtTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,11 @@ */ package hu.bme.mit.theta.analysis.expl; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static java.util.Collections.singleton; + import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expl.StmtApplier.ApplyResult; import hu.bme.mit.theta.analysis.expr.ExprStates; @@ -28,15 +33,9 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.Solver; - import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static java.util.Collections.singleton; - public final class ExplStmtTransFunc implements TransFunc { private final Solver solver; @@ -54,13 +53,13 @@ public static ExplStmtTransFunc create(final Solver solver, final int maxSuccToE } @Override - public Collection getSuccStates(final ExplState state, final StmtAction action, - final ExplPrec prec) { + public Collection getSuccStates( + final ExplState state, final StmtAction action, final ExplPrec prec) { return getSuccStates(state, action.getStmts(), prec); } - Collection getSuccStates(final ExplState state, final List stmts, - final ExplPrec prec) { + Collection getSuccStates( + final ExplState state, final List stmts, final ExplPrec prec) { final MutableValuation val = MutableValuation.copyOf(state); boolean triedSolver = false; @@ -75,16 +74,16 @@ Collection getSuccStates(final ExplState state, final List stmt } else if (applyResult == ApplyResult.FAILURE) { triedSolver = true; final List remainingStmts = stmts.subList(i, stmts.size()); - final StmtUnfoldResult toExprResult = StmtUtils.toExpr(remainingStmts, - VarIndexingFactory.indexing(0)); + final StmtUnfoldResult toExprResult = + StmtUtils.toExpr(remainingStmts, VarIndexingFactory.indexing(0)); final Expr expr = And(val.toExpr(), And(toExprResult.getExprs())); final VarIndexing nextIdx = toExprResult.getIndexing(); // We query (max + 1) states from the solver to see if there // would be more than max final int maxToQuery = maxSuccToEnumerate == 0 ? 0 : maxSuccToEnumerate + 1; - final Collection succStates = ExprStates.createStatesForExpr(solver, - expr, 0, - prec::createState, nextIdx, maxToQuery); + final Collection succStates = + ExprStates.createStatesForExpr( + solver, expr, 0, prec::createState, nextIdx, maxToQuery); if (succStates.isEmpty()) { return singleton(ExplState.bottom()); @@ -100,5 +99,4 @@ Collection getSuccStates(final ExplState state, final List stmt final ExplState abstracted = prec.createState(val); return singleton(abstracted); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplTransFunc.java index dac4f04bfa..14ceb8d57f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ExplTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.Collections; - import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.analysis.expr.ExprStates; import hu.bme.mit.theta.core.type.booltype.BoolExprs; import hu.bme.mit.theta.solver.Solver; +import java.util.Collection; +import java.util.Collections; public final class ExplTransFunc implements TransFunc { @@ -39,16 +38,18 @@ public static ExplTransFunc create(final Solver solver) { } @Override - public Collection getSuccStates(final ExplState state, - final ExprAction action, - final ExplPrec prec) { + public Collection getSuccStates( + final ExplState state, final ExprAction action, final ExplPrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); - final Collection succStates = ExprStates.createStatesForExpr(solver, - BoolExprs.And(state.toExpr(), action.toExpr()), 0, prec::createState, - action.nextIndexing()); + final Collection succStates = + ExprStates.createStatesForExpr( + solver, + BoolExprs.And(state.toExpr(), action.toExpr()), + 0, + prec::createState, + action.nextIndexing()); return succStates.isEmpty() ? Collections.singleton(ExplState.bottom()) : succStates; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ItpRefToExplPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ItpRefToExplPrec.java index eee132ceea..424310eb4a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ItpRefToExplPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/ItpRefToExplPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import hu.bme.mit.theta.analysis.expr.refinement.ItpRefutation; import hu.bme.mit.theta.analysis.expr.refinement.RefutationToPrec; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; +import java.util.Collection; public class ItpRefToExplPrec implements RefutationToPrec { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/StmtApplier.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/StmtApplier.java index 67945a67c5..2bb1351a5d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/StmtApplier.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/StmtApplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expl; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; @@ -39,24 +41,22 @@ import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.type.booltype.NotExpr; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; - public final class StmtApplier { public enum ApplyResult { - FAILURE, SUCCESS, BOTTOM + FAILURE, + SUCCESS, + BOTTOM } - private StmtApplier() { - } + private StmtApplier() {} - public static ApplyResult apply(final Stmt stmt, final MutableValuation val, - final boolean approximate) { + public static ApplyResult apply( + final Stmt stmt, final MutableValuation val, final boolean approximate) { if (stmt instanceof AssignStmt) { final AssignStmt assignStmt = (AssignStmt) stmt; return applyAssign(assignStmt, val, approximate); @@ -90,26 +90,29 @@ public static ApplyResult apply(final Stmt stmt, final MutableValuation val, } } - private static ApplyResult applyMemAssign(MemoryAssignStmt stmt, MutableValuation val, boolean approximate) { + private static ApplyResult applyMemAssign( + MemoryAssignStmt stmt, MutableValuation val, boolean approximate) { final var expr = ExprUtils.simplify(stmt.getDeref(), val); final var deref = stmt.getDeref(); final var newOffset = ExprUtils.simplify(deref.getOffset(), val); -// if (expr instanceof LitExpr litExpr && deref.getArray() instanceof RefExpr refExpr && newOffset instanceof LitExpr litOffset) { -// final VarDecl varDecl = (VarDecl) refExpr.getDecl(); -// final IntLitExpr intLitOffset = (IntLitExpr) litOffset; -// val.put(varDecl.getConstDecl(intLitOffset.getValue().intValue()), litExpr); -// return ApplyResult.SUCCESS; -// } else if (approximate && deref.getArray() instanceof RefExpr refExpr && newOffset instanceof LitExpr litOffset) { -// final VarDecl varDecl = (VarDecl) refExpr.getDecl(); -// final IntLitExpr intLitOffset = (IntLitExpr) litOffset; -// val.remove(varDecl.getConstDecl(intLitOffset.getValue().intValue())); -// return ApplyResult.SUCCESS; -// } + // if (expr instanceof LitExpr litExpr && deref.getArray() instanceof RefExpr + // refExpr && newOffset instanceof LitExpr litOffset) { + // final VarDecl varDecl = (VarDecl) refExpr.getDecl(); + // final IntLitExpr intLitOffset = (IntLitExpr) litOffset; + // val.put(varDecl.getConstDecl(intLitOffset.getValue().intValue()), litExpr); + // return ApplyResult.SUCCESS; + // } else if (approximate && deref.getArray() instanceof RefExpr refExpr && + // newOffset instanceof LitExpr litOffset) { + // final VarDecl varDecl = (VarDecl) refExpr.getDecl(); + // final IntLitExpr intLitOffset = (IntLitExpr) litOffset; + // val.remove(varDecl.getConstDecl(intLitOffset.getValue().intValue())); + // return ApplyResult.SUCCESS; + // } return ApplyResult.FAILURE; } - private static ApplyResult applyAssign(final AssignStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applyAssign( + final AssignStmt stmt, final MutableValuation val, final boolean approximate) { final VarDecl varDecl = stmt.getVarDecl(); final Expr expr = ExprUtils.simplify(stmt.getExpr(), val); if (expr instanceof LitExpr) { @@ -124,8 +127,8 @@ private static ApplyResult applyAssign(final AssignStmt stmt, final MutableVa } } - private static ApplyResult applyAssume(final AssumeStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applyAssume( + final AssumeStmt stmt, final MutableValuation val, final boolean approximate) { final Expr cond = ExprUtils.simplify(stmt.getCond(), val); if (cond instanceof BoolLitExpr) { final BoolLitExpr condLit = (BoolLitExpr) cond; @@ -146,8 +149,8 @@ private static ApplyResult applyAssume(final AssumeStmt stmt, final MutableValua } // Helper function to evaluate assumptions of form [x = 1] or [not x != 1] - private static boolean checkAssumeVarEqualsLit(final Expr cond, - final MutableValuation val) { + private static boolean checkAssumeVarEqualsLit( + final Expr cond, final MutableValuation val) { RefExpr ref = null; LitExpr lit = null; @@ -204,8 +207,8 @@ private static ApplyResult applySkip() { return ApplyResult.SUCCESS; } - private static ApplyResult applySequence(final SequenceStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applySequence( + final SequenceStmt stmt, final MutableValuation val, final boolean approximate) { MutableValuation copy = MutableValuation.copyOf(val); for (Stmt subStmt : stmt.getStmts()) { ApplyResult res = apply(subStmt, copy, approximate); @@ -218,14 +221,14 @@ private static ApplyResult applySequence(final SequenceStmt stmt, final MutableV return ApplyResult.SUCCESS; } - private static ApplyResult applyLoop(final LoopStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applyLoop( + final LoopStmt stmt, final MutableValuation val, final boolean approximate) { throw new UnsupportedOperationException( String.format("Loop statement %s was not unrolled", stmt)); } - private static ApplyResult applyNonDet(final NonDetStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applyNonDet( + final NonDetStmt stmt, final MutableValuation val, final boolean approximate) { List valuations = new ArrayList(); int successIndex = -1; for (int i = 0; i < stmt.getStmts().size(); i++) { @@ -265,8 +268,8 @@ private static ApplyResult applyNonDet(final NonDetStmt stmt, final MutableValua } } - private static ApplyResult applyIf(final IfStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applyIf( + final IfStmt stmt, final MutableValuation val, final boolean approximate) { final Expr cond = ExprUtils.simplify(stmt.getCond(), val); if (cond instanceof BoolLitExpr) { @@ -292,22 +295,23 @@ private static ApplyResult applyIf(final IfStmt stmt, final MutableValuation val } if (thenResult == ApplyResult.SUCCESS && elzeResult == ApplyResult.BOTTOM) { - SequenceStmt seq = SequenceStmt.of( - ImmutableList.of(AssumeStmt.of(cond), stmt.getThen())); + SequenceStmt seq = + SequenceStmt.of(ImmutableList.of(AssumeStmt.of(cond), stmt.getThen())); return apply(seq, val, approximate); } if (thenResult == ApplyResult.BOTTOM && elzeResult == ApplyResult.SUCCESS) { - SequenceStmt seq = SequenceStmt.of( - ImmutableList.of(AssumeStmt.of(Not(cond)), stmt.getElze())); + SequenceStmt seq = + SequenceStmt.of(ImmutableList.of(AssumeStmt.of(Not(cond)), stmt.getElze())); return apply(seq, val, approximate); } if (approximate) { apply(stmt.getThen(), val, approximate); - var toRemove = val.getDecls().stream() - .filter(it -> !val.eval(it).equals(elzeVal.eval(it))) - .collect(Collectors.toSet()); + var toRemove = + val.getDecls().stream() + .filter(it -> !val.eval(it).equals(elzeVal.eval(it))) + .collect(Collectors.toSet()); for (Decl decl : toRemove) { val.remove(decl); } @@ -318,9 +322,8 @@ private static ApplyResult applyIf(final IfStmt stmt, final MutableValuation val } } - private static ApplyResult applyOrt(final OrtStmt stmt, final MutableValuation val, - final boolean approximate) { + private static ApplyResult applyOrt( + final OrtStmt stmt, final MutableValuation val, final boolean approximate) { throw new UnsupportedOperationException(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/VarsRefToExplPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/VarsRefToExplPrec.java index ab4aa2bf50..ae5477644f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/VarsRefToExplPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expl/VarsRefToExplPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,11 +17,10 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import hu.bme.mit.theta.analysis.expr.refinement.RefutationToPrec; import hu.bme.mit.theta.analysis.expr.refinement.VarsRefutation; import hu.bme.mit.theta.core.decl.VarDecl; +import java.util.Collection; public class VarsRefToExplPrec implements RefutationToPrec { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprMeetStrategy.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprMeetStrategy.java index b946cbb3d4..049f42739c 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprMeetStrategy.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprMeetStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - public final class BasicExprMeetStrategy implements ExprLattice.MeetStrategy { private static final BasicExprMeetStrategy INSTANCE = new BasicExprMeetStrategy(); - private BasicExprMeetStrategy() { - } + private BasicExprMeetStrategy() {} public static BasicExprMeetStrategy getInstance() { return INSTANCE; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprState.java index 5b57dc0df3..7fc0617557 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/BasicExprState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprAction.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprAction.java index 677e8f344d..f56f7fe2dc 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprAction.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,5 +25,4 @@ public interface ExprAction extends Action { Expr toExpr(); VarIndexing nextIndexing(); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprLattice.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprLattice.java index 163a3d880e..9f74a8ed6e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprLattice.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprLattice.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,17 @@ */ package hu.bme.mit.theta.analysis.expr; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import hu.bme.mit.theta.analysis.Lattice; import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.solver.Solver; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public final class ExprLattice implements Lattice { @FunctionalInterface diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprMeetStrategy.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprMeetStrategy.java index 2784bd31c6..1b8505ee65 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprMeetStrategy.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprMeetStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.analysis.expr; public enum ExprMeetStrategy { - BASIC, SEMANTIC, SYNTACTIC + BASIC, + SEMANTIC, + SYNTACTIC } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprOrd.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprOrd.java index e1778d050a..18bc71e7d0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprOrd.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -46,5 +46,4 @@ public boolean isLeq(final ExprState state1, final ExprState state2) { return solver.check().isUnsat(); } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprState.java index 60568dae7e..da44c77e62 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStatePredicate.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStatePredicate.java index 116c89743f..0d125d4fce 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStatePredicate.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStatePredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,14 +17,13 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.function.Predicate; - import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.utils.WithPushPop; +import java.util.function.Predicate; public class ExprStatePredicate implements Predicate { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStateUtils.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStateUtils.java index d89d04ead2..70396ca0d0 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStateUtils.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStateUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,27 +15,27 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static hu.bme.mit.theta.core.utils.PathUtils.extractValuation; +import static hu.bme.mit.theta.core.utils.PathUtils.unfold; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.SolverStatus; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.Collection; import java.util.Optional; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static hu.bme.mit.theta.core.utils.PathUtils.extractValuation; -import static hu.bme.mit.theta.core.utils.PathUtils.unfold; - public final class ExprStateUtils { - private ExprStateUtils() { - } + private ExprStateUtils() {} - public static Optional anyUncoveredSuccessor(final ExprState state, - final ExprAction action, - final Collection succStates, final Solver solver) { + public static Optional anyUncoveredSuccessor( + final ExprState state, + final ExprAction action, + final Collection succStates, + final Solver solver) { try (WithPushPop wpp = new WithPushPop(solver)) { final VarIndexing indexing = action.nextIndexing(); solver.add(unfold(state.toExpr(), 0)); @@ -59,7 +59,9 @@ public static Optional anyUncoveredSuccessor(final ExprState state, public static Optional anyUncoveredPredecessor( final Collection predStates, - final ExprAction action, final ExprState state, final Solver solver) { + final ExprAction action, + final ExprState state, + final Solver solver) { try (WithPushPop wpp = new WithPushPop(solver)) { final VarIndexing indexing = action.nextIndexing(); for (final ExprState predState : predStates) { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStates.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStates.java index d891e76fdc..2c887b7b8d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStates.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprStates.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; + import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; @@ -22,54 +24,52 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.Collection; import java.util.function.Function; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; - -/** - * Utility for generating ExprStates. - */ +/** Utility for generating ExprStates. */ public final class ExprStates { - private ExprStates() { - } + private ExprStates() {} /** * Generate all states that satisfy a given expression. * - * @param solver Solver - * @param expr Expression to be satisfied - * @param exprIndex Index for unfolding the expression + * @param solver Solver + * @param expr Expression to be satisfied + * @param exprIndex Index for unfolding the expression * @param valuationToState Mapping from a valuation to a state - * @param stateIndexing Index for extracting the state + * @param stateIndexing Index for extracting the state * @return States satisfying the expression */ - public static Collection createStatesForExpr(final Solver solver, - final Expr expr, final int exprIndex, - final Function valuationToState, - final VarIndexing stateIndexing) { + public static Collection createStatesForExpr( + final Solver solver, + final Expr expr, + final int exprIndex, + final Function valuationToState, + final VarIndexing stateIndexing) { return createStatesForExpr(solver, expr, exprIndex, valuationToState, stateIndexing, 0); } /** * Generate all or a limited number of states that satisfy a given expression. * - * @param solver Solver - * @param expr Expression to be satisfied - * @param exprIndex Index for unfolding the expression + * @param solver Solver + * @param expr Expression to be satisfied + * @param exprIndex Index for unfolding the expression * @param valuationToState Mapping from a valuation to a state - * @param stateIndexing Index for extracting the state - * @param limit Limit the number of states to generate (0 is unlimited) + * @param stateIndexing Index for extracting the state + * @param limit Limit the number of states to generate (0 is unlimited) * @return States satisfying the expression */ - public static Collection createStatesForExpr(final Solver solver, - final Expr expr, final int exprIndex, - final Function valuationToState, - final VarIndexing stateIndexing, - final int limit) { + public static Collection createStatesForExpr( + final Solver solver, + final Expr expr, + final int exprIndex, + final Function valuationToState, + final VarIndexing stateIndexing, + final int limit) { try (WithPushPop wpp = new WithPushPop(solver)) { solver.add(PathUtils.unfold(expr, exprIndex)); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprTraceUtils.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprTraceUtils.java index 47d7327da2..0348f81aed 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprTraceUtils.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/ExprTraceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,18 +20,16 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; import static java.util.Collections.singleton; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.core.model.Valuation; import hu.bme.mit.theta.solver.Solver; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; public final class ExprTraceUtils { - private ExprTraceUtils() { - } + private ExprTraceUtils() {} public static Trace traceFrom( final List actions) { @@ -43,21 +41,19 @@ public static Trace traceFrom( return Trace.of(states, actions); } - public static boolean isInductive(final Trace trace, - final Solver solver) { + public static boolean isInductive( + final Trace trace, final Solver solver) { for (int i = 0; i < trace.length(); i++) { final ExprState sourceState = trace.getState(i); final ExprAction action = trace.getAction(i); final ExprState targetState = trace.getState(i + 1); - final Optional uncoveredSuccessor = anyUncoveredSuccessor(sourceState, - action, - singleton(targetState), solver); + final Optional uncoveredSuccessor = + anyUncoveredSuccessor(sourceState, action, singleton(targetState), solver); if (uncoveredSuccessor.isPresent()) { return false; } } return true; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInitFunc.java index 538f5b6540..4a256e95d4 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expr; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.unit.UnitPrec; import hu.bme.mit.theta.core.type.Expr; @@ -22,12 +24,9 @@ import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; - import java.util.Collection; import java.util.Collections; -import static com.google.common.base.Preconditions.checkNotNull; - public final class IndexedExprInitFunc implements InitFunc { private final Expr initExpr; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInvTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInvTransFunc.java index 8b863e294a..65ab0c4148 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInvTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprInvTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,33 +15,34 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.InvTransFunc; import hu.bme.mit.theta.analysis.unit.UnitPrec; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; - import java.util.Collection; import java.util.Collections; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - -public final class IndexedExprInvTransFunc implements InvTransFunc { +public final class IndexedExprInvTransFunc + implements InvTransFunc { - private final static IndexedExprInvTransFunc INSTANCE = new IndexedExprInvTransFunc(); + private static final IndexedExprInvTransFunc INSTANCE = new IndexedExprInvTransFunc(); - private IndexedExprInvTransFunc() { - } + private IndexedExprInvTransFunc() {} public static IndexedExprInvTransFunc getInstance() { return INSTANCE; } @Override - public Collection getPreStates(IndexedExprState state, ExprAction action, UnitPrec prec) { + public Collection getPreStates( + IndexedExprState state, ExprAction action, UnitPrec prec) { final VarIndexing currentIndexing = state.getVarIndexing(); - final Expr preExpr = And(state.toExpr(), PathUtils.unfoldReverse(action.toExpr(), currentIndexing)); + final Expr preExpr = + And(state.toExpr(), PathUtils.unfoldReverse(action.toExpr(), currentIndexing)); final VarIndexing newIndexing = currentIndexing.add(action.nextIndexing()); final IndexedExprState preState = IndexedExprState.of(preExpr, newIndexing); return Collections.singleton(preState); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprState.java index ff71f7cf7b..702c7c806d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,15 @@ */ package hu.bme.mit.theta.analysis.expr; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; + import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; - public final class IndexedExprState implements ExprState { private final Expr indexedExpr; @@ -34,7 +34,8 @@ protected IndexedExprState(final Expr indexedExpr, final VarIndexing v this.varIndexing = checkNotNull(varIndexing); } - public static IndexedExprState of(final Expr indexedExpr, final VarIndexing varIndexing) { + public static IndexedExprState of( + final Expr indexedExpr, final VarIndexing varIndexing) { return new IndexedExprState(indexedExpr, varIndexing); } @@ -58,7 +59,8 @@ public boolean isBottom() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).body() + return Utils.lispStringBuilder(getClass().getSimpleName()) + .body() .add(indexedExpr) .add(varIndexing.toString()) .toString(); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprTransFunc.java index f674e798d1..ec304a7808 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/IndexedExprTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,33 +15,34 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.unit.UnitPrec; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; - import java.util.Collection; import java.util.Collections; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - -public final class IndexedExprTransFunc implements TransFunc { +public final class IndexedExprTransFunc + implements TransFunc { - private final static IndexedExprTransFunc INSTANCE = new IndexedExprTransFunc(); + private static final IndexedExprTransFunc INSTANCE = new IndexedExprTransFunc(); - private IndexedExprTransFunc() { - } + private IndexedExprTransFunc() {} public static IndexedExprTransFunc getInstance() { return INSTANCE; } @Override - public Collection getSuccStates(IndexedExprState state, ExprAction action, UnitPrec prec) { + public Collection getSuccStates( + IndexedExprState state, ExprAction action, UnitPrec prec) { final VarIndexing currentIndexing = state.getVarIndexing(); - final Expr succExpr = And(state.toExpr(), PathUtils.unfold(action.toExpr(), currentIndexing)); + final Expr succExpr = + And(state.toExpr(), PathUtils.unfold(action.toExpr(), currentIndexing)); final VarIndexing newIndexing = currentIndexing.add(action.nextIndexing()); final IndexedExprState succState = IndexedExprState.of(succExpr, newIndexing); return Collections.singleton(succState); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SemanticExprMeetStrategy.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SemanticExprMeetStrategy.java index 58172852b7..fb6a175644 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SemanticExprMeetStrategy.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SemanticExprMeetStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,11 +15,11 @@ */ package hu.bme.mit.theta.analysis.expr; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.solver.Solver; -import static com.google.common.base.Preconditions.checkNotNull; - public final class SemanticExprMeetStrategy implements ExprLattice.MeetStrategy { private final PartialOrd partialOrd; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/StmtAction.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/StmtAction.java index f78157ced6..0be638f444 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/StmtAction.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/StmtAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.analysis.expr; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; +import static hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory.indexing; + import hu.bme.mit.theta.core.stmt.Stmt; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.StmtUnfoldResult; import hu.bme.mit.theta.core.utils.StmtUtils; import hu.bme.mit.theta.core.utils.indexings.VarIndexing; - import java.util.List; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; -import static hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory.indexing; - public abstract class StmtAction implements ExprAction { private volatile Expr expr = null; @@ -57,5 +56,4 @@ public final VarIndexing nextIndexing() { } return result; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SyntacticExprMeetStrategy.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SyntacticExprMeetStrategy.java index c5e458177c..62ad019ea7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SyntacticExprMeetStrategy.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/SyntacticExprMeetStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/AasporRefiner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/AasporRefiner.java index 69b184e8b6..722892e869 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/AasporRefiner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/AasporRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceBwBinItpChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceBwBinItpChecker.java index f4a360b5f3..6e47ea9c0b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceBwBinItpChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceBwBinItpChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expr.refinement; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.ExprAction; @@ -29,12 +31,9 @@ import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.ItpPattern; import hu.bme.mit.theta.solver.ItpSolver; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - /** * An ExprTraceChecker that generates a binary interpolant by incrementally checking the * counterexample backward. @@ -45,16 +44,15 @@ public final class ExprTraceBwBinItpChecker implements ExprTraceChecker init; private final Expr target; - private ExprTraceBwBinItpChecker(final Expr init, final Expr target, - final ItpSolver solver) { + private ExprTraceBwBinItpChecker( + final Expr init, final Expr target, final ItpSolver solver) { this.solver = checkNotNull(solver); this.init = checkNotNull(init); this.target = checkNotNull(target); } - public static ExprTraceBwBinItpChecker create(final Expr init, - final Expr target, - final ItpSolver solver) { + public static ExprTraceBwBinItpChecker create( + final Expr init, final Expr target, final ItpSolver solver) { return new ExprTraceBwBinItpChecker(init, target, solver); } @@ -103,10 +101,16 @@ public ExprTraceStatus check( solver.add(B, PathUtils.unfold(init, indexings.get(stateCount - 1))); concretizable = solver.check().isSat(); } else { - solver.add(B, PathUtils.unfold(traceRev.getState(satPostfix + 1).toExpr(), - indexings.get(satPostfix + 1))); - solver.add(B, PathUtils.unfold(traceRev.getAction(satPostfix).toExpr(), - indexings.get(satPostfix + 1))); + solver.add( + B, + PathUtils.unfold( + traceRev.getState(satPostfix + 1).toExpr(), + indexings.get(satPostfix + 1))); + solver.add( + B, + PathUtils.unfold( + traceRev.getAction(satPostfix).toExpr(), + indexings.get(satPostfix + 1))); solver.check(); assert solver.getStatus().isUnsat() : "Trying to interpolate a feasible formula"; concretizable = false; @@ -119,15 +123,17 @@ public ExprTraceStatus check( for (final VarIndexing indexing : indexings) { builder.add(PathUtils.extractValuation(model, indexing)); } - status = ExprTraceStatus.feasible( - Trace.of(builder.build().reverse(), trace.getActions())); + status = + ExprTraceStatus.feasible( + Trace.of(builder.build().reverse(), trace.getActions())); } else { final Interpolant interpolant = solver.getInterpolant(pattern); - final Expr itpFolded = PathUtils.foldin(interpolant.eval(A), - indexings.get(satPostfix)); - status = ExprTraceStatus - .infeasible( - ItpRefutation.binary(itpFolded, stateCount - 1 - satPostfix, stateCount)); + final Expr itpFolded = + PathUtils.foldin(interpolant.eval(A), indexings.get(satPostfix)); + status = + ExprTraceStatus.infeasible( + ItpRefutation.binary( + itpFolded, stateCount - 1 - satPostfix, stateCount)); } assert status != null; solver.pop(nPush); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceChecker.java index dbbda0a01c..258aeff8de 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedChecker.java index ec77d41bfa..06dae60b10 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,37 +17,36 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.analysis.expr.ExprState; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; public final class ExprTraceCombinedChecker implements ExprTraceChecker { private final Collection> checkers; private final ExprTraceStatusMerger merger; - private ExprTraceCombinedChecker(final Collection> checkers, - final ExprTraceStatusMerger merger) { + private ExprTraceCombinedChecker( + final Collection> checkers, final ExprTraceStatusMerger merger) { this.checkers = ImmutableList.copyOf(checkNotNull(checkers)); this.merger = checkNotNull(merger); } public static ExprTraceCombinedChecker create( final ExprTraceChecker checker1, - final ExprTraceChecker checker2, final ExprTraceStatusMerger merger) { + final ExprTraceChecker checker2, + final ExprTraceStatusMerger merger) { return new ExprTraceCombinedChecker<>(ImmutableList.of(checker1, checker2), merger); } @Override public ExprTraceStatus check(final Trace trace) { - final List> statuses = checkers.stream().map(c -> c.check(trace)) - .collect(Collectors.toList()); + final List> statuses = + checkers.stream().map(c -> c.check(trace)).collect(Collectors.toList()); return merger.merge(statuses); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedCheckers.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedCheckers.java index 0ee2e2f36d..8059e076c9 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedCheckers.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceCombinedCheckers.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,25 +21,24 @@ public final class ExprTraceCombinedCheckers { - private ExprTraceCombinedCheckers() { - } + private ExprTraceCombinedCheckers() {} - public static ExprTraceChecker createBwFwMinPrune(final Expr init, - final Expr target, final ItpSolver solver) { - final ExprTraceBwBinItpChecker bwChecker = ExprTraceBwBinItpChecker.create(init, target, - solver); - final ExprTraceFwBinItpChecker fwChecker = ExprTraceFwBinItpChecker.create(init, target, - solver); + public static ExprTraceChecker createBwFwMinPrune( + final Expr init, final Expr target, final ItpSolver solver) { + final ExprTraceBwBinItpChecker bwChecker = + ExprTraceBwBinItpChecker.create(init, target, solver); + final ExprTraceFwBinItpChecker fwChecker = + ExprTraceFwBinItpChecker.create(init, target, solver); final ExprTraceStatusMerger merger = ExprTraceStatusMergers.minPruneIndex(); return ExprTraceCombinedChecker.create(bwChecker, fwChecker, merger); } - public static ExprTraceChecker createBwFwMaxPrune(final Expr init, - final Expr target, final ItpSolver solver) { - final ExprTraceBwBinItpChecker bwChecker = ExprTraceBwBinItpChecker.create(init, target, - solver); - final ExprTraceFwBinItpChecker fwChecker = ExprTraceFwBinItpChecker.create(init, target, - solver); + public static ExprTraceChecker createBwFwMaxPrune( + final Expr init, final Expr target, final ItpSolver solver) { + final ExprTraceBwBinItpChecker bwChecker = + ExprTraceBwBinItpChecker.create(init, target, solver); + final ExprTraceFwBinItpChecker fwChecker = + ExprTraceFwBinItpChecker.create(init, target, solver); final ExprTraceStatusMerger merger = ExprTraceStatusMergers.maxPruneIndex(); return ExprTraceCombinedChecker.create(bwChecker, fwChecker, merger); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceFwBinItpChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceFwBinItpChecker.java index 3433a0c994..3090941225 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceFwBinItpChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceFwBinItpChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expr.refinement; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.ExprAction; @@ -29,12 +31,9 @@ import hu.bme.mit.theta.solver.ItpMarker; import hu.bme.mit.theta.solver.ItpPattern; import hu.bme.mit.theta.solver.ItpSolver; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - /** * An ExprTraceChecker that generates a binary interpolant by incrementally checking the * counterexample forward. @@ -45,16 +44,15 @@ public final class ExprTraceFwBinItpChecker implements ExprTraceChecker init; private final Expr target; - private ExprTraceFwBinItpChecker(final Expr init, final Expr target, - final ItpSolver solver) { + private ExprTraceFwBinItpChecker( + final Expr init, final Expr target, final ItpSolver solver) { this.solver = checkNotNull(solver); this.init = checkNotNull(init); this.target = checkNotNull(target); } - public static ExprTraceFwBinItpChecker create(final Expr init, - final Expr target, - final ItpSolver solver) { + public static ExprTraceFwBinItpChecker create( + final Expr init, final Expr target, final ItpSolver solver) { return new ExprTraceFwBinItpChecker(init, target, solver); } @@ -101,10 +99,14 @@ public ExprTraceStatus check( solver.add(B, PathUtils.unfold(target, indexings.get(stateCount - 1))); concretizable = solver.check().isSat(); } else { - solver.add(B, PathUtils.unfold(trace.getState(satPrefix + 1).toExpr(), - indexings.get(satPrefix + 1))); - solver.add(B, - PathUtils.unfold(trace.getAction(satPrefix).toExpr(), indexings.get(satPrefix))); + solver.add( + B, + PathUtils.unfold( + trace.getState(satPrefix + 1).toExpr(), indexings.get(satPrefix + 1))); + solver.add( + B, + PathUtils.unfold( + trace.getAction(satPrefix).toExpr(), indexings.get(satPrefix))); solver.check(); assert solver.getStatus().isUnsat() : "Trying to interpolate a feasible formula"; concretizable = false; @@ -120,10 +122,11 @@ public ExprTraceStatus check( status = ExprTraceStatus.feasible(Trace.of(builder.build(), trace.getActions())); } else { final Interpolant interpolant = solver.getInterpolant(pattern); - final Expr itpFolded = PathUtils.foldin(interpolant.eval(A), - indexings.get(satPrefix)); - status = ExprTraceStatus.infeasible( - ItpRefutation.binary(itpFolded, satPrefix, stateCount)); + final Expr itpFolded = + PathUtils.foldin(interpolant.eval(A), indexings.get(satPrefix)); + status = + ExprTraceStatus.infeasible( + ItpRefutation.binary(itpFolded, satPrefix, stateCount)); } assert status != null; solver.pop(nPush); @@ -135,5 +138,4 @@ public ExprTraceStatus check( public String toString() { return getClass().getSimpleName(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceNewtonChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceNewtonChecker.java index 599195154e..59cb66cb32 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceNewtonChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceNewtonChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.expr.refinement; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.decl.Decls.Param; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toUnmodifiableMap; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import hu.bme.mit.theta.analysis.Trace; @@ -54,7 +61,6 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -64,23 +70,18 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.decl.Decls.Param; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toUnmodifiableMap; - /** - * An ExprTraceChecker that generates new predicates based on the Newton-style algorithms described in - * Daniel Dietsch, Matthias Heizmann, Betim Musa, Alexander Nutz, and Andreas Podelski. 2017. - * Craig vs. Newton in software model checking. In Proceedings of the 2017 11th Joint Meeting on Foundations - * of Software Engineering (ESEC/FSE 2017). Association for Computing Machinery, New York, NY, USA, - * 487-497. DOI:https://doi.org/10.1145/3106237.3106307 + * An ExprTraceChecker that generates new predicates based on the Newton-style algorithms described + * in Daniel Dietsch, Matthias Heizmann, Betim Musa, Alexander Nutz, and Andreas Podelski. 2017. + * Craig vs. Newton in software model checking. In Proceedings of the 2017 11th Joint Meeting on + * Foundations of Software Engineering (ESEC/FSE 2017). Association for Computing + * Machinery, New York, NY, USA, 487-497. DOI:https://doi.org/10.1145/3106237.3106307 */ public class ExprTraceNewtonChecker implements ExprTraceChecker { - private enum AssertionGeneratorMethod {SP, WP} + private enum AssertionGeneratorMethod { + SP, + WP + } private final UCSolver solver; private final Expr init; @@ -92,9 +93,12 @@ private enum AssertionGeneratorMethod {SP, WP} private final boolean LV; // Whether to project the assertions to live variables private ExprTraceNewtonChecker( - final Expr init, final Expr target, final UCSolver solver, - boolean it, AssertionGeneratorMethod sPorWP, boolean lv - ) { + final Expr init, + final Expr target, + final UCSolver solver, + boolean it, + AssertionGeneratorMethod sPorWP, + boolean lv) { this.solver = checkNotNull(solver); this.init = checkNotNull(init); this.target = checkNotNull(target); @@ -105,14 +109,14 @@ private ExprTraceNewtonChecker( } public static ExprTraceNewtonCheckerITBuilder create( - final Expr init, final Expr target, final UCSolver solver - ) { + final Expr init, final Expr target, final UCSolver solver) { return new ExprTraceNewtonCheckerITBuilder(solver, init, target); } @SuppressWarnings("unchecked") @Override - public ExprTraceStatus check(final Trace trace) { + public ExprTraceStatus check( + final Trace trace) { checkNotNull(trace); try { return check2((Trace) trace); @@ -121,8 +125,12 @@ public ExprTraceStatus check(final Trace check2(final Trace trace) { - var ftrace = flattenTrace(trace); // Moves the expressions in the states to the corresponting actions as assumptions + private ExprTraceStatus check2( + final Trace trace) { + var ftrace = + flattenTrace( + trace); // Moves the expressions in the states to the corresponting actions + // as assumptions final int stateCount = ftrace.getStates().size(); final List indexings = new ArrayList<>(stateCount); @@ -137,7 +145,9 @@ private ExprTraceStatus check2(final Trace flattenTrace(final Trace trace) { + private Trace flattenTrace( + final Trace trace) { final var stateCount = trace.getStates().size(); final var flattenedActions = new ArrayList(stateCount - 1); @@ -178,23 +189,25 @@ public String toString() { ? ExprUtils.getConjuncts(init).stream().map(AssumeStmt::of) : Stream.empty(); - var stateStream = ExprUtils.getConjuncts(trace.getState(i - 1).toExpr()).stream().map(AssumeStmt::of); + var stateStream = + ExprUtils.getConjuncts(trace.getState(i - 1).toExpr()).stream() + .map(AssumeStmt::of); var actionStream = trace.getAction(i - 1).getStmts().stream(); var targetStream = (i == stateCount - 1) ? Stream.concat( - ExprUtils.getConjuncts(trace.getState(i).toExpr()).stream().map(AssumeStmt::of), - ExprUtils.getConjuncts(target).stream().map(AssumeStmt::of) - ) + ExprUtils.getConjuncts(trace.getState(i).toExpr()).stream() + .map(AssumeStmt::of), + ExprUtils.getConjuncts(target).stream().map(AssumeStmt::of)) : Stream.empty(); flattenedActions.add( NewtonAction.of( - Stream.of(initStream, stateStream, actionStream, targetStream).flatMap(e -> e).collect(toList()) - ) - ); + Stream.of(initStream, stateStream, actionStream, targetStream) + .flatMap(e -> e) + .collect(toList()))); } return ExprTraceUtils.traceFrom(flattenedActions); @@ -203,8 +216,7 @@ public String toString() { private ExprTraceStatus.Feasible createCounterexample( final Valuation model, final List indexings, - final Trace trace - ) { + final Trace trace) { final ImmutableList.Builder builder = ImmutableList.builder(); for (final VarIndexing indexing : indexings) { builder.add(PathUtils.extractValuation(model, indexing)); @@ -215,8 +227,7 @@ private ExprTraceStatus.Feasible createCounterexample( private ExprTraceStatus.Infeasible createRefinement( final Collection> unsatCore, final List indexings, - Trace trace - ) { + Trace trace) { if (IT) { trace = computeAbstractTrace(unsatCore, trace); } @@ -239,8 +250,7 @@ private ExprTraceStatus.Infeasible createRefinement( private Trace computeAbstractTrace( final Collection> unsatCore, - final Trace trace - ) { + final Trace trace) { final var stateCount = trace.getStates().size(); var curIndexing = VarIndexingFactory.indexing(0); @@ -250,7 +260,9 @@ private ExprTraceStatus.Infeasible createRefinement( final var stmts = new ArrayList(); for (final var stmt : trace.getAction(i - 1).getStmts()) { final var stmtUnfoldResult = StmtUtils.toExpr(stmt, VarIndexingFactory.indexing(0)); - final var stmtExpr = PathUtils.unfold(stmtUnfoldResult.getExprs().iterator().next(), curIndexing); + final var stmtExpr = + PathUtils.unfold( + stmtUnfoldResult.getExprs().iterator().next(), curIndexing); if (unsatCore.contains(stmtExpr)) { stmts.add(stmt); @@ -267,56 +279,64 @@ private ExprTraceStatus.Infeasible createRefinement( } private Stmt computeAbstractStmt(Stmt stmt) { - return stmt.accept(new StmtVisitor() { - @Override - public Stmt visit(SkipStmt stmt, Void param) { - return SkipStmt.getInstance(); - } - - @Override - public Stmt visit(AssumeStmt stmt, Void param) { - return AssumeStmt.of(True()); - } - - @Override - public Stmt visit(AssignStmt stmt, Void param) { - return HavocStmt.of(stmt.getVarDecl()); - } - - @Override - public Stmt visit(MemoryAssignStmt stmt, Void param) { - throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); - } - - @Override - public Stmt visit(HavocStmt stmt, Void param) { - return HavocStmt.of(stmt.getVarDecl()); - } - - @Override - public Stmt visit(SequenceStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Stmt visit(NonDetStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Stmt visit(OrtStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Stmt visit(LoopStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - public Stmt visit(IfStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - }, null); + return stmt.accept( + new StmtVisitor() { + @Override + public Stmt visit(SkipStmt stmt, Void param) { + return SkipStmt.getInstance(); + } + + @Override + public Stmt visit(AssumeStmt stmt, Void param) { + return AssumeStmt.of(True()); + } + + @Override + public Stmt visit( + AssignStmt stmt, Void param) { + return HavocStmt.of(stmt.getVarDecl()); + } + + @Override + public + Stmt visit( + MemoryAssignStmt stmt, + Void param) { + throw new UnsupportedOperationException( + "MemoryAssignStmt not supported (yet)"); + } + + @Override + public Stmt visit( + HavocStmt stmt, Void param) { + return HavocStmt.of(stmt.getVarDecl()); + } + + @Override + public Stmt visit(SequenceStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Stmt visit(NonDetStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Stmt visit(OrtStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Stmt visit(LoopStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + public Stmt visit(IfStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + }, + null); } /* @@ -324,8 +344,7 @@ public Stmt visit(IfStmt stmt, Void param) { */ private List> computeAssertionsFromTraceWithStrongestPostcondition( - final Trace trace - ) { + final Trace trace) { final int stateCount = trace.getStates().size(); final List> assertions = new ArrayList<>(stateCount); @@ -344,7 +363,12 @@ private List> computeAssertionsFromTraceWithStrongestPostconditio var allVariables = collectVariablesInTrace(trace); var futureLiveVariables = collectFutureLiveVariablesForTrace(trace); return IntStream.range(0, assertions.size()) - .mapToObj(i -> existentialProjection(assertions.get(i), futureLiveVariables.get(i), allVariables)) + .mapToObj( + i -> + existentialProjection( + assertions.get(i), + futureLiveVariables.get(i), + allVariables)) .collect(Collectors.toUnmodifiableList()); } else { return assertions; @@ -352,10 +376,10 @@ private List> computeAssertionsFromTraceWithStrongestPostconditio } private List> computeAssertionsFromTraceWithWeakestPrecondition( - final Trace trace - ) { + final Trace trace) { final int stateCount = trace.getStates().size(); - final List> assertions = new ArrayList<>(Collections.nCopies(stateCount, null)); + final List> assertions = + new ArrayList<>(Collections.nCopies(stateCount, null)); assertions.set(stateCount - 1, True()); var constCount = 0; @@ -364,7 +388,8 @@ private List> computeAssertionsFromTraceWithWeakestPrecondition( for (var stmt : Lists.reverse(trace.getAction(i).getStmts())) { wpState = wpState.wep(stmt); } - assertions.set(i, exprSimplifier.simplify(wpState.getExpr(), ImmutableValuation.empty())); + assertions.set( + i, exprSimplifier.simplify(wpState.getExpr(), ImmutableValuation.empty())); constCount = wpState.getConstCount(); } @@ -372,7 +397,12 @@ private List> computeAssertionsFromTraceWithWeakestPrecondition( var allVariables = collectVariablesInTrace(trace); var pastLiveVariables = collectPastLiveVariablesForTrace(trace); return IntStream.range(0, assertions.size()) - .mapToObj(i -> universalProjection(assertions.get(i), pastLiveVariables.get(i), allVariables)) + .mapToObj( + i -> + universalProjection( + assertions.get(i), + pastLiveVariables.get(i), + allVariables)) .collect(Collectors.toUnmodifiableList()); } else { return assertions; @@ -383,7 +413,8 @@ private List> computeAssertionsFromTraceWithWeakestPrecondition( * Live variable collection */ - private Collection> collectVariablesInTrace(final Trace trace) { + private Collection> collectVariablesInTrace( + final Trace trace) { var variables = new HashSet>(); for (var state : trace.getStates()) { @@ -397,179 +428,211 @@ private Collection> collectVariablesInTrace(final Trace> stmtReadsVariables(final Stmt stmt) { - return stmt.accept(new StmtVisitor>>() { - @Override - public Collection> visit(SkipStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(AssumeStmt stmt, Void param) { - return ExprUtils.getVars(stmt.getCond()); - } - - @Override - public Collection> visit(AssignStmt stmt, Void param) { - return ExprUtils.getVars(stmt.getExpr()); - } - - @Override - public Collection> visit(MemoryAssignStmt stmt, Void param) { - throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); - } - - @Override - public Collection> visit(HavocStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(SequenceStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(NonDetStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(OrtStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(LoopStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - public Collection> visit(IfStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - }, null); + return stmt.accept( + new StmtVisitor>>() { + @Override + public Collection> visit(SkipStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit(AssumeStmt stmt, Void param) { + return ExprUtils.getVars(stmt.getCond()); + } + + @Override + public Collection> visit( + AssignStmt stmt, Void param) { + return ExprUtils.getVars(stmt.getExpr()); + } + + @Override + public + Collection> visit( + MemoryAssignStmt stmt, + Void param) { + throw new UnsupportedOperationException( + "MemoryAssignStmt not supported (yet)"); + } + + @Override + public Collection> visit( + HavocStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit(SequenceStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(NonDetStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(OrtStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(LoopStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + public Collection> visit(IfStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + }, + null); } private Collection> stmtWritesVariables(final Stmt stmt) { - return stmt.accept(new StmtVisitor>>() { - @Override - public Collection> visit(SkipStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(AssumeStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(AssignStmt stmt, Void param) { - return Collections.singletonList(stmt.getVarDecl()); - } - - @Override - public Collection> visit(MemoryAssignStmt stmt, Void param) { - throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); - } - - @Override - public Collection> visit(HavocStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(SequenceStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(NonDetStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(OrtStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(LoopStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - public Collection> visit(IfStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - }, null); + return stmt.accept( + new StmtVisitor>>() { + @Override + public Collection> visit(SkipStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit(AssumeStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit( + AssignStmt stmt, Void param) { + return Collections.singletonList(stmt.getVarDecl()); + } + + @Override + public + Collection> visit( + MemoryAssignStmt stmt, + Void param) { + throw new UnsupportedOperationException( + "MemoryAssignStmt not supported (yet)"); + } + + @Override + public Collection> visit( + HavocStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit(SequenceStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(NonDetStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(OrtStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(LoopStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + public Collection> visit(IfStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + }, + null); } private Collection> stmtHavocsVariables(final Stmt stmt) { - return stmt.accept(new StmtVisitor>>() { - @Override - public Collection> visit(SkipStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(AssumeStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(AssignStmt stmt, Void param) { - return Collections.emptySet(); - } - - @Override - public Collection> visit(MemoryAssignStmt stmt, Void param) { - throw new UnsupportedOperationException("MemoryAssignStmt not supported (yet)"); - } - - @Override - public Collection> visit(HavocStmt stmt, Void param) { - return Collections.singletonList(stmt.getVarDecl()); - } - - @Override - public Collection> visit(SequenceStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(NonDetStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(OrtStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - @Override - public Collection> visit(LoopStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - - public Collection> visit(IfStmt stmt, Void param) { - throw new UnsupportedOperationException(); - } - }, null); + return stmt.accept( + new StmtVisitor>>() { + @Override + public Collection> visit(SkipStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit(AssumeStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public Collection> visit( + AssignStmt stmt, Void param) { + return Collections.emptySet(); + } + + @Override + public + Collection> visit( + MemoryAssignStmt stmt, + Void param) { + throw new UnsupportedOperationException( + "MemoryAssignStmt not supported (yet)"); + } + + @Override + public Collection> visit( + HavocStmt stmt, Void param) { + return Collections.singletonList(stmt.getVarDecl()); + } + + @Override + public Collection> visit(SequenceStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(NonDetStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(OrtStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + @Override + public Collection> visit(LoopStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + + public Collection> visit(IfStmt stmt, Void param) { + throw new UnsupportedOperationException(); + } + }, + null); } private Collection> actionReadsVariables(final StmtAction action) { - return action.getStmts().stream().flatMap(stmt -> stmtReadsVariables(stmt).stream()).collect(Collectors.toUnmodifiableSet()); + return action.getStmts().stream() + .flatMap(stmt -> stmtReadsVariables(stmt).stream()) + .collect(Collectors.toUnmodifiableSet()); } private Collection> actionWritesVariables(final StmtAction action) { - return action.getStmts().stream().flatMap(stmt -> stmtWritesVariables(stmt).stream()).collect(Collectors.toUnmodifiableSet()); + return action.getStmts().stream() + .flatMap(stmt -> stmtWritesVariables(stmt).stream()) + .collect(Collectors.toUnmodifiableSet()); } private Collection> actionHavocsVariables(final StmtAction action) { - return action.getStmts().stream().flatMap(stmt -> stmtHavocsVariables(stmt).stream()).collect(Collectors.toUnmodifiableSet()); + return action.getStmts().stream() + .flatMap(stmt -> stmtHavocsVariables(stmt).stream()) + .collect(Collectors.toUnmodifiableSet()); } - private List>> collectFutureLiveVariablesForTrace(final Trace trace) { + private List>> collectFutureLiveVariablesForTrace( + final Trace trace) { final var stateCount = trace.getStates().size(); - final var futureLiveVariables = new ArrayList>>(Collections.nCopies(stateCount, null)); + final var futureLiveVariables = + new ArrayList>>(Collections.nCopies(stateCount, null)); futureLiveVariables.set(stateCount - 1, Collections.emptySet()); for (var i = stateCount - 2; i >= 0; i--) { @@ -583,9 +646,11 @@ private List>> collectFutureLiveVariablesForTrace(final Tr return futureLiveVariables; } - private List>> collectPastLiveVariablesForTrace(final Trace trace) { + private List>> collectPastLiveVariablesForTrace( + final Trace trace) { final var stateCount = trace.getStates().size(); - final var pastLiveVariables = new ArrayList>>(Collections.nCopies(stateCount, null)); + final var pastLiveVariables = + new ArrayList>>(Collections.nCopies(stateCount, null)); pastLiveVariables.set(0, Collections.emptySet()); for (var i = 1; i < stateCount; i++) { @@ -606,38 +671,52 @@ private List>> collectPastLiveVariablesForTrace(final Trac private Expr existentialProjection( final Expr expr, final Collection> variables, - final Collection> allVariables - ) { - var params = allVariables.stream() - .filter(e -> !variables.contains(e)) - .map(e -> Tuple2.of(e, Param(e.getName(), e.getType()))) - .collect(Collectors.toUnmodifiableSet()); - - var substitution = BasicSubstitution.builder() - .putAll(params.stream().collect(toUnmodifiableMap(Tuple2::get1, e -> e.get2().getRef()))) - .build(); + final Collection> allVariables) { + var params = + allVariables.stream() + .filter(e -> !variables.contains(e)) + .map(e -> Tuple2.of(e, Param(e.getName(), e.getType()))) + .collect(Collectors.toUnmodifiableSet()); + + var substitution = + BasicSubstitution.builder() + .putAll( + params.stream() + .collect( + toUnmodifiableMap( + Tuple2::get1, e -> e.get2().getRef()))) + .build(); return params.size() > 0 - ? Exists(params.stream().map(Tuple2::get2).collect(toList()), substitution.apply(expr)) + ? Exists( + params.stream().map(Tuple2::get2).collect(toList()), + substitution.apply(expr)) : expr; } private Expr universalProjection( final Expr expr, final Collection> variables, - final Collection> allVariables - ) { - var params = allVariables.stream() - .filter(e -> !variables.contains(e)) - .map(e -> Tuple2.of(e, Param(e.getName(), e.getType()))) - .collect(Collectors.toUnmodifiableSet()); - - var substitution = BasicSubstitution.builder() - .putAll(params.stream().collect(toUnmodifiableMap(Tuple2::get1, e -> e.get2().getRef()))) - .build(); + final Collection> allVariables) { + var params = + allVariables.stream() + .filter(e -> !variables.contains(e)) + .map(e -> Tuple2.of(e, Param(e.getName(), e.getType()))) + .collect(Collectors.toUnmodifiableSet()); + + var substitution = + BasicSubstitution.builder() + .putAll( + params.stream() + .collect( + toUnmodifiableMap( + Tuple2::get1, e -> e.get2().getRef()))) + .build(); return params.size() > 0 - ? Forall(params.stream().map(Tuple2::get2).collect(toList()), substitution.apply(expr)) + ? Forall( + params.stream().map(Tuple2::get2).collect(toList()), + substitution.apply(expr)) : expr; } @@ -650,7 +729,8 @@ public static class ExprTraceNewtonCheckerITBuilder { private final Expr init; private final Expr target; - public ExprTraceNewtonCheckerITBuilder(UCSolver solver, Expr init, Expr target) { + public ExprTraceNewtonCheckerITBuilder( + UCSolver solver, Expr init, Expr target) { this.solver = solver; this.init = init; this.target = target; @@ -672,7 +752,8 @@ public static class ExprTraceNewtonCheckerAssertBuilder { private final boolean IT; - public ExprTraceNewtonCheckerAssertBuilder(UCSolver solver, Expr init, Expr target, boolean it) { + public ExprTraceNewtonCheckerAssertBuilder( + UCSolver solver, Expr init, Expr target, boolean it) { this.solver = solver; this.init = init; this.target = target; @@ -680,11 +761,13 @@ public ExprTraceNewtonCheckerAssertBuilder(UCSolver solver, Expr init, } public ExprTraceNewtonCheckerLVBuilder withSP() { - return new ExprTraceNewtonCheckerLVBuilder(solver, init, target, IT, AssertionGeneratorMethod.SP); + return new ExprTraceNewtonCheckerLVBuilder( + solver, init, target, IT, AssertionGeneratorMethod.SP); } public ExprTraceNewtonCheckerLVBuilder withWP() { - return new ExprTraceNewtonCheckerLVBuilder(solver, init, target, IT, AssertionGeneratorMethod.WP); + return new ExprTraceNewtonCheckerLVBuilder( + solver, init, target, IT, AssertionGeneratorMethod.WP); } } @@ -696,7 +779,12 @@ public static class ExprTraceNewtonCheckerLVBuilder { private final boolean IT; private final AssertionGeneratorMethod SPorWP; - public ExprTraceNewtonCheckerLVBuilder(UCSolver solver, Expr init, Expr target, boolean it, AssertionGeneratorMethod sPorWP) { + public ExprTraceNewtonCheckerLVBuilder( + UCSolver solver, + Expr init, + Expr target, + boolean it, + AssertionGeneratorMethod sPorWP) { this.solver = solver; this.init = init; this.target = target; @@ -735,7 +823,10 @@ public List getStmts() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).body().addAll(stmts).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .body() + .addAll(stmts) + .toString(); } } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceSeqItpChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceSeqItpChecker.java index a09ad0761f..875fedf66e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceSeqItpChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceSeqItpChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expr.refinement; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.ExprAction; @@ -30,31 +32,25 @@ import hu.bme.mit.theta.solver.ItpPattern; import hu.bme.mit.theta.solver.ItpSolver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * An ExprTraceChecker that generates a sequence interpolant by checking the trace at once. - */ +/** An ExprTraceChecker that generates a sequence interpolant by checking the trace at once. */ public final class ExprTraceSeqItpChecker implements ExprTraceChecker { private final ItpSolver solver; private final Expr init; private final Expr target; - private ExprTraceSeqItpChecker(final Expr init, final Expr target, - final ItpSolver solver) { + private ExprTraceSeqItpChecker( + final Expr init, final Expr target, final ItpSolver solver) { this.solver = checkNotNull(solver); this.init = checkNotNull(init); this.target = checkNotNull(target); } - public static ExprTraceSeqItpChecker create(final Expr init, - final Expr target, - final ItpSolver solver) { + public static ExprTraceSeqItpChecker create( + final Expr init, final Expr target, final ItpSolver solver) { return new ExprTraceSeqItpChecker(init, target, solver); } @@ -75,19 +71,22 @@ public ExprTraceStatus check( indexings.add(VarIndexingFactory.indexing(0)); solver.add(markers.get(0), PathUtils.unfold(init, indexings.get(0))); - solver.add(markers.get(0), - PathUtils.unfold(trace.getState(0).toExpr(), indexings.get(0))); + solver.add( + markers.get(0), PathUtils.unfold(trace.getState(0).toExpr(), indexings.get(0))); assert solver.check().isSat() : "Initial state of the trace is not feasible"; for (int i = 1; i < stateCount; ++i) { indexings.add(indexings.get(i - 1).add(trace.getAction(i - 1).nextIndexing())); - solver.add(markers.get(i), + solver.add( + markers.get(i), PathUtils.unfold(trace.getState(i).toExpr(), indexings.get(i))); - solver.add(markers.get(i), + solver.add( + markers.get(i), PathUtils.unfold(trace.getAction(i - 1).toExpr(), indexings.get(i - 1))); } - solver.add(markers.get(trace.getStates().size()), + solver.add( + markers.get(trace.getStates().size()), PathUtils.unfold(target, indexings.get(stateCount - 1))); final boolean concretizable = solver.check().isSat(); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatus.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatus.java index 44f041ea70..e3ab74e429 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatus.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatus.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,8 +24,7 @@ public abstract class ExprTraceStatus { - private ExprTraceStatus() { - } + private ExprTraceStatus() {} public static Infeasible infeasible(final R refutation) { return new Infeasible<>(refutation); @@ -44,7 +43,7 @@ public static Feasible feasible( public abstract Feasible asFeasible(); - public final static class Infeasible extends ExprTraceStatus { + public static final class Infeasible extends ExprTraceStatus { private final R refutation; @@ -74,7 +73,9 @@ public Infeasible asInfeasible() { @Override public Feasible asFeasible() { throw new ClassCastException( - "Cannot cast " + Infeasible.class.getSimpleName() + " to " + "Cannot cast " + + Infeasible.class.getSimpleName() + + " to " + Feasible.class.getSimpleName()); } @@ -84,10 +85,9 @@ public String toString() { .add(getClass().getSimpleName()) .toString(); } - } - public final static class Feasible extends ExprTraceStatus { + public static final class Feasible extends ExprTraceStatus { private final Trace valuations; @@ -112,7 +112,9 @@ public boolean isFeasible() { @Override public Infeasible asInfeasible() { throw new ClassCastException( - "Cannot cast " + Feasible.class.getSimpleName() + " to " + "Cannot cast " + + Feasible.class.getSimpleName() + + " to " + Infeasible.class.getSimpleName()); } @@ -127,6 +129,5 @@ public String toString() { .add(getClass().getSimpleName()) .toString(); } - } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMerger.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMerger.java index 0c5472ca06..26c6dd496b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMerger.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMerger.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.analysis.expr.refinement; -import java.util.Collection; - import com.google.common.collect.ImmutableList; +import java.util.Collection; public interface ExprTraceStatusMerger { - default ExprTraceStatus merge(final ExprTraceStatus status1, - final ExprTraceStatus status2) { + default ExprTraceStatus merge( + final ExprTraceStatus status1, final ExprTraceStatus status2) { return merge(ImmutableList.of(status1, status2)); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMergers.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMergers.java index 0a738de0b9..177a9a5de9 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMergers.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceStatusMergers.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,8 +21,7 @@ public final class ExprTraceStatusMergers { - private ExprTraceStatusMergers() { - } + private ExprTraceStatusMergers() {} public static ExprTraceStatusMerger minPruneIndex() { return new MinPruneIndex<>(); @@ -44,9 +43,14 @@ public ExprTraceStatus merge(final Collection> statuses) { return firstStatus; } else { assert statuses.stream().allMatch(ExprTraceStatus::isInfeasible); - return statuses.stream().map(ExprTraceStatus::asInfeasible).min((s1, s2) -> Integer - .compare(s1.getRefutation().getPruneIndex(), - s2.getRefutation().getPruneIndex())).get(); + return statuses.stream() + .map(ExprTraceStatus::asInfeasible) + .min( + (s1, s2) -> + Integer.compare( + s1.getRefutation().getPruneIndex(), + s2.getRefutation().getPruneIndex())) + .get(); } } } @@ -63,9 +67,14 @@ public ExprTraceStatus merge(final Collection> statuses) { return firstStatus; } else { assert statuses.stream().allMatch(ExprTraceStatus::isInfeasible); - return statuses.stream().map(ExprTraceStatus::asInfeasible).max((s1, s2) -> Integer - .compare(s1.getRefutation().getPruneIndex(), - s2.getRefutation().getPruneIndex())).get(); + return statuses.stream() + .map(ExprTraceStatus::asInfeasible) + .max( + (s1, s2) -> + Integer.compare( + s1.getRefutation().getPruneIndex(), + s2.getRefutation().getPruneIndex())) + .get(); } } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUCBChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUCBChecker.java index 5fafe70d30..3263ce48c5 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUCBChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUCBChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.expr.refinement; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; +import static java.util.stream.Collectors.toList; + import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import hu.bme.mit.theta.analysis.Trace; @@ -39,7 +44,6 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -49,16 +53,10 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.SmartBoolExprs.Not; -import static java.util.stream.Collectors.toList; - /** - * An ExprTraceChecker that generates new predicates based on the UCB algorithm by - * Leucker, Martin & Markin, Grigory & Neuhausser, Martin. (2015). A New Refinement - * Strategy for CEGAR-Based Industrial Model Checking. 155-170. 10.1007/978-3-319-26287-1_10. + * An ExprTraceChecker that generates new predicates based on the UCB algorithm by Leucker, Martin + * & Markin, Grigory & Neuhausser, Martin. (2015). A New Refinement Strategy for CEGAR-Based + * Industrial Model Checking. 155-170. 10.1007/978-3-319-26287-1_10. */ public class ExprTraceUCBChecker implements ExprTraceChecker { @@ -67,7 +65,8 @@ public class ExprTraceUCBChecker implements ExprTraceChecker { private final Expr target; private final ExprSimplifier exprSimplifier; - private ExprTraceUCBChecker(final Expr init, final Expr target, final UCSolver solver) { + private ExprTraceUCBChecker( + final Expr init, final Expr target, final UCSolver solver) { this.solver = checkNotNull(solver); this.init = checkNotNull(init); this.target = checkNotNull(target); @@ -75,14 +74,14 @@ private ExprTraceUCBChecker(final Expr init, final Expr targ } public static ExprTraceUCBChecker create( - final Expr init, final Expr target, final UCSolver solver - ) { + final Expr init, final Expr target, final UCSolver solver) { return new ExprTraceUCBChecker(init, target, solver); } @SuppressWarnings("unchecked") @Override - public ExprTraceStatus check(final Trace trace) { + public ExprTraceStatus check( + final Trace trace) { checkNotNull(trace); try { return check2((Trace) trace); @@ -91,7 +90,8 @@ public ExprTraceStatus check(final Trace check2(final Trace trace) { + private ExprTraceStatus check2( + final Trace trace) { final var ftrace = flattenTrace(trace); final int stateCount = trace.getStates().size(); @@ -107,9 +107,8 @@ private ExprTraceStatus check2(final Trace createCounterexample( final Valuation model, final List indexings, - final Trace trace - ) { + final Trace trace) { final ImmutableList.Builder builder = ImmutableList.builder(); for (final VarIndexing indexing : indexings) { builder.add(PathUtils.extractValuation(model, indexing)); @@ -152,8 +150,7 @@ private ExprTraceStatus.Feasible createCounterexample( private ExprTraceStatus.Infeasible createRefinement( final Collection> unsatCore, final List indexings, - final Trace trace - ) { + final Trace trace) { final int stateCount = trace.getStates().size(); final List> wps = calculateWpStates(trace, indexings); @@ -169,7 +166,10 @@ private ExprTraceStatus.Infeasible createRefinement( solver.track(True()); dataRegion.add(True()); } else /* i > 0 */ { - var spState = SpState.of(PathUtils.foldin(predicates.get(i - 1), indexings.get(i - 1)), constCount); + var spState = + SpState.of( + PathUtils.foldin(predicates.get(i - 1), indexings.get(i - 1)), + constCount); for (var stmt : trace.getAction(i - 1).getStmts()) { spState = spState.sp(stmt); } @@ -198,25 +198,20 @@ private ExprTraceStatus.Infeasible createRefinement( /* Add the negated of the above expression as the new predicate */ predicates.add( exprSimplifier.simplify( - Not(And(new HashSet<>(predicate))), - ImmutableValuation.empty() - ) - ); + Not(And(new HashSet<>(predicate))), ImmutableValuation.empty())); } } return ExprTraceStatus.infeasible( ItpRefutation.sequence( IntStream.range(0, predicates.size()) - .mapToObj(i -> PathUtils.foldin(predicates.get(i), indexings.get(i))) - .collect(Collectors.toUnmodifiableList()) - ) - ); + .mapToObj( + i -> PathUtils.foldin(predicates.get(i), indexings.get(i))) + .collect(Collectors.toUnmodifiableList()))); } private List> calculateWpStates( final Trace trace, - final List indexings - ) { + final List indexings) { final int stateCount = trace.getStates().size(); final List> wps = new ArrayList<>(Collections.nCopies(stateCount, null)); @@ -235,7 +230,8 @@ private List> calculateWpStates( return wps; } - private Trace flattenTrace(final Trace trace) { + private Trace flattenTrace( + final Trace trace) { final var stateCount = trace.getStates().size(); final var flattenedActions = new ArrayList(stateCount - 1); @@ -245,23 +241,25 @@ private List> calculateWpStates( ? ExprUtils.getConjuncts(init).stream().map(AssumeStmt::of) : Stream.empty(); - var stateStream = ExprUtils.getConjuncts(trace.getState(i - 1).toExpr()).stream().map(AssumeStmt::of); + var stateStream = + ExprUtils.getConjuncts(trace.getState(i - 1).toExpr()).stream() + .map(AssumeStmt::of); var actionStream = trace.getAction(i - 1).getStmts().stream(); var targetStream = (i == stateCount - 1) ? Stream.concat( - ExprUtils.getConjuncts(trace.getState(i).toExpr()).stream().map(AssumeStmt::of), - ExprUtils.getConjuncts(target).stream().map(AssumeStmt::of) - ) + ExprUtils.getConjuncts(trace.getState(i).toExpr()).stream() + .map(AssumeStmt::of), + ExprUtils.getConjuncts(target).stream().map(AssumeStmt::of)) : Stream.empty(); flattenedActions.add( UCBAction.of( - Stream.of(initStream, stateStream, actionStream, targetStream).flatMap(e -> e).collect(toList()) - ) - ); + Stream.of(initStream, stateStream, actionStream, targetStream) + .flatMap(e -> e) + .collect(toList()))); } return ExprTraceUtils.traceFrom(flattenedActions); @@ -289,7 +287,10 @@ public List getStmts() { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).body().addAll(stmts).toString(); + return Utils.lispStringBuilder(getClass().getSimpleName()) + .body() + .addAll(stmts) + .toString(); } } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUnsatCoreChecker.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUnsatCoreChecker.java index 7a56ef2d5f..6654a2c610 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUnsatCoreChecker.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ExprTraceUnsatCoreChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,8 @@ */ package hu.bme.mit.theta.analysis.expr.refinement; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import hu.bme.mit.theta.analysis.Trace; import hu.bme.mit.theta.analysis.expr.ExprAction; @@ -29,32 +31,26 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; import hu.bme.mit.theta.solver.UCSolver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * An ExprTraceChecker that generates an unsat core by checking the trace at once. - */ +/** An ExprTraceChecker that generates an unsat core by checking the trace at once. */ public final class ExprTraceUnsatCoreChecker implements ExprTraceChecker { private final UCSolver solver; private final Expr init; private final Expr target; - private ExprTraceUnsatCoreChecker(final Expr init, final Expr target, - final UCSolver solver) { + private ExprTraceUnsatCoreChecker( + final Expr init, final Expr target, final UCSolver solver) { this.solver = checkNotNull(solver); this.init = checkNotNull(init); this.target = checkNotNull(target); } - public static ExprTraceUnsatCoreChecker create(final Expr init, - final Expr target, - final UCSolver solver) { + public static ExprTraceUnsatCoreChecker create( + final Expr init, final Expr target, final UCSolver solver) { return new ExprTraceUnsatCoreChecker(init, target, solver); } @@ -69,18 +65,21 @@ public ExprTraceStatus check( try (WithPushPop wpp = new WithPushPop(solver)) { solver.track(ExprUtils.getConjuncts(PathUtils.unfold(init, indexings.get(0)))); - solver.track(ExprUtils.getConjuncts( - PathUtils.unfold(trace.getState(0).toExpr(), indexings.get(0)))); + solver.track( + ExprUtils.getConjuncts( + PathUtils.unfold(trace.getState(0).toExpr(), indexings.get(0)))); assert solver.check().isSat() : "Initial state of the trace is not feasible"; boolean concretizable = true; for (int i = 1; i < stateCount; ++i) { indexings.add(indexings.get(i - 1).add(trace.getAction(i - 1).nextIndexing())); - solver.track(ExprUtils.getConjuncts( - PathUtils.unfold(trace.getState(i).toExpr(), indexings.get(i)))); - solver.track(ExprUtils - .getConjuncts( - PathUtils.unfold(trace.getAction(i - 1).toExpr(), indexings.get(i - 1)))); + solver.track( + ExprUtils.getConjuncts( + PathUtils.unfold(trace.getState(i).toExpr(), indexings.get(i)))); + solver.track( + ExprUtils.getConjuncts( + PathUtils.unfold( + trace.getAction(i - 1).toExpr(), indexings.get(i - 1)))); if (!solver.check().isSat()) { concretizable = false; @@ -89,8 +88,9 @@ public ExprTraceStatus check( } if (concretizable) { - solver.track(ExprUtils.getConjuncts( - PathUtils.unfold(target, indexings.get(stateCount - 1)))); + solver.track( + ExprUtils.getConjuncts( + PathUtils.unfold(target, indexings.get(stateCount - 1)))); concretizable = solver.check().isSat(); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ItpRefutation.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ItpRefutation.java index 3335271d23..946238e283 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ItpRefutation.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/ItpRefutation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,23 +21,19 @@ import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.stream.Stream; - import com.google.common.collect.ImmutableList; - import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; import hu.bme.mit.theta.core.utils.IndexedVars; import hu.bme.mit.theta.core.utils.IndexedVars.Builder; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Stream; -/** - * An interpolant-based refutation that is a sequence of formulas. - */ +/** An interpolant-based refutation that is a sequence of formulas. */ public final class ItpRefutation implements Refutation, Iterable> { private final List> itpSequence; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/JoiningPrecRefiner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/JoiningPrecRefiner.java index dfa89ece22..b7713a16e2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/JoiningPrecRefiner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/JoiningPrecRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -27,7 +27,8 @@ * A basic implementation of PrecRefiner that simply converts each element of the Refutation into a * Precision and joins them. */ -public final class JoiningPrecRefiner +public final class JoiningPrecRefiner< + S extends State, A extends Action, P extends Prec, R extends Refutation> implements PrecRefiner { private final RefutationToPrec refToPrec; @@ -36,8 +37,8 @@ private JoiningPrecRefiner(final RefutationToPrec refToPrec) { this.refToPrec = checkNotNull(refToPrec); } - public static JoiningPrecRefiner create( - final RefutationToPrec refToPrec) { + public static + JoiningPrecRefiner create(final RefutationToPrec refToPrec) { return new JoiningPrecRefiner<>(refToPrec); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/MultiExprTraceRefiner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/MultiExprTraceRefiner.java index 71b8799468..feec2a2661 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/MultiExprTraceRefiner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/MultiExprTraceRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/NodePruner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/NodePruner.java index 2073ef2141..6b13d861fb 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/NodePruner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/NodePruner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,15 +20,13 @@ import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.analysis.expr.ExprState; -/** - * Functional interface for pruning a node from an ARG. - */ +/** Functional interface for pruning a node from an ARG. */ public interface NodePruner { /** * Prunes the given node or one of its ancestors in the ARG from the given ARG. * - * @param arg the ARG + * @param arg the ARG * @param node the node which or whose ancestor will be pruned from the ARG */ void prune(final ARG arg, ArgNode node); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PrecRefiner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PrecRefiner.java index 0be91cc41d..007c98ae03 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PrecRefiner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PrecRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,14 +20,10 @@ import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.Trace; -/** - * Interface for refining a precision based on a trace and a refutation. - */ -public interface PrecRefiner { +/** Interface for refining a precision based on a trace and a refutation. */ +public interface PrecRefiner< + S extends State, A extends Action, P extends Prec, R extends Refutation> { - /** - * Refine a precision based on a trace and a refutation. - */ + /** Refine a precision based on a trace and a refutation. */ P refine(P prec, Trace trace, R refutation); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PruneStrategy.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PruneStrategy.java index 2c700ba33b..c47841f57a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PruneStrategy.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/PruneStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,6 @@ package hu.bme.mit.theta.analysis.expr.refinement; public enum PruneStrategy { - LAZY, FULL + LAZY, + FULL } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/Refutation.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/Refutation.java index 43ac078204..d95c8b3c2b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/Refutation.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/Refutation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/RefutationToPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/RefutationToPrec.java index ee6a110170..f7ff1f5e75 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/RefutationToPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/RefutationToPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/SingleExprTraceRefiner.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/SingleExprTraceRefiner.java index 04befdbfcb..dc4c94f33d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/SingleExprTraceRefiner.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/SingleExprTraceRefiner.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/VarsRefutation.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/VarsRefutation.java index f1c8d9fabb..20a43b19ae 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/VarsRefutation.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/VarsRefutation.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -21,9 +21,7 @@ import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.utils.IndexedVars; -/** - * A variable-based refutation that is a sequence of sets of variables. - */ +/** A variable-based refutation that is a sequence of sets of variables. */ public final class VarsRefutation implements Refutation { private final IndexedVars indexedVars; @@ -31,8 +29,8 @@ public final class VarsRefutation implements Refutation { private VarsRefutation(final IndexedVars indexedVars) { checkNotNull(indexedVars); - checkArgument(!indexedVars.isEmpty(), - "Trying to create refutation with empty set of variables"); + checkArgument( + !indexedVars.isEmpty(), "Trying to create refutation with empty set of variables"); this.indexedVars = indexedVars; int i = 0; while (indexedVars.getVars(i).isEmpty()) { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/AutoExpl.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/AutoExpl.java index 50e57780de..a0bb0dadb2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/AutoExpl.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/AutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,5 +24,4 @@ public interface AutoExpl { boolean isExpl(final VarDecl decl); void update(final Expr itp); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewAtomsAutoExpl.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewAtomsAutoExpl.java index 899633c0dd..f44d3ef6e2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewAtomsAutoExpl.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewAtomsAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.analysis.expr.refinement.autoexpl; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.Map; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public class NewAtomsAutoExpl implements AutoExpl { private final Set> explVars = Containers.createSet(); @@ -35,8 +34,10 @@ public class NewAtomsAutoExpl implements AutoExpl { private final Map, Set>> newAtoms; private final int newAtomsLimit; - public NewAtomsAutoExpl(final Set> explPreferredVars, - final Set> modelAtoms, final int newAtomsLimit) { + public NewAtomsAutoExpl( + final Set> explPreferredVars, + final Set> modelAtoms, + final int newAtomsLimit) { explVars.addAll(explPreferredVars); this.modelAtoms = modelAtoms; this.newAtomsLimit = newAtomsLimit; @@ -52,24 +53,32 @@ public boolean isExpl(final VarDecl decl) { @Override public void update(final Expr itp) { - final var canonicalAtoms = ExprUtils.getAtoms(itp).stream() - .map(ExprUtils::canonize) - .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) - .collect(Collectors.toSet()); + final var canonicalAtoms = + ExprUtils.getAtoms(itp).stream() + .map(ExprUtils::canonize) + .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) + .collect(Collectors.toSet()); canonicalAtoms.stream() .filter(Predicate.not(modelAtoms::contains)) .forEach( - atom -> ExprUtils.getVars(atom).forEach( - decl -> newAtoms.computeIfAbsent(decl, (k) -> Containers.createSet()).add(atom) - ) - ); + atom -> + ExprUtils.getVars(atom) + .forEach( + decl -> + newAtoms.computeIfAbsent( + decl, + (k) -> + Containers + .createSet()) + .add(atom))); explVars.addAll( ExprUtils.getVars(itp).stream() .filter( - decl -> newAtoms.containsKey(decl) && newAtoms.get(decl).size() > newAtomsLimit - || decl.getType() == Bool()) + decl -> + newAtoms.containsKey(decl) + && newAtoms.get(decl).size() > newAtomsLimit + || decl.getType() == Bool()) .collect(Collectors.toSet())); - } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewOperandsAutoExpl.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewOperandsAutoExpl.java index a505e69a8e..5f7fa04c7b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewOperandsAutoExpl.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/NewOperandsAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,22 +15,20 @@ */ package hu.bme.mit.theta.analysis.expr.refinement.autoexpl; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.Decl; import hu.bme.mit.theta.core.decl.VarDecl; -import hu.bme.mit.theta.core.type.BinaryExpr; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.anytype.RefExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.Map; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public class NewOperandsAutoExpl implements AutoExpl { private final Set> explVars = Containers.createSet(); @@ -38,8 +36,10 @@ public class NewOperandsAutoExpl implements AutoExpl { private final Map, Set>> newOperands; private final int newOperandsLimit; - public NewOperandsAutoExpl(final Set> explPreferredVars, - final Map, Set>> modelOperands, final int newOperandsLimit) { + public NewOperandsAutoExpl( + final Set> explPreferredVars, + final Map, Set>> modelOperands, + final int newOperandsLimit) { explVars.addAll(explPreferredVars); this.newOperandsLimit = newOperandsLimit; this.modelOperands = modelOperands; @@ -55,10 +55,11 @@ public boolean isExpl(VarDecl decl) { @Override public void update(Expr itp) { - final Set> canonicalAtoms = ExprUtils.getAtoms(itp).stream() - .map(ExprUtils::canonize) - .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) - .collect(Collectors.toSet()); + final Set> canonicalAtoms = + ExprUtils.getAtoms(itp).stream() + .map(ExprUtils::canonize) + .flatMap(atom -> ExprUtils.getAtoms(atom).stream()) + .collect(Collectors.toSet()); canonicalAtoms.stream() .filter(atom -> atom.getOps().size() > 1) .forEach( @@ -67,29 +68,39 @@ public void update(Expr itp) { .filter(RefExpr.class::isInstance) .map(RefExpr.class::cast) .forEach( - ref -> atom.getOps().stream() - .filter(Predicate.not(ref::equals)) - .forEach( - op -> { - final Decl decl = ref.getDecl(); - if (modelOperands.containsKey(decl) && !modelOperands.get( - decl).contains(op)) { - newOperands.computeIfAbsent(decl, - k -> Containers.createSet()).add(op); - } - } - ) - - ); - } - ); + ref -> + atom.getOps().stream() + .filter(Predicate.not(ref::equals)) + .forEach( + op -> { + final Decl decl = + ref.getDecl(); + if (modelOperands + .containsKey( + decl) + && !modelOperands + .get(decl) + .contains( + op)) { + newOperands + .computeIfAbsent( + decl, + k -> + Containers + .createSet()) + .add(op); + } + })); + }); explVars.addAll( ExprUtils.getVars(itp).stream() - .filter(decl -> - newOperands.containsKey(decl) && newOperands.get(decl).size() > newOperandsLimit - || decl.getType() == Bool()) + .filter( + decl -> + newOperands.containsKey(decl) + && newOperands.get(decl).size() + > newOperandsLimit + || decl.getType() == Bool()) .collect(Collectors.toSet())); - } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/StaticAutoExpl.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/StaticAutoExpl.java index 4d292f4b0a..f1d13d78af 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/StaticAutoExpl.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/expr/refinement/autoexpl/StaticAutoExpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,13 @@ */ package hu.bme.mit.theta.analysis.expr.refinement.autoexpl; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; + import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Set; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool; - public class StaticAutoExpl implements AutoExpl { private final Set> ctrlVars; @@ -37,6 +36,5 @@ public boolean isExpl(final VarDecl decl) { } @Override - public void update(final Expr itp) { - } + public void update(final Expr itp) {} } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingAnalysis.java index 75146b9185..a6f24d32bd 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,25 +17,26 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Analysis; -import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.InitFunc; +import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; +import java.util.function.Function; -public final class PrecMappingAnalysis +public final class PrecMappingAnalysis< + S extends State, A extends Action, PP extends Prec, PR extends Prec> implements Analysis { private final PartialOrd partialOrd; private final InitFunc initFunc; private final TransFunc transFunc; - private PrecMappingAnalysis(final Analysis analysis, - final Function mapping) { + private PrecMappingAnalysis( + final Analysis analysis, + final Function mapping) { checkNotNull(analysis); checkNotNull(mapping); this.partialOrd = analysis.getPartialOrd(); @@ -43,9 +44,10 @@ private PrecMappingAnalysis(final Analysis analysis, this.transFunc = PrecMappingTransFunc.create(analysis.getTransFunc(), mapping); } - public static PrecMappingAnalysis create( - final Analysis analysis, - final Function mapping) { + public static + PrecMappingAnalysis create( + final Analysis analysis, + final Function mapping) { return new PrecMappingAnalysis<>(analysis, mapping); } @@ -63,5 +65,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingInitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingInitFunc.java index f0c0fe712a..f098712072 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingInitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,27 +17,29 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; +import java.util.Collection; +import java.util.function.Function; -final class PrecMappingInitFunc implements - InitFunc { +final class PrecMappingInitFunc + implements InitFunc { private final InitFunc initFunc; private final Function mapping; - private PrecMappingInitFunc(final InitFunc initFunc, - final Function mapping) { + private PrecMappingInitFunc( + final InitFunc initFunc, + final Function mapping) { this.initFunc = checkNotNull(initFunc); this.mapping = checkNotNull(mapping); } - public static PrecMappingInitFunc create( - final InitFunc initFunc, final Function mapping) { + public static + PrecMappingInitFunc create( + final InitFunc initFunc, + final Function mapping) { return new PrecMappingInitFunc<>(initFunc, mapping); } @@ -45,5 +47,4 @@ public static PrecMappingIni public Collection getInitStates(final PP prec) { return initFunc.getInitStates(mapping.apply(prec)); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingTransFunc.java index f533945a76..b064bf1ef1 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/impl/PrecMappingTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,29 +17,31 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; -import java.util.function.Function; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; +import java.util.Collection; +import java.util.function.Function; -final class PrecMappingTransFunc +final class PrecMappingTransFunc< + S extends State, A extends Action, PP extends Prec, PR extends Prec> implements TransFunc { private final TransFunc transFunc; private final Function mapping; - private PrecMappingTransFunc(final TransFunc transFunc, - final Function mapping) { + private PrecMappingTransFunc( + final TransFunc transFunc, + final Function mapping) { this.transFunc = checkNotNull(transFunc); this.mapping = checkNotNull(mapping); } - public static PrecMappingTransFunc create( - final TransFunc transFunc, - final Function mapping) { + public static + PrecMappingTransFunc create( + final TransFunc transFunc, + final Function mapping) { return new PrecMappingTransFunc<>(transFunc, mapping); } @@ -47,5 +49,4 @@ public static getSuccStates(final S state, final A action, final PP prec) { return transFunc.getSuccStates(state, action, mapping.apply(prec)); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAction.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAction.java index 74d9c52188..1dc55dae79 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAction.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,7 +15,6 @@ */ package hu.bme.mit.theta.analysis.multi; - import hu.bme.mit.theta.analysis.Action; public interface MultiAction extends Action { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAnalysis.java index ce51c74247..0e67832b32 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,30 +17,43 @@ import hu.bme.mit.theta.analysis.*; import hu.bme.mit.theta.analysis.unit.UnitState; - import java.util.function.Function; /** - * @param Type of combined (with data) state of left formalism - * @param Type of combined (with data) state of right formalism + * @param Type of combined (with data) state of left formalism + * @param Type of combined (with data) state of right formalism * @param Type of data state - * @param Type of control state from left formalism - * @param Type of control state from right formalism - * @param Type of action from left formalism - * @param Type of action from right formalism - * @param Type of precision of left formalism - * @param Type of precision of right formalism - * @param Type of data precision (formalism independent) + * @param Type of control state from left formalism + * @param Type of control state from right formalism + * @param Type of action from left formalism + * @param Type of action from right formalism + * @param Type of precision of left formalism + * @param Type of precision of right formalism + * @param Type of data precision (formalism independent) */ @SuppressWarnings("java:S119") -public abstract class MultiAnalysis, MBlankState extends MultiState, MAction extends MultiAction> +public abstract class MultiAnalysis< + LState extends State, + RState extends State, + DataState extends State, + LControl extends State, + RControl extends State, + LAction extends Action, + RAction extends Action, + LPrec extends Prec, + RPrec extends Prec, + DataPrec extends Prec, + LControlPrec extends Prec, + RControlPrec extends Prec, + MState extends MultiState, + MBlankState extends MultiState, + MAction extends MultiAction> implements Analysis> { - protected final MultiAnalysisSide leftSide; - protected final MultiAnalysisSide rightSide; + protected final MultiAnalysisSide + leftSide; + protected final MultiAnalysisSide + rightSide; private final PartialOrd partialOrder; private final InitFunc> initFunc; private final TransFunc> transFunc; @@ -49,51 +62,55 @@ protected MultiAnalysis( Function defineNextSide, MultiAnalysisSide leftSide, MultiAnalysisSide rightSide, - InitFunc dataInitFunc - ) { + InitFunc dataInitFunc) { this.leftSide = leftSide; this.rightSide = rightSide; - this.partialOrder = new MultiPartialOrd<>( - leftSide.getAnalysis().getPartialOrd(), - leftSide.getCombineStates(), - rightSide.getAnalysis().getPartialOrd(), - rightSide.getCombineStates() - ); - this.initFunc = new MultiInitFunc<>( - this::createInitialState, - dataInitFunc, - leftSide.getExtractControlPrec(), - leftSide.getControlInitFunc(), - rightSide.getExtractControlPrec(), - rightSide.getControlInitFunc() - ); - this.transFunc = new MultiTransFunc<>( - defineNextSide::apply, - this::createState, - leftSide.getAnalysis().getTransFunc(), - leftSide.getCombineStates(), - leftSide.getExtractControlState(), - leftSide.getExtractDataState(), - rightSide.getAnalysis().getTransFunc(), - rightSide.getCombineStates(), - rightSide.getExtractControlState(), - rightSide.getExtractDataState() - ); + this.partialOrder = + new MultiPartialOrd<>( + leftSide.getAnalysis().getPartialOrd(), + leftSide.getCombineStates(), + rightSide.getAnalysis().getPartialOrd(), + rightSide.getCombineStates()); + this.initFunc = + new MultiInitFunc<>( + this::createInitialState, + dataInitFunc, + leftSide.getExtractControlPrec(), + leftSide.getControlInitFunc(), + rightSide.getExtractControlPrec(), + rightSide.getControlInitFunc()); + this.transFunc = + new MultiTransFunc<>( + defineNextSide::apply, + this::createState, + leftSide.getAnalysis().getTransFunc(), + leftSide.getCombineStates(), + leftSide.getExtractControlState(), + leftSide.getExtractDataState(), + rightSide.getAnalysis().getTransFunc(), + rightSide.getCombineStates(), + rightSide.getExtractControlState(), + rightSide.getExtractDataState()); } - public MultiAnalysisSide getLeftSide() { + public MultiAnalysisSide + getLeftSide() { return leftSide; } - public MultiAnalysisSide getRightSide() { + public MultiAnalysisSide + getRightSide() { return rightSide; } - protected abstract MState createInitialState(LControl leftState, RControl rightState, DataState dataState); + protected abstract MState createInitialState( + LControl leftState, RControl rightState, DataState dataState); - public abstract MState createState(LControl leftState, RControl rightState, DataState dataState, MultiSide sourceSide); + public abstract MState createState( + LControl leftState, RControl rightState, DataState dataState, MultiSide sourceSide); - public abstract MBlankState createControlState(LControl leftState, RControl rightState, MultiSide sourceSide); + public abstract MBlankState createControlState( + LControl leftState, RControl rightState, MultiSide sourceSide); public MBlankState createControlInitState(LControl leftState, RControl rightState) { return createControlState(leftState, rightState, null); @@ -113,5 +130,4 @@ public InitFunc> getInitFunc() { public TransFunc> getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiLts.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiLts.java index 993559f91c..271e7e8922 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiLts.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,7 +18,6 @@ import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.LTS; import hu.bme.mit.theta.analysis.State; - import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -27,21 +26,34 @@ import java.util.stream.Stream; @SuppressWarnings("java:S119") -public abstract class MultiLts, MAction extends MultiAction> +public abstract class MultiLts< + LState extends State, + RState extends State, + DataState extends State, + LBlank extends State, + RBlank extends State, + LAction extends Action, + RAction extends Action, + MState extends MultiState, + MAction extends MultiAction> implements LTS { private final Function defineNextSide; private final Side left; private final Side right; - protected MultiLts(Function defineNextSide, Side left, Side right) { + protected MultiLts( + Function defineNextSide, + Side left, + Side right) { this.defineNextSide = defineNextSide; this.left = left; this.right = right; } protected static - Side createSide(LTS lts, BiFunction combineStates) { + Side createSide( + LTS lts, BiFunction combineStates) { return new Side<>(lts, combineStates); } @@ -55,12 +67,24 @@ public Collection getEnabledActionsFor(MState state) { MultiSide nextSide = defineNextSide.apply(state); List enabledActions = new LinkedList<>(); if (nextSide != MultiSide.RIGHT) { - Stream actionStream = left.lts.getEnabledActionsFor(left.combineStates.apply(state.getLeftState(), state.getDataState())).stream(); + Stream actionStream = + left + .lts + .getEnabledActionsFor( + left.combineStates.apply( + state.getLeftState(), state.getDataState())) + .stream(); Stream multiActionStream = actionStream.map(this::wrapLeftAction); multiActionStream.forEach(enabledActions::add); } if (nextSide != MultiSide.LEFT) { - Stream actionStream = right.lts.getEnabledActionsFor(right.combineStates.apply(state.getRightState(), state.getDataState())).stream(); + Stream actionStream = + right + .lts + .getEnabledActionsFor( + right.combineStates.apply( + state.getRightState(), state.getDataState())) + .stream(); Stream multiActionStream = actionStream.map(this::wrapRightAction); multiActionStream.forEach(enabledActions::add); } @@ -71,8 +95,7 @@ public Function getDefineNextSide() { return defineNextSide; } - protected record Side( - LTS lts, BiFunction combineStates) { - } - + protected record Side< + S extends State, Data extends State, Blank extends State, A extends Action>( + LTS lts, BiFunction combineStates) {} } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiPrec.java index 9cb72d0c08..bc3d916447 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; @SuppressWarnings("java:S119") @@ -31,8 +30,6 @@ public Collection> getUsedVars() { @Override public String toString() { - return "MultiPrec{" + - "dataPrec=" + dataPrec + - '}'; + return "MultiPrec{" + "dataPrec=" + dataPrec + '}'; } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiSide.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiSide.java index f3c9010949..c16144a872 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiSide.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiSide.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,5 +16,7 @@ package hu.bme.mit.theta.analysis.multi; public enum MultiSide { - LEFT, RIGHT, BOTH + LEFT, + RIGHT, + BOTH } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiState.java index f7aa2d8336..96c559d520 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,30 +15,38 @@ */ package hu.bme.mit.theta.analysis.multi; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.common.base.Objects; import hu.bme.mit.theta.analysis.State; -import static com.google.common.base.Preconditions.checkArgument; - @SuppressWarnings("java:S119") -public abstract class MultiState implements State { +public abstract class MultiState< + LState extends State, RState extends State, DataState extends State> + implements State { private final LState leftState; private final RState rightState; private final DataState dataState; /** - * Shows if this state derived from an action that considered the left or the right state of the previous multi state. - * Can and will be null if this is an initial state. + * Shows if this state derived from an action that considered the left or the right state of the + * previous multi state. Can and will be null if this is an initial state. */ private final MultiSide sourceSide; /** - * Flag whether to include {@link hu.bme.mit.theta.analysis.multi.MultiState#sourceSide} in {@link hu.bme.mit.theta.analysis.multi.MultiState#equals(Object)} + * Flag whether to include {@link hu.bme.mit.theta.analysis.multi.MultiState#sourceSide} in + * {@link hu.bme.mit.theta.analysis.multi.MultiState#equals(Object)} */ private final boolean sourceMattersInEquality; - protected MultiState(LState ls, RState rs, DataState data, MultiSide sourceSide, boolean sourceMattersInEquality) { + protected MultiState( + LState ls, + RState rs, + DataState data, + MultiSide sourceSide, + boolean sourceMattersInEquality) { checkArgument(sourceSide != MultiSide.BOTH); leftState = ls; rightState = rs; @@ -65,10 +73,13 @@ public boolean equals(Object o) { return false; } MultiState that = (MultiState) o; - if ((sourceMattersInEquality || that.sourceMattersInEquality) && sourceSide != that.sourceSide) { + if ((sourceMattersInEquality || that.sourceMattersInEquality) + && sourceSide != that.sourceSide) { return false; } - return Objects.equal(leftState, that.leftState) && Objects.equal(rightState, that.rightState) && Objects.equal(dataState, that.dataState); + return Objects.equal(leftState, that.leftState) + && Objects.equal(rightState, that.rightState) + && Objects.equal(dataState, that.dataState); } @Override @@ -78,7 +89,6 @@ public int hashCode() { return Objects.hashCode(leftState, rightState, dataState); } - public LState getLeftState() { return leftState; } @@ -97,10 +107,13 @@ public boolean isSourceMatteringInEquality() { @Override public String toString() { - return "MultiState{" + - "leftState=" + leftState + - ", rightState=" + rightState + - ", dataState=" + dataState + - '}'; + return "MultiState{" + + "leftState=" + + leftState + + ", rightState=" + + rightState + + ", dataState=" + + dataState + + '}'; } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiStatePredicate.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiStatePredicate.java index d3a6c98f0c..be95f701f9 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiStatePredicate.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/MultiStatePredicate.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,11 +16,15 @@ package hu.bme.mit.theta.analysis.multi; import hu.bme.mit.theta.analysis.State; - import java.util.function.Predicate; @SuppressWarnings("java:S119") -public class MultiStatePredicate> implements Predicate { +public class MultiStatePredicate< + LState extends State, + RState extends State, + DataState extends State, + MState extends MultiState> + implements Predicate { private final Predicate dataStatePredicate; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/NextSideFunctions.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/NextSideFunctions.java index 9324f80d78..5d703b48a6 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/NextSideFunctions.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/NextSideFunctions.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,31 +22,49 @@ public final class NextSideFunctions { @FunctionalInterface - public interface NextSideFunction> { + public interface NextSideFunction< + L extends State, R extends State, D extends State, MState extends MultiState> { MultiSide defineNextSide(MState state); } - public static class Alternating> implements NextSideFunction { + public static class Alternating< + L extends State, + R extends State, + D extends State, + MState extends MultiState> + implements NextSideFunction { @Override public MultiSide defineNextSide(MState state) { return state.getSourceSide() == MultiSide.LEFT ? MultiSide.RIGHT : MultiSide.LEFT; } } - public static class Alternating3, MMState extends MultiState> implements NextSideFunction { + public static class Alternating3< + L extends State, + RL extends State, + RR extends State, + D extends State, + MState extends MultiState, + MMState extends MultiState> + implements NextSideFunction { @Override public MultiSide defineNextSide(MMState state) { - return state.getSourceSide() == MultiSide.RIGHT && state.getRightState().getSourceSide() == MultiSide.RIGHT + return state.getSourceSide() == MultiSide.RIGHT + && state.getRightState().getSourceSide() == MultiSide.RIGHT ? MultiSide.LEFT : MultiSide.RIGHT; } } - public static class Nondet> implements NextSideFunction { + public static class Nondet< + L extends State, + R extends State, + D extends State, + MState extends MultiState> + implements NextSideFunction { @Override public MultiSide defineNextSide(MState state) { return MultiSide.BOTH; } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/RefToMultiPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/RefToMultiPrec.java index 7c78d5219f..180c1c8a28 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/RefToMultiPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/RefToMultiPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,20 +20,30 @@ import hu.bme.mit.theta.analysis.expr.refinement.RefutationToPrec; @SuppressWarnings("java:S119") -public record RefToMultiPrec( +public record RefToMultiPrec< + LPrec extends Prec, + RPrec extends Prec, + DataPrec extends Prec, + R extends Refutation>( RefutationToPrec leftRefToPrec, RefutationToPrec rightRefToPrec, - RefutationToPrec dataRefToPrec -) + RefutationToPrec dataRefToPrec) implements RefutationToPrec, R> { @Override public MultiPrec toPrec(R refutation, int index) { - return new MultiPrec<>(leftRefToPrec.toPrec(refutation, index), rightRefToPrec().toPrec(refutation, index), dataRefToPrec().toPrec(refutation, index)); + return new MultiPrec<>( + leftRefToPrec.toPrec(refutation, index), + rightRefToPrec().toPrec(refutation, index), + dataRefToPrec().toPrec(refutation, index)); } @Override - public MultiPrec join(MultiPrec prec1, MultiPrec prec2) { - return new MultiPrec<>(leftRefToPrec.join(prec1.leftPrec(), prec2.leftPrec()), rightRefToPrec.join(prec1.rightPrec(), prec2.rightPrec()), dataRefToPrec.join(prec1.dataPrec(), prec2.dataPrec())); + public MultiPrec join( + MultiPrec prec1, MultiPrec prec2) { + return new MultiPrec<>( + leftRefToPrec.join(prec1.leftPrec(), prec2.leftPrec()), + rightRefToPrec.join(prec1.rightPrec(), prec2.rightPrec()), + dataRefToPrec.join(prec1.dataPrec(), prec2.dataPrec())); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResultPOJO.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResultPOJO.java index 9f872566fc..722cd35c95 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResultPOJO.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/MultiBuilderResultPOJO.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -24,20 +24,64 @@ @SuppressWarnings("java:S119") public class MultiBuilderResultPOJO< - LState extends State, RState extends State, DataState extends State, LBlank extends State, RBlank extends State, - LAction extends Action, RAction extends Action, - LPrec extends Prec, RPrec extends Prec, DataPrec extends Prec, LBlankPrec extends Prec, RBlankPrec extends Prec, - MState extends MultiState, MBlankState extends MultiState, MAction extends MultiAction, - MLts extends MultiLts> { - private final MultiAnalysisSide, MultiPrec> side; + LState extends State, + RState extends State, + DataState extends State, + LBlank extends State, + RBlank extends State, + LAction extends Action, + RAction extends Action, + LPrec extends Prec, + RPrec extends Prec, + DataPrec extends Prec, + LBlankPrec extends Prec, + RBlankPrec extends Prec, + MState extends MultiState, + MBlankState extends MultiState, + MAction extends MultiAction, + MLts extends + MultiLts< + LState, + RState, + DataState, + LBlank, + RBlank, + LAction, + RAction, + MState, + MAction>> { + private final MultiAnalysisSide< + MState, + DataState, + MBlankState, + MAction, + MultiPrec, + MultiPrec> + side; private final MLts lts; - public MultiBuilderResultPOJO(MultiAnalysisSide, MultiPrec> side, MLts lts) { + public MultiBuilderResultPOJO( + MultiAnalysisSide< + MState, + DataState, + MBlankState, + MAction, + MultiPrec, + MultiPrec> + side, + MLts lts) { this.side = side; this.lts = lts; } - public MultiAnalysisSide, MultiPrec> getSide() { + public MultiAnalysisSide< + MState, + DataState, + MBlankState, + MAction, + MultiPrec, + MultiPrec> + getSide() { return side; } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilderPair.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilderPair.java index f3f079b5a1..d128106a17 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilderPair.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/builder/stmt/StmtMultiBuilderPair.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.multi.builder.stmt; import hu.bme.mit.theta.analysis.InitFunc; @@ -32,22 +31,71 @@ import hu.bme.mit.theta.analysis.unit.UnitState; @SuppressWarnings("java:S119") -public final class StmtMultiBuilderPair { +public final class StmtMultiBuilderPair< + LState extends ExprState, + LBlank extends ExprState, + LAction extends StmtAction, + DataState extends ExprState, + LPrec extends Prec, + LBlankPrec extends Prec, + RState extends ExprState, + RBlank extends ExprState, + RAction extends StmtAction, + RPrec extends Prec, + RBlankPrec extends Prec> { private final MultiAnalysisSide leftSide; private final LTS leftLts; - private final MultiAnalysisSide rightSide; + private final MultiAnalysisSide + rightSide; private final LTS rightLts; - StmtMultiBuilderPair(MultiAnalysisSide leftSide, LTS leftLts, MultiAnalysisSide rightSide, LTS rightLts) { + StmtMultiBuilderPair( + MultiAnalysisSide leftSide, + LTS leftLts, + MultiAnalysisSide rightSide, + LTS rightLts) { this.leftSide = leftSide; this.leftLts = leftLts; this.rightSide = rightSide; this.rightLts = rightLts; } - public MultiBuilderResultPOJO, ExprMultiState, StmtMultiAction, StmtMultiLts> build(NextSideFunctions.NextSideFunction> nextSideFunction, InitFunc dataInitFunc) { - return MultiBuilderResultKt.multiBuilderResult(StmtMultiAnalysis.of(leftSide, rightSide, nextSideFunction::defineNextSide, dataInitFunc), StmtMultiLts.of(leftLts, (lbs, ds) -> leftSide.getCombineStates().invoke(lbs, ds), rightLts, (rbs, ds) -> rightSide.getCombineStates().invoke(rbs, ds), nextSideFunction::defineNextSide)); + public + MultiBuilderResultPOJO< + LState, + RState, + DataState, + LBlank, + RBlank, + LAction, + RAction, + LPrec, + RPrec, + DataPrec, + LBlankPrec, + RBlankPrec, + ExprMultiState, + ExprMultiState, + StmtMultiAction, + StmtMultiLts< + LState, RState, DataState, LBlank, RBlank, LAction, RAction>> + build( + NextSideFunctions.NextSideFunction< + LBlank, + RBlank, + DataState, + ExprMultiState> + nextSideFunction, + InitFunc dataInitFunc) { + return MultiBuilderResultKt.multiBuilderResult( + StmtMultiAnalysis.of( + leftSide, rightSide, nextSideFunction::defineNextSide, dataInitFunc), + StmtMultiLts.of( + leftLts, + (lbs, ds) -> leftSide.getCombineStates().invoke(lbs, ds), + rightLts, + (rbs, ds) -> rightSide.getCombineStates().invoke(rbs, ds), + nextSideFunction::defineNextSide)); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/ExprMultiState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/ExprMultiState.java index 7662cd3b26..8d18323373 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/ExprMultiState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/ExprMultiState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,33 +15,41 @@ */ package hu.bme.mit.theta.analysis.multi.stmt; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.analysis.multi.MultiSide; import hu.bme.mit.theta.analysis.multi.MultiState; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - -public final class ExprMultiState extends MultiState implements ExprState { +public final class ExprMultiState + extends MultiState implements ExprState { - private ExprMultiState(L ls, R rs, D data, MultiSide sourceSide, boolean sourceMattersInEquality) { + private ExprMultiState( + L ls, R rs, D data, MultiSide sourceSide, boolean sourceMattersInEquality) { super(ls, rs, data, sourceSide, sourceMattersInEquality); } - public static ExprMultiState create(L ls, R rs, D d, MultiSide sourceSide, boolean sourceMattersInEquality) { + public static + ExprMultiState create( + L ls, R rs, D d, MultiSide sourceSide, boolean sourceMattersInEquality) { return new ExprMultiState<>(ls, rs, d, sourceSide, sourceMattersInEquality); } - public static ExprMultiState create(L ls, R rs, D d, MultiSide sourceSide) { + public static + ExprMultiState create(L ls, R rs, D d, MultiSide sourceSide) { return create(ls, rs, d, sourceSide, true); } - public static ExprMultiState createInitial(L ls, R rs, D d, boolean sourceMattersInEquality) { + public static + ExprMultiState createInitial( + L ls, R rs, D d, boolean sourceMattersInEquality) { return create(ls, rs, d, null, sourceMattersInEquality); } - public static ExprMultiState createInitial(L ls, R rs, D d) { + public static + ExprMultiState createInitial(L ls, R rs, D d) { return createInitial(ls, rs, d, true); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAction.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAction.java index 82b9ff1c11..6e84ad32d3 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAction.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,29 +15,33 @@ */ package hu.bme.mit.theta.analysis.multi.stmt; +import static com.google.common.base.Preconditions.checkArgument; + import hu.bme.mit.theta.analysis.expr.StmtAction; import hu.bme.mit.theta.analysis.multi.MultiAction; import hu.bme.mit.theta.core.stmt.Stmt; - import java.util.List; -import static com.google.common.base.Preconditions.checkArgument; - -public final class StmtMultiAction extends StmtAction implements MultiAction { +public final class StmtMultiAction extends StmtAction + implements MultiAction { private final L leftAction; private final R rightAction; private StmtMultiAction(L lAction, R rAction) { - checkArgument((lAction != null && rAction == null) || (rAction != null && lAction == null), "One of the actions should be null while the other not"); + checkArgument( + (lAction != null && rAction == null) || (rAction != null && lAction == null), + "One of the actions should be null while the other not"); leftAction = lAction; rightAction = rAction; } - public static StmtMultiAction ofLeftStmtAction(L action) { + public static + StmtMultiAction ofLeftStmtAction(L action) { return new StmtMultiAction<>(action, null); } - public static StmtMultiAction ofRightStmtAction(R action) { + public static + StmtMultiAction ofRightStmtAction(R action) { return new StmtMultiAction<>(null, action); } @@ -47,10 +51,12 @@ public StmtAction getAction() { @Override public String toString() { - return "ExprMultiAction{" + - "leftAction=" + leftAction + - ", rightAction=" + rightAction + - '}'; + return "ExprMultiAction{" + + "leftAction=" + + leftAction + + ", rightAction=" + + rightAction + + '}'; } @Override diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAnalysis.java index 89739de788..046f3bf1bf 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -23,42 +23,100 @@ import hu.bme.mit.theta.analysis.multi.MultiAnalysisSide; import hu.bme.mit.theta.analysis.multi.MultiSide; import hu.bme.mit.theta.analysis.unit.UnitState; - import java.util.function.Function; @SuppressWarnings("java:S119") -public final class StmtMultiAnalysis - extends MultiAnalysis, ExprMultiState, StmtMultiAction> { +public final class StmtMultiAnalysis< + LState extends ExprState, + RState extends ExprState, + DataState extends ExprState, + LBlank extends ExprState, + RBlank extends ExprState, + LAction extends StmtAction, + RAction extends StmtAction, + LPrec extends Prec, + RPrec extends Prec, + DataPrec extends Prec, + LBlankPrec extends Prec, + RBlankPrec extends Prec> + extends MultiAnalysis< + LState, + RState, + DataState, + LBlank, + RBlank, + LAction, + RAction, + LPrec, + RPrec, + DataPrec, + LBlankPrec, + RBlankPrec, + ExprMultiState, + ExprMultiState, + StmtMultiAction> { - private StmtMultiAnalysis(Function, MultiSide> defineNextSide, MultiAnalysisSide leftSide, MultiAnalysisSide rightSide, InitFunc dataInitFunc) { + private StmtMultiAnalysis( + Function, MultiSide> defineNextSide, + MultiAnalysisSide leftSide, + MultiAnalysisSide rightSide, + InitFunc dataInitFunc) { super(defineNextSide, leftSide, rightSide, dataInitFunc); } - public static - StmtMultiAnalysis - of(MultiAnalysisSide leftSide, MultiAnalysisSide rightSide, - Function, MultiSide> defineNextSide, - InitFunc dataInitFunc) { + public static < + LState extends ExprState, + RState extends ExprState, + DataState extends ExprState, + LBlank extends ExprState, + RBlank extends ExprState, + LAction extends StmtAction, + RAction extends StmtAction, + LPrec extends Prec, + RPrec extends Prec, + DataPrec extends Prec, + LBlankPrec extends Prec, + RBlankPrec extends Prec> + StmtMultiAnalysis< + LState, + RState, + DataState, + LBlank, + RBlank, + LAction, + RAction, + LPrec, + RPrec, + DataPrec, + LBlankPrec, + RBlankPrec> + of( + MultiAnalysisSide + leftSide, + MultiAnalysisSide + rightSide, + Function, MultiSide> + defineNextSide, + InitFunc dataInitFunc) { return new StmtMultiAnalysis<>(defineNextSide, leftSide, rightSide, dataInitFunc); } @Override - public ExprMultiState createInitialState(LBlank leftState, RBlank rightState, DataState dataState) { + public ExprMultiState createInitialState( + LBlank leftState, RBlank rightState, DataState dataState) { return ExprMultiState.createInitial(leftState, rightState, dataState); } @Override - public ExprMultiState createState(LBlank leftState, RBlank rightState, DataState dataState, MultiSide sourceSide) { + public ExprMultiState createState( + LBlank leftState, RBlank rightState, DataState dataState, MultiSide sourceSide) { return ExprMultiState.create(leftState, rightState, dataState, sourceSide, true); } @Override - public ExprMultiState createControlState(LBlank leftState, RBlank rightState, MultiSide sourceSide) { - return ExprMultiState.create(leftState, rightState, UnitState.getInstance(), sourceSide, true); + public ExprMultiState createControlState( + LBlank leftState, RBlank rightState, MultiSide sourceSide) { + return ExprMultiState.create( + leftState, rightState, UnitState.getInstance(), sourceSide, true); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiLts.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiLts.java index 57606fe4de..2318b696cd 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiLts.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/multi/stmt/StmtMultiLts.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,24 +20,54 @@ import hu.bme.mit.theta.analysis.expr.StmtAction; import hu.bme.mit.theta.analysis.multi.MultiLts; import hu.bme.mit.theta.analysis.multi.MultiSide; - import java.util.function.BiFunction; import java.util.function.Function; @SuppressWarnings("java:S119") -public final class StmtMultiLts - extends MultiLts, StmtMultiAction> { +public final class StmtMultiLts< + LState extends ExprState, + RState extends ExprState, + DataState extends ExprState, + LBlank extends ExprState, + RBlank extends ExprState, + LAction extends StmtAction, + RAction extends StmtAction> + extends MultiLts< + LState, + RState, + DataState, + LBlank, + RBlank, + LAction, + RAction, + ExprMultiState, + StmtMultiAction> { - private StmtMultiLts(Function, MultiSide> defineNextSide, Side left, Side right) { + private StmtMultiLts( + Function, MultiSide> defineNextSide, + Side left, + Side right) { super(defineNextSide, left, right); } - public static - StmtMultiLts of( - LTS leftLts, BiFunction wrapLeftState, - LTS rightLts, BiFunction wrapRightState, - Function, MultiSide> defineNextSide) { - return new StmtMultiLts<>(defineNextSide, createSide(leftLts, wrapLeftState), createSide(rightLts, wrapRightState)); + public static < + LState extends ExprState, + RState extends ExprState, + DataState extends ExprState, + LBlank extends ExprState, + RBlank extends ExprState, + LAction extends StmtAction, + RAction extends StmtAction> + StmtMultiLts of( + LTS leftLts, + BiFunction wrapLeftState, + LTS rightLts, + BiFunction wrapRightState, + Function, MultiSide> defineNextSide) { + return new StmtMultiLts<>( + defineNextSide, + createSide(leftLts, wrapLeftState), + createSide(rightLts, wrapRightState)); } @Override diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/package-info.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/package-info.java index 858d236fba..0171575815 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/package-info.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -19,5 +19,4 @@ * * @see hu.bme.mit.theta.analysis.Analysis */ - -package hu.bme.mit.theta.analysis; \ No newline at end of file +package hu.bme.mit.theta.analysis; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ExprSplitters.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ExprSplitters.java index 7542fdad5e..897953e22e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ExprSplitters.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ExprSplitters.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,28 +15,20 @@ */ package hu.bme.mit.theta.analysis.pred; -import java.util.Collection; -import java.util.Collections; -import java.util.function.Function; - import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; +import java.util.Collection; +import java.util.Collections; +import java.util.function.Function; -/** - * Strategies for splitting an expression into a collection of expressions. - */ +/** Strategies for splitting an expression into a collection of expressions. */ public final class ExprSplitters { - /** - * Interface for splitting an expression into a collection of expressions. - */ - public interface ExprSplitter extends Function, Collection>> { - - } + /** Interface for splitting an expression into a collection of expressions. */ + public interface ExprSplitter extends Function, Collection>> {} - private ExprSplitters() { - } + private ExprSplitters() {} /** * Get the strategy that keeps the expression as a whole. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ItpRefToPredPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ItpRefToPredPrec.java index 700791bec0..9b9ebca4a7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ItpRefToPredPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/ItpRefToPredPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,18 +17,15 @@ import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collection; - import hu.bme.mit.theta.analysis.expr.refinement.ItpRefutation; import hu.bme.mit.theta.analysis.expr.refinement.RefutationToPrec; import hu.bme.mit.theta.analysis.pred.ExprSplitters.ExprSplitter; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; +import java.util.Collection; -/** - * Transformer from interpolant refutation to predicate precision. - */ +/** Transformer from interpolant refutation to predicate precision. */ public class ItpRefToPredPrec implements RefutationToPrec { private final ExprSplitter exprSplitter; @@ -54,7 +51,9 @@ public PredPrec join(final PredPrec prec1, final PredPrec prec2) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).aligned().add(exprSplitter) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .aligned() + .add(exprSplitter) .toString(); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAbstractors.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAbstractors.java index 7fe21c627a..930df6bd1d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAbstractors.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAbstractors.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,13 @@ */ package hu.bme.mit.theta.analysis.pred; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Iff; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.ConstDecl; @@ -29,7 +36,6 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -39,45 +45,36 @@ import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Iff; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - -/** - * Strategies for performing predicate abstraction over an expression. - */ +/** Strategies for performing predicate abstraction over an expression. */ public class PredAbstractors { - private PredAbstractors() { - } + private PredAbstractors() {} - /** - * Interface for performing predicate abstraction over an expression. - */ + /** Interface for performing predicate abstraction over an expression. */ public interface PredAbstractor { /** * Create predicate states for a given expression with a given precision. * - * @param expr Expression to be abstracted + * @param expr Expression to be abstracted * @param exprIndexing Unfold indexing of the expression - * @param prec Precision + * @param prec Precision * @param precIndexing Unfold indexing of the precision * @return */ - Collection createStatesForExpr(final Expr expr, - final VarIndexing exprIndexing, - final PredPrec prec, final VarIndexing precIndexing); + Collection createStatesForExpr( + final Expr expr, + final VarIndexing exprIndexing, + final PredPrec prec, + final VarIndexing precIndexing); - default Collection createStatesForExpr(final Expr expr, - final VarIndexing exprIndexing, - final PredPrec prec, - final VarIndexing precIndexing, - final PredState state, - final ExprAction action) { + default Collection createStatesForExpr( + final Expr expr, + final VarIndexing exprIndexing, + final PredPrec prec, + final VarIndexing precIndexing, + final PredState state, + final ExprAction action) { return createStatesForExpr(expr, exprIndexing, prec, precIndexing); } } @@ -129,9 +126,11 @@ public BooleanAbstractor(final Solver solver, final boolean split) { } @Override - public Collection createStatesForExpr(final Expr expr, - final VarIndexing exprIndexing, - final PredPrec prec, final VarIndexing precIndexing) { + public Collection createStatesForExpr( + final Expr expr, + final VarIndexing exprIndexing, + final PredPrec prec, + final VarIndexing precIndexing) { checkNotNull(expr); checkNotNull(exprIndexing); checkNotNull(prec); @@ -147,7 +146,9 @@ public Collection createStatesForExpr(final Expr expr, solver.add(PathUtils.unfold(expr, exprIndexing)); for (int i = 0; i < preds.size(); ++i) { solver.add( - Iff(actLits.get(i).getRef(), PathUtils.unfold(preds.get(i), precIndexing))); + Iff( + actLits.get(i).getRef(), + PathUtils.unfold(preds.get(i), precIndexing))); } while (solver.check().isSat()) { final Valuation model = solver.getModel(); @@ -173,8 +174,8 @@ public Collection createStatesForExpr(final Expr expr, } } if (!split && states.size() > 1) { - final Expr pred = Or( - states.stream().map(PredState::toExpr).collect(Collectors.toList())); + final Expr pred = + Or(states.stream().map(PredState::toExpr).collect(Collectors.toList())); return Collections.singleton(PredState.of(pred)); } else { return states; @@ -197,9 +198,11 @@ public CartesianAbstractor(final Solver solver) { } @Override - public Collection createStatesForExpr(final Expr expr, - final VarIndexing exprIndexing, - final PredPrec prec, final VarIndexing precIndexing) { + public Collection createStatesForExpr( + final Expr expr, + final VarIndexing exprIndexing, + final PredPrec prec, + final VarIndexing precIndexing) { final List> newStatePreds = new ArrayList<>(); try (WithPushPop wp = new WithPushPop(solver)) { @@ -221,8 +224,8 @@ public Collection createStatesForExpr(final Expr expr, negEntailed = solver.check().isUnsat(); } - assert !(ponEntailed - && negEntailed) : "Ponated and negated predicates are both entailed."; + assert !(ponEntailed && negEntailed) + : "Ponated and negated predicates are both entailed."; if (ponEntailed) { newStatePreds.add(pred); @@ -237,19 +240,25 @@ public Collection createStatesForExpr(final Expr expr, } @Override - public Collection createStatesForExpr(final Expr expr, - final VarIndexing exprIndexing, - final PredPrec prec, - final VarIndexing precIndexing, - final PredState state, - final ExprAction action) { + public Collection createStatesForExpr( + final Expr expr, + final VarIndexing exprIndexing, + final PredPrec prec, + final VarIndexing precIndexing, + final PredState state, + final ExprAction action) { var actionExpr = action.toExpr(); if (actionExpr.equals(True())) { - var filteredPreds = state.getPreds().stream().filter(p -> { - var vars = ExprUtils.getVars(p); - var indexing = action.nextIndexing(); - return vars.stream().allMatch(v -> indexing.get(v) == 0); - }).collect(Collectors.toList()); + var filteredPreds = + state.getPreds().stream() + .filter( + p -> { + var vars = ExprUtils.getVars(p); + var indexing = action.nextIndexing(); + return vars.stream() + .allMatch(v -> indexing.get(v) == 0); + }) + .collect(Collectors.toList()); return Collections.singleton(PredState.of(filteredPreds)); } return createStatesForExpr(expr, exprIndexing, prec, precIndexing); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAnalysis.java index b31a26820b..3edb613c53 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -31,16 +31,19 @@ public final class PredAnalysis implements Analysis initFunc; private final TransFunc transFunc; - private PredAnalysis(final Solver solver, final PredAbstractor predAbstractor, - final Expr initExpr) { + private PredAnalysis( + final Solver solver, + final PredAbstractor predAbstractor, + final Expr initExpr) { partialOrd = PredOrd.create(solver); initFunc = PredInitFunc.create(predAbstractor, initExpr); transFunc = PredTransFunc.create(predAbstractor); } - public static PredAnalysis create(final Solver solver, - final PredAbstractor predAbstractor, - final Expr initExpr) { + public static PredAnalysis create( + final Solver solver, + final PredAbstractor predAbstractor, + final Expr initExpr) { return new PredAnalysis(solver, predAbstractor, initExpr); } @@ -60,5 +63,4 @@ public InitFunc getInitFunc() { public TransFunc getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredInitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredInitFunc.java index 36cd947ca2..157d6a28fa 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredInitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredInitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,17 +15,16 @@ */ package hu.bme.mit.theta.analysis.pred; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.pred.PredAbstractors.PredAbstractor; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; - import java.util.Collection; import java.util.Collections; -import static com.google.common.base.Preconditions.checkNotNull; - public final class PredInitFunc implements InitFunc { private final Expr initExpr; @@ -36,18 +35,20 @@ private PredInitFunc(final PredAbstractor predAbstractor, final Expr i this.predAbstractor = checkNotNull(predAbstractor); } - public static PredInitFunc create(final PredAbstractor predAbstractor, - final Expr expr) { + public static PredInitFunc create( + final PredAbstractor predAbstractor, final Expr expr) { return new PredInitFunc(predAbstractor, expr); } @Override public Collection getInitStates(final PredPrec prec) { checkNotNull(prec); - final Collection initStates = predAbstractor.createStatesForExpr(initExpr, - VarIndexingFactory.indexing(0), prec, - VarIndexingFactory.indexing(0)); + final Collection initStates = + predAbstractor.createStatesForExpr( + initExpr, + VarIndexingFactory.indexing(0), + prec, + VarIndexingFactory.indexing(0)); return initStates.isEmpty() ? Collections.singleton(PredState.bottom()) : initStates; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredOrd.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredOrd.java index 96e8aa9dc9..20a4a96cfa 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredOrd.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredOrd.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -43,5 +43,4 @@ public boolean isLeq(final PredState state1, final PredState state2) { return solver.check().isUnsat(); } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredPrec.java index c7bce9add9..e6f1296762 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,6 +15,10 @@ */ package hu.bme.mit.theta.analysis.pred; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; + import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import hu.bme.mit.theta.analysis.Prec; @@ -25,20 +29,13 @@ import hu.bme.mit.theta.core.type.booltype.BoolLitExpr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; - -/** - * Represents an immutable, simple predicate precision that is a set of predicates. - */ +/** Represents an immutable, simple predicate precision that is a set of predicates. */ public final class PredPrec implements Prec { private final Map, Expr> predToNegMap; @@ -86,8 +83,11 @@ public Expr negate(final Expr pred) { public PredPrec join(final PredPrec other) { checkNotNull(other); - final Collection> joinedPreds = ImmutableSet.>builder() - .addAll(this.predToNegMap.keySet()).addAll(other.predToNegMap.keySet()).build(); + final Collection> joinedPreds = + ImmutableSet.>builder() + .addAll(this.predToNegMap.keySet()) + .addAll(other.predToNegMap.keySet()) + .build(); // If no new predicate was added, return same instance (immutable) if (joinedPreds.size() == this.predToNegMap.size()) { return this; @@ -100,7 +100,8 @@ public PredPrec join(final PredPrec other) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).addAll(predToNegMap.keySet()) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .addAll(predToNegMap.keySet()) .toString(); } @@ -123,8 +124,12 @@ public int hashCode() { @Override public Collection> getUsedVars() { - return predToNegMap.keySet().stream().map(ExprUtils::getVars).reduce( - (vars1, vars2) -> Streams.concat(vars1.stream(), vars2.stream()) - .collect(Collectors.toSet())).orElse(Set.of()); + return predToNegMap.keySet().stream() + .map(ExprUtils::getVars) + .reduce( + (vars1, vars2) -> + Streams.concat(vars1.stream(), vars2.stream()) + .collect(Collectors.toSet())) + .orElse(Set.of()); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredState.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredState.java index 2724128235..7bdf5c8be7 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredState.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredState.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,20 +15,19 @@ */ package hu.bme.mit.theta.analysis.pred; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.common.Utils.singleElementOf; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import com.google.common.collect.ImmutableSet; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.Set; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.common.Utils.singleElementOf; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public final class PredState implements ExprState { private static final int HASH_SEED = 7621; @@ -66,20 +65,25 @@ public static PredState of(final Expr pred1, final Expr pred return new PredState(ImmutableSet.of(pred1, pred2)); } - public static PredState of(final Expr pred1, final Expr pred2, - final Expr pred3) { + public static PredState of( + final Expr pred1, final Expr pred2, final Expr pred3) { return new PredState(ImmutableSet.of(pred1, pred2, pred3)); } - public static PredState of(final Expr pred1, final Expr pred2, - final Expr pred3, - final Expr pred4) { + public static PredState of( + final Expr pred1, + final Expr pred2, + final Expr pred3, + final Expr pred4) { return new PredState(ImmutableSet.of(pred1, pred2, pred3, pred4)); } - public static PredState of(final Expr pred1, final Expr pred2, - final Expr pred3, - final Expr pred4, final Expr pred5) { + public static PredState of( + final Expr pred1, + final Expr pred2, + final Expr pred3, + final Expr pred4, + final Expr pred5) { return new PredState(ImmutableSet.of(pred1, pred2, pred3, pred4, pred5)); } @@ -135,8 +139,9 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(getClass().getSimpleName()).aligned().addAll(preds) + return Utils.lispStringBuilder(getClass().getSimpleName()) + .aligned() + .addAll(preds) .toString(); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredStmtOptimizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredStmtOptimizer.java index f667052a67..245a94173f 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredStmtOptimizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredStmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -16,14 +16,13 @@ package hu.bme.mit.theta.analysis.pred; import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; -import hu.bme.mit.theta.core.utils.StmtSimplifier; import hu.bme.mit.theta.core.model.ImmutableValuation; import hu.bme.mit.theta.core.stmt.Stmt; +import hu.bme.mit.theta.core.utils.StmtSimplifier; public class PredStmtOptimizer implements StmtOptimizer { - private PredStmtOptimizer() { - } + private PredStmtOptimizer() {} private static class LazyHolder { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredTransFunc.java index 6f3d2abd65..eef7025070 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/pred/PredTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,19 +15,18 @@ */ package hu.bme.mit.theta.analysis.pred; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expr.ExprAction; import hu.bme.mit.theta.analysis.pred.PredAbstractors.PredAbstractor; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; - import java.util.Collection; import java.util.Collections; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - -public final class PredTransFunc implements - TransFunc { +public final class PredTransFunc + implements TransFunc { private final PredAbstractor predAbstractor; @@ -41,17 +40,20 @@ public static PredTransFunc create( } @Override - public Collection getSuccStates(final PredState state, - final ExprAction action, - final PredPrec prec) { + public Collection getSuccStates( + final PredState state, final ExprAction action, final PredPrec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); - final Collection succStates = predAbstractor.createStatesForExpr( - And(state.toExpr(), action.toExpr()), VarIndexingFactory.indexing(0), prec, - action.nextIndexing(), state, action); + final Collection succStates = + predAbstractor.createStatesForExpr( + And(state.toExpr(), action.toExpr()), + VarIndexingFactory.indexing(0), + prec, + action.nextIndexing(), + state, + action); return succStates.isEmpty() ? Collections.singleton(PredState.bottom()) : succStates; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/DefaultPreStrengtheningOperator.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/DefaultPreStrengtheningOperator.java index 564a0d24dc..3b178e2ac9 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/DefaultPreStrengtheningOperator.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/DefaultPreStrengtheningOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,15 +15,14 @@ */ package hu.bme.mit.theta.analysis.prod2; -import hu.bme.mit.theta.analysis.State; - import static com.google.common.base.Preconditions.checkNotNull; -public final class DefaultPreStrengtheningOperator implements - PreStrengtheningOperator { +import hu.bme.mit.theta.analysis.State; - private DefaultPreStrengtheningOperator() { - } +public final class DefaultPreStrengtheningOperator + implements PreStrengtheningOperator { + + private DefaultPreStrengtheningOperator() {} public static PreStrengtheningOperator create() { return new DefaultPreStrengtheningOperator<>(); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/PreStrengtheningOperator.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/PreStrengtheningOperator.java index 1dddd033a1..b14a3f6a9d 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/PreStrengtheningOperator.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/PreStrengtheningOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,5 +22,4 @@ public interface PreStrengtheningOperator { S1 strengthenState1(final Prod2State state); S2 strengthenState2(final Prod2State state); - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Analysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Analysis.java index ccd5091f8a..f71e77bac2 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Analysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Analysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,38 +25,66 @@ import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; -public final class Prod2Analysis +public final class Prod2Analysis< + S1 extends State, + S2 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec> implements Analysis, A, Prod2Prec> { private final PartialOrd> partialOrd; private final InitFunc, Prod2Prec> initFunc; private final TransFunc, A, Prod2Prec> transFunc; - private Prod2Analysis(final Analysis analysis1, - final Analysis analysis2, - final PreStrengtheningOperator preStrengtheningOperator, - final StrengtheningOperator strenghteningOperator) { + private Prod2Analysis( + final Analysis analysis1, + final Analysis analysis2, + final PreStrengtheningOperator preStrengtheningOperator, + final StrengtheningOperator strenghteningOperator) { checkNotNull(analysis1); checkNotNull(analysis2); partialOrd = Prod2Ord.create(analysis1.getPartialOrd(), analysis2.getPartialOrd()); - initFunc = Prod2InitFunc.create(analysis1.getInitFunc(), analysis2.getInitFunc(), - strenghteningOperator); - transFunc = Prod2TransFunc.create(analysis1.getTransFunc(), analysis2.getTransFunc(), - preStrengtheningOperator, strenghteningOperator); + initFunc = + Prod2InitFunc.create( + analysis1.getInitFunc(), analysis2.getInitFunc(), strenghteningOperator); + transFunc = + Prod2TransFunc.create( + analysis1.getTransFunc(), + analysis2.getTransFunc(), + preStrengtheningOperator, + strenghteningOperator); } - public static Prod2Analysis create( - final Analysis analysis1, final Analysis analysis2) { - return create(analysis1, analysis2, DefaultPreStrengtheningOperator.create(), + public static < + S1 extends State, + S2 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec> + Prod2Analysis create( + final Analysis analysis1, + final Analysis analysis2) { + return create( + analysis1, + analysis2, + DefaultPreStrengtheningOperator.create(), (states, prec) -> states); } - public static Prod2Analysis create( - final Analysis analysis1, final Analysis analysis2, - final PreStrengtheningOperator preStrengtheningOperator, - final StrengtheningOperator strenghteningOperator) { - return new Prod2Analysis<>(analysis1, analysis2, preStrengtheningOperator, - strenghteningOperator); + public static < + S1 extends State, + S2 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec> + Prod2Analysis create( + final Analysis analysis1, + final Analysis analysis2, + final PreStrengtheningOperator preStrengtheningOperator, + final StrengtheningOperator strenghteningOperator) { + return new Prod2Analysis<>( + analysis1, analysis2, preStrengtheningOperator, strenghteningOperator); } @Override @@ -73,5 +101,4 @@ public InitFunc, Prod2Prec> getInitFunc() { public TransFunc, A, Prod2Prec> getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2InitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2InitFunc.java index 5d3c42b231..af4598460e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2InitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2InitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,35 +18,40 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; +import java.util.Collection; +import java.util.Optional; -public final class Prod2InitFunc +public final class Prod2InitFunc< + S1 extends State, S2 extends State, P1 extends Prec, P2 extends Prec> implements InitFunc, Prod2Prec> { private final InitFunc initFunc1; private final InitFunc initFunc2; private final StrengtheningOperator strenghteningOperator; - private Prod2InitFunc(final InitFunc initFunc1, final InitFunc initFunc2, - final StrengtheningOperator strenghteningOperator) { + private Prod2InitFunc( + final InitFunc initFunc1, + final InitFunc initFunc2, + final StrengtheningOperator strenghteningOperator) { this.initFunc1 = checkNotNull(initFunc1); this.initFunc2 = checkNotNull(initFunc2); this.strenghteningOperator = checkNotNull(strenghteningOperator); } - public static Prod2InitFunc create( - final InitFunc initFunc1, final InitFunc initFunc2) { + public static + Prod2InitFunc create( + final InitFunc initFunc1, final InitFunc initFunc2) { return create(initFunc1, initFunc2, (states, prec) -> states); } - public static Prod2InitFunc create( - final InitFunc initFunc1, final InitFunc initFunc2, - final StrengtheningOperator strenghteningOperator) { + public static + Prod2InitFunc create( + final InitFunc initFunc1, + final InitFunc initFunc2, + final StrengtheningOperator strenghteningOperator) { return new Prod2InitFunc<>(initFunc1, initFunc2, strenghteningOperator); } @@ -54,8 +59,8 @@ public static > getInitStates(final Prod2Prec prec) { checkNotNull(prec); final Collection initStates1 = initFunc1.getInitStates(prec.getPrec1()); - final Optional optBottom1 = initStates1.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom1 = + initStates1.stream().filter(State::isBottom).findAny(); if (optBottom1.isPresent()) { final S1 bottom1 = optBottom1.get(); @@ -63,18 +68,17 @@ public Collection> getInitStates(final Prod2Prec prec } final Collection initStates2 = initFunc2.getInitStates(prec.getPrec2()); - final Optional optBottom2 = initStates2.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom2 = + initStates2.stream().filter(State::isBottom).findAny(); if (optBottom2.isPresent()) { final S2 bottom2 = optBottom2.get(); return singleton(Prod2State.bottom2(bottom2)); } - final Collection> initStates = Prod2State.cartesian(initStates1, - initStates2); + final Collection> initStates = + Prod2State.cartesian(initStates1, initStates2); return strenghteningOperator.strengthen(initStates, prec); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Ord.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Ord.java index cd57466d28..41138f3b5c 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Ord.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Ord.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,8 +20,8 @@ import hu.bme.mit.theta.analysis.PartialOrd; import hu.bme.mit.theta.analysis.State; -public final class Prod2Ord implements - PartialOrd> { +public final class Prod2Ord + implements PartialOrd> { private final PartialOrd partialOrd1; private final PartialOrd partialOrd2; @@ -32,8 +32,7 @@ private Prod2Ord(final PartialOrd partialOrd1, final PartialOrd partialO } public static Prod2Ord create( - final PartialOrd partialOrd1, - final PartialOrd partialOrd2) { + final PartialOrd partialOrd1, final PartialOrd partialOrd2) { return new Prod2Ord<>(partialOrd1, partialOrd2); } @@ -44,9 +43,8 @@ public boolean isLeq(final Prod2State state1, final Prod2State s } else if (state2.isBottom()) { return false; } else { - return partialOrd1.isLeq(state1.getState1(), state2.getState1()) && partialOrd2.isLeq( - state1.getState2(), state2.getState2()); + return partialOrd1.isLeq(state1.getState1(), state2.getState1()) + && partialOrd2.isLeq(state1.getState2(), state2.getState2()); } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Prec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Prec.java index dda0338e4b..8471aa2ac8 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Prec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2Prec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,16 +15,15 @@ */ package hu.bme.mit.theta.analysis.prod2; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.Streams; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - public final class Prod2Prec implements Prec { private static final int HASH_SEED = 2267; @@ -38,8 +37,8 @@ private Prod2Prec(final P1 prec1, final P2 prec2) { this.prec2 = checkNotNull(prec2); } - public static Prod2Prec of(final P1 prec1, - final P2 prec2) { + public static Prod2Prec of( + final P1 prec1, final P2 prec2) { return new Prod2Prec<>(prec1, prec2); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2State.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2State.java index 4c82f6dbb3..4ea45ad59a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2State.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2State.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,26 +15,24 @@ */ package hu.bme.mit.theta.analysis.prod2; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.ArrayList; import java.util.Collection; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - public abstract class Prod2State implements ExprState { - private Prod2State() { - } + private Prod2State() {} - public static Prod2State of(final S1 state1, - final S2 state2) { + public static Prod2State of( + final S1 state1, final S2 state2) { checkNotNull(state1); checkNotNull(state2); if (state1.isBottom()) { @@ -54,8 +52,8 @@ public static Prod2State bottom2(fi return new Bottom2<>(state); } - private static Prod2State product(final S1 state1, - final S2 state2) { + private static Prod2State product( + final S1 state1, final S2 state2) { return new Product<>(state1, state2); } @@ -82,8 +80,8 @@ public static Collection public abstract Prod2State with2(final S state); - private static final class Product extends - Prod2State { + private static final class Product + extends Prod2State { private static final int HASH_SEED = 7879; private volatile int hashCode = 0; @@ -180,19 +178,21 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(Prod2State.class.getSimpleName()).body().add(state1) - .add(state2).toString(); + return Utils.lispStringBuilder(Prod2State.class.getSimpleName()) + .body() + .add(state1) + .add(state2) + .toString(); } } - private static abstract class Bottom extends - Prod2State { + private abstract static class Bottom + extends Prod2State { private static final int HASH_SEED = 2879; private volatile int hashCode = 0; - private Bottom() { - } + private Bottom() {} public abstract int getIndex(); @@ -232,8 +232,8 @@ public final boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Bottom that = (Bottom) obj; - return this.getIndex() == that.getIndex() && this.getState() - .equals(that.getState()); + return this.getIndex() == that.getIndex() + && this.getState().equals(that.getState()); } else { return false; } @@ -241,8 +241,10 @@ public final boolean equals(final Object obj) { @Override public final String toString() { - return Utils.lispStringBuilder(Prod2State.class.getSimpleName()).add(getIndex()) - .add(getState()).toString(); + return Utils.lispStringBuilder(Prod2State.class.getSimpleName()) + .add(getIndex()) + .add(getState()) + .toString(); } } @@ -353,5 +355,4 @@ public Prod2State with2(final S state) { return (Prod2State) this; } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2StmtOptimizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2StmtOptimizer.java index 002b3af759..f8b96a6a2b 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2StmtOptimizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2StmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -20,27 +20,28 @@ import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; import hu.bme.mit.theta.core.stmt.Stmt; -public class Prod2StmtOptimizer implements - StmtOptimizer> { +public class Prod2StmtOptimizer + implements StmtOptimizer> { private final StmtOptimizer stmtOptimizer1; private final StmtOptimizer stmtOptimizer2; - private Prod2StmtOptimizer(final StmtOptimizer stmtOptimizer1, - final StmtOptimizer stmtOptimizer2) { + private Prod2StmtOptimizer( + final StmtOptimizer stmtOptimizer1, final StmtOptimizer stmtOptimizer2) { this.stmtOptimizer1 = stmtOptimizer1; this.stmtOptimizer2 = stmtOptimizer2; } - public static Prod2StmtOptimizer create( - final StmtOptimizer stmtOptimizer1, - final StmtOptimizer stmtOptimizer2) { + public static + Prod2StmtOptimizer create( + final StmtOptimizer stmtOptimizer1, + final StmtOptimizer stmtOptimizer2) { return new Prod2StmtOptimizer<>(stmtOptimizer1, stmtOptimizer2); } @Override public Stmt optimizeStmt(final Prod2State state, final Stmt stmt) { - return stmtOptimizer2.optimizeStmt(state.getState2(), - stmtOptimizer1.optimizeStmt(state.getState1(), stmt)); + return stmtOptimizer2.optimizeStmt( + state.getState2(), stmtOptimizer1.optimizeStmt(state.getState1(), stmt)); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2TransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2TransFunc.java index 4b285f0c5a..3d51e0d411 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2TransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/Prod2TransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,15 +18,19 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; +import java.util.Collection; +import java.util.Optional; -final class Prod2TransFunc +final class Prod2TransFunc< + S1 extends State, + S2 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec> implements TransFunc, A, Prod2Prec> { private final TransFunc transFunc1; @@ -34,37 +38,51 @@ final class Prod2TransFunc preStrenghteningOperator; private final StrengtheningOperator strenghteningOperator; - private Prod2TransFunc(final TransFunc transFunc1, - final TransFunc transFunc2, - final PreStrengtheningOperator preStrengtheningOperator, - final StrengtheningOperator strenghteningOperator) { + private Prod2TransFunc( + final TransFunc transFunc1, + final TransFunc transFunc2, + final PreStrengtheningOperator preStrengtheningOperator, + final StrengtheningOperator strenghteningOperator) { this.transFunc1 = checkNotNull(transFunc1); this.transFunc2 = checkNotNull(transFunc2); this.strenghteningOperator = checkNotNull(strenghteningOperator); this.preStrenghteningOperator = checkNotNull(preStrengtheningOperator); } - public static Prod2TransFunc create( - final TransFunc transFunc1, - final TransFunc transFunc2) { - return create(transFunc1, transFunc2, DefaultPreStrengtheningOperator.create(), + public static < + S1 extends State, + S2 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec> + Prod2TransFunc create( + final TransFunc transFunc1, + final TransFunc transFunc2) { + return create( + transFunc1, + transFunc2, + DefaultPreStrengtheningOperator.create(), (states, prec) -> states); } - public static Prod2TransFunc create( - final TransFunc transFunc1, - final TransFunc transFunc2, - final PreStrengtheningOperator preStrengtheningOperator, - final StrengtheningOperator strenghteningOperator - ) { - return new Prod2TransFunc<>(transFunc1, transFunc2, preStrengtheningOperator, - strenghteningOperator); + public static < + S1 extends State, + S2 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec> + Prod2TransFunc create( + final TransFunc transFunc1, + final TransFunc transFunc2, + final PreStrengtheningOperator preStrengtheningOperator, + final StrengtheningOperator strenghteningOperator) { + return new Prod2TransFunc<>( + transFunc1, transFunc2, preStrengtheningOperator, strenghteningOperator); } @Override - public Collection> getSuccStates(final Prod2State state, - final A action, - final Prod2Prec prec) { + public Collection> getSuccStates( + final Prod2State state, final A action, final Prod2Prec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); @@ -73,32 +91,31 @@ public Collection> getSuccStates(final Prod2State sta return singleton(state); } - final Collection succStates1 = transFunc1.getSuccStates( - preStrenghteningOperator.strengthenState1(state), - action, prec.getPrec1()); - final Optional optBottom1 = succStates1.stream().filter(State::isBottom) - .findAny(); + final Collection succStates1 = + transFunc1.getSuccStates( + preStrenghteningOperator.strengthenState1(state), action, prec.getPrec1()); + final Optional optBottom1 = + succStates1.stream().filter(State::isBottom).findAny(); if (optBottom1.isPresent()) { final S1 bottom1 = optBottom1.get(); return singleton(Prod2State.bottom1(bottom1)); } - final Collection succStates2 = transFunc2.getSuccStates( - preStrenghteningOperator.strengthenState2(state), - action, prec.getPrec2()); - final Optional optBottom2 = succStates2.stream().filter(State::isBottom) - .findAny(); + final Collection succStates2 = + transFunc2.getSuccStates( + preStrenghteningOperator.strengthenState2(state), action, prec.getPrec2()); + final Optional optBottom2 = + succStates2.stream().filter(State::isBottom).findAny(); if (optBottom2.isPresent()) { final S2 bottom2 = optBottom2.get(); return singleton(Prod2State.bottom2(bottom2)); } - final Collection> succStates = Prod2State.cartesian(succStates1, - succStates2); + final Collection> succStates = + Prod2State.cartesian(succStates1, succStates2); return strenghteningOperator.strengthen(succStates, prec); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/StrengtheningOperator.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/StrengtheningOperator.java index 5c1afbba2d..7b5eb45834 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/StrengtheningOperator.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/StrengtheningOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,14 +15,14 @@ */ package hu.bme.mit.theta.analysis.prod2; -import java.util.Collection; - import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; +import java.util.Collection; @FunctionalInterface -public interface StrengtheningOperator { +public interface StrengtheningOperator< + S1 extends State, S2 extends State, P1 extends Prec, P2 extends Prec> { - Collection> strengthen(final Collection> states, - final Prod2Prec prec); + Collection> strengthen( + final Collection> states, final Prod2Prec prec); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/AutomaticItpRefToProd2ExplPredPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/AutomaticItpRefToProd2ExplPredPrec.java index 47f0804d1f..a2ce89af89 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/AutomaticItpRefToProd2ExplPredPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/AutomaticItpRefToProd2ExplPredPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.prod2.prod2explpred; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expl.ExplPrec; import hu.bme.mit.theta.analysis.expr.refinement.ItpRefutation; import hu.bme.mit.theta.analysis.expr.refinement.RefutationToPrec; @@ -28,30 +29,27 @@ import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class AutomaticItpRefToProd2ExplPredPrec implements - RefutationToPrec, ItpRefutation> { +public final class AutomaticItpRefToProd2ExplPredPrec + implements RefutationToPrec, ItpRefutation> { private final Map, Set>> atomCount; private final ExprSplitter exprSplitter; private final AutoExpl autoExpl; - private AutomaticItpRefToProd2ExplPredPrec(final AutoExpl autoExpl, - final ExprSplitter exprSplitter) { + private AutomaticItpRefToProd2ExplPredPrec( + final AutoExpl autoExpl, final ExprSplitter exprSplitter) { this.exprSplitter = checkNotNull(exprSplitter); this.autoExpl = autoExpl; this.atomCount = Containers.createMap(); } - public static AutomaticItpRefToProd2ExplPredPrec create(final AutoExpl autoExpl, - final ExprSplitter exprSplitter) { + public static AutomaticItpRefToProd2ExplPredPrec create( + final AutoExpl autoExpl, final ExprSplitter exprSplitter) { checkNotNull(autoExpl); return new AutomaticItpRefToProd2ExplPredPrec(autoExpl, exprSplitter); } @@ -61,24 +59,30 @@ public Prod2Prec toPrec(ItpRefutation refutation, int index) final Expr refExpr = refutation.get(index); autoExpl.update(refExpr); - final var explSelectedVars = ExprUtils.getVars(refExpr).stream() - .filter(autoExpl::isExpl) - .collect(Collectors.toSet()); - final var predSelectedExprs = exprSplitter.apply(refExpr).stream() - .filter(expr -> !ExprUtils.getVars(expr).stream().allMatch(autoExpl::isExpl)) - .collect(Collectors.toSet()); + final var explSelectedVars = + ExprUtils.getVars(refExpr).stream() + .filter(autoExpl::isExpl) + .collect(Collectors.toSet()); + final var predSelectedExprs = + exprSplitter.apply(refExpr).stream() + .filter( + expr -> + !ExprUtils.getVars(expr).stream() + .allMatch(autoExpl::isExpl)) + .collect(Collectors.toSet()); return Prod2Prec.of(ExplPrec.of(explSelectedVars), PredPrec.of(predSelectedExprs)); } @Override - public Prod2Prec join(Prod2Prec prec1, - Prod2Prec prec2) { + public Prod2Prec join( + Prod2Prec prec1, Prod2Prec prec2) { final ExplPrec joinedExpl = prec1.getPrec1().join(prec2.getPrec1()); final PredPrec joinedPred = prec1.getPrec2().join(prec2.getPrec2()); - final var filteredPreds = joinedPred.getPreds().stream() - .filter(pred -> !joinedExpl.getVars().containsAll(ExprUtils.getVars(pred))) - .collect(Collectors.toList()); + final var filteredPreds = + joinedPred.getPreds().stream() + .filter(pred -> !joinedExpl.getVars().containsAll(ExprUtils.getVars(pred))) + .collect(Collectors.toList()); final PredPrec filteredPred = PredPrec.of(filteredPreds); return Prod2Prec.of(joinedExpl, filteredPred); } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/ItpRefToProd2ExplPredPrec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/ItpRefToProd2ExplPredPrec.java index 75dd45c00c..5201a42bd5 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/ItpRefToProd2ExplPredPrec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/ItpRefToProd2ExplPredPrec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,39 +15,36 @@ */ package hu.bme.mit.theta.analysis.prod2.prod2explpred; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expl.ExplPrec; import hu.bme.mit.theta.analysis.expr.refinement.ItpRefutation; import hu.bme.mit.theta.analysis.expr.refinement.RefutationToPrec; import hu.bme.mit.theta.analysis.pred.ExprSplitters.ExprSplitter; import hu.bme.mit.theta.analysis.pred.PredPrec; import hu.bme.mit.theta.analysis.prod2.Prod2Prec; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.decl.VarDecl; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; import hu.bme.mit.theta.core.utils.ExprUtils; - import java.util.Collection; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.Set; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class ItpRefToProd2ExplPredPrec implements - RefutationToPrec, ItpRefutation> { +public final class ItpRefToProd2ExplPredPrec + implements RefutationToPrec, ItpRefutation> { private final Set> explPreferredVars; private final ExprSplitter exprSplitter; - private ItpRefToProd2ExplPredPrec(final Set> explPreferredVars, - final ExprSplitter exprSplitter) { + private ItpRefToProd2ExplPredPrec( + final Set> explPreferredVars, final ExprSplitter exprSplitter) { this.explPreferredVars = checkNotNull(explPreferredVars); this.exprSplitter = checkNotNull(exprSplitter); } - public static ItpRefToProd2ExplPredPrec create(final Set> explPreferredVars, - final ExprSplitter exprSplitter) { + public static ItpRefToProd2ExplPredPrec create( + final Set> explPreferredVars, final ExprSplitter exprSplitter) { return new ItpRefToProd2ExplPredPrec(explPreferredVars, exprSplitter); } @@ -71,14 +68,13 @@ public Prod2Prec toPrec(ItpRefutation refutation, int index) } } return Prod2Prec.of(ExplPrec.of(explSelectedVars), PredPrec.of(predSelectedExprs)); - } @Override - public Prod2Prec join(Prod2Prec prec1, - Prod2Prec prec2) { - return Prod2Prec.of(prec1.getPrec1().join(prec2.getPrec1()), - prec1.getPrec2().join(prec2.getPrec2())); + public Prod2Prec join( + Prod2Prec prec1, Prod2Prec prec2) { + return Prod2Prec.of( + prec1.getPrec1().join(prec2.getPrec1()), prec1.getPrec2().join(prec2.getPrec2())); } @Override diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAbstractors.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAbstractors.java index d904e79bf0..3cea0db2da 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAbstractors.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAbstractors.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.prod2.prod2explpred; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Iff; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; + import hu.bme.mit.theta.analysis.expl.ExplPrec; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.pred.PredPrec; @@ -35,7 +40,6 @@ import hu.bme.mit.theta.core.utils.indexings.VarIndexing; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; @@ -45,25 +49,19 @@ import java.util.function.Function; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Iff; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; - public class Prod2ExplPredAbstractors { - private Prod2ExplPredAbstractors() { - } + private Prod2ExplPredAbstractors() {} public interface Prod2ExplPredAbstractor { - Collection> createStatesForExpr(final Expr expr, - final VarIndexing exprIndexing, - final Prod2Prec prec, final VarIndexing precIndexing, - final Function valuationToState, - final int limit); - + Collection> createStatesForExpr( + final Expr expr, + final VarIndexing exprIndexing, + final Prod2Prec prec, + final VarIndexing precIndexing, + final Function valuationToState, + final int limit); } public static BooleanAbstractor booleanAbstractor(final Solver solver) { @@ -89,8 +87,10 @@ public BooleanAbstractor(final Solver solver, final boolean split) { @Override public Collection> createStatesForExpr( - final Expr expr, final VarIndexing exprIndexing, - final Prod2Prec prec, final VarIndexing stateIndexing, + final Expr expr, + final VarIndexing exprIndexing, + final Prod2Prec prec, + final VarIndexing stateIndexing, final Function valuationToState, final int limit) { checkNotNull(expr); @@ -107,8 +107,10 @@ public Collection> createStatesForExpr( try (WithPushPop wp = new WithPushPop(solver)) { solver.add(PathUtils.unfold(expr, exprIndexing)); for (int i = 0; i < preds.size(); ++i) { - solver.add(Iff(actLits.get(i).getRef(), - PathUtils.unfold(preds.get(i), stateIndexing))); + solver.add( + Iff( + actLits.get(i).getRef(), + PathUtils.unfold(preds.get(i), stateIndexing))); } while (solver.check().isSat() && (limit == 0 || states.size() < limit)) { final Valuation model = solver.getModel(); @@ -133,18 +135,21 @@ public Collection> createStatesForExpr( } } } - final Set> simplfiedNewStatePreds = newStatePreds.stream() - .map(pred -> ExprUtils.simplify(pred, explState)) - .collect(Collectors.toSet()); + final Set> simplfiedNewStatePreds = + newStatePreds.stream() + .map(pred -> ExprUtils.simplify(pred, explState)) + .collect(Collectors.toSet()); final PredState predState = PredState.of(simplfiedNewStatePreds); - final Prod2State prod2ExplPredState = Prod2State.of( - explState, predState); + final Prod2State prod2ExplPredState = + Prod2State.of(explState, predState); states.add(prod2ExplPredState); - solver.add(Not(And(PathUtils.unfold(explState.toExpr(), stateIndexing), - And(feedback)))); + solver.add( + Not( + And( + PathUtils.unfold(explState.toExpr(), stateIndexing), + And(feedback)))); } - } return states; } @@ -155,5 +160,4 @@ private void generateActivationLiterals(final int n) { } } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAnalysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAnalysis.java index 069e97f0f5..18b2977300 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAnalysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredAnalysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -17,7 +17,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Analysis; import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.PartialOrd; @@ -29,34 +28,39 @@ import hu.bme.mit.theta.analysis.pred.PredState; import hu.bme.mit.theta.analysis.prod2.*; import hu.bme.mit.theta.analysis.prod2.prod2explpred.Prod2ExplPredAbstractors.Prod2ExplPredAbstractor; -import hu.bme.mit.theta.analysis.prod2.prod2explpred.Prod2ExplPredDedicatedTransFunc; public final class Prod2ExplPredAnalysis implements Analysis, A, Prod2Prec> { private final PartialOrd> partialOrd; - private final InitFunc, Prod2Prec> initFunc; - private final TransFunc, A, Prod2Prec> transFunc; + private final InitFunc, Prod2Prec> + initFunc; + private final TransFunc, A, Prod2Prec> + transFunc; - private Prod2ExplPredAnalysis(final Analysis analysis1, - final Analysis analysis2, - final StrengtheningOperator strenghteningOperator, - final Prod2ExplPredAbstractor prod2ExplPredAbstractor) { + private Prod2ExplPredAnalysis( + final Analysis analysis1, + final Analysis analysis2, + final StrengtheningOperator + strenghteningOperator, + final Prod2ExplPredAbstractor prod2ExplPredAbstractor) { checkNotNull(analysis1); checkNotNull(analysis2); partialOrd = Prod2Ord.create(analysis1.getPartialOrd(), analysis2.getPartialOrd()); - initFunc = Prod2InitFunc.create(analysis1.getInitFunc(), analysis2.getInitFunc(), - strenghteningOperator); + initFunc = + Prod2InitFunc.create( + analysis1.getInitFunc(), analysis2.getInitFunc(), strenghteningOperator); transFunc = Prod2ExplPredDedicatedTransFunc.create(prod2ExplPredAbstractor); } public static Prod2ExplPredAnalysis create( final Analysis analysis1, final Analysis analysis2, - final StrengtheningOperator strenghteningOperator, + final StrengtheningOperator + strenghteningOperator, final Prod2ExplPredAbstractor prod2ExplPredAbstractor) { - return new Prod2ExplPredAnalysis(analysis1, analysis2, strenghteningOperator, - prod2ExplPredAbstractor); + return new Prod2ExplPredAnalysis( + analysis1, analysis2, strenghteningOperator, prod2ExplPredAbstractor); } @Override @@ -70,8 +74,8 @@ public InitFunc, Prod2Prec> } @Override - public TransFunc, A, Prod2Prec> getTransFunc() { + public TransFunc, A, Prod2Prec> + getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredDedicatedTransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredDedicatedTransFunc.java index c8017245c8..c99bef9a90 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredDedicatedTransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredDedicatedTransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package hu.bme.mit.theta.analysis.prod2.prod2explpred; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.TransFunc; import hu.bme.mit.theta.analysis.expl.ExplPrec; import hu.bme.mit.theta.analysis.expl.ExplState; @@ -26,15 +28,11 @@ import hu.bme.mit.theta.analysis.prod2.Prod2State; import hu.bme.mit.theta.analysis.prod2.prod2explpred.Prod2ExplPredAbstractors.Prod2ExplPredAbstractor; import hu.bme.mit.theta.core.utils.indexings.VarIndexingFactory; - import java.util.Collection; import java.util.Collections; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - -public class Prod2ExplPredDedicatedTransFunc implements - TransFunc, A, Prod2Prec> { +public class Prod2ExplPredDedicatedTransFunc + implements TransFunc, A, Prod2Prec> { private final Prod2ExplPredAbstractor prod2ExplPredAbstractor; @@ -49,16 +47,21 @@ public static Prod2ExplPredDedicatedTransFunc create( @Override public Collection> getSuccStates( - Prod2State state, - A action, Prod2Prec prec) { + Prod2State state, A action, Prod2Prec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); - final Collection> succStates = prod2ExplPredAbstractor.createStatesForExpr( - And(state.toExpr(), action.toExpr()), VarIndexingFactory.indexing(0), prec, - action.nextIndexing(), prec.getPrec1()::createState, 0); - return succStates.isEmpty() ? Collections.singleton( - Prod2State.of(ExplState.bottom(), PredState.bottom())) : succStates; + final Collection> succStates = + prod2ExplPredAbstractor.createStatesForExpr( + And(state.toExpr(), action.toExpr()), + VarIndexingFactory.indexing(0), + prec, + action.nextIndexing(), + prec.getPrec1()::createState, + 0); + return succStates.isEmpty() + ? Collections.singleton(Prod2State.of(ExplState.bottom(), PredState.bottom())) + : succStates; } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredPreStrengtheningOperator.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredPreStrengtheningOperator.java index 57463020a8..86e1e613a6 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredPreStrengtheningOperator.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredPreStrengtheningOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,22 +15,20 @@ */ package hu.bme.mit.theta.analysis.prod2.prod2explpred; +import static com.google.common.base.Preconditions.checkNotNull; + import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.pred.PredState; import hu.bme.mit.theta.analysis.prod2.PreStrengtheningOperator; import hu.bme.mit.theta.analysis.prod2.Prod2State; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.ArrayList; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class Prod2ExplPredPreStrengtheningOperator implements - PreStrengtheningOperator { +public final class Prod2ExplPredPreStrengtheningOperator + implements PreStrengtheningOperator { - private Prod2ExplPredPreStrengtheningOperator() { - } + private Prod2ExplPredPreStrengtheningOperator() {} public static Prod2ExplPredPreStrengtheningOperator create() { return new Prod2ExplPredPreStrengtheningOperator(); diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStmtOptimizer.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStmtOptimizer.java index 841b9b3e24..7192d7f0b3 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStmtOptimizer.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStmtOptimizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,10 +15,10 @@ */ package hu.bme.mit.theta.analysis.prod2.prod2explpred; -import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; import hu.bme.mit.theta.analysis.expl.ExplState; import hu.bme.mit.theta.analysis.pred.PredState; import hu.bme.mit.theta.analysis.prod2.Prod2State; +import hu.bme.mit.theta.analysis.stmtoptimizer.StmtOptimizer; import hu.bme.mit.theta.core.stmt.Stmt; public class Prod2ExplPredStmtOptimizer implements StmtOptimizer> { diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStrengtheningOperator.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStrengtheningOperator.java index 91ce28631b..fdd20047aa 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStrengtheningOperator.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod2/prod2explpred/Prod2ExplPredStrengtheningOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -22,18 +22,15 @@ import hu.bme.mit.theta.analysis.prod2.Prod2Prec; import hu.bme.mit.theta.analysis.prod2.Prod2State; import hu.bme.mit.theta.analysis.prod2.StrengtheningOperator; +import hu.bme.mit.theta.common.container.Containers; import hu.bme.mit.theta.core.utils.PathUtils; import hu.bme.mit.theta.solver.Solver; import hu.bme.mit.theta.solver.utils.WithPushPop; - import java.util.Collection; - -import hu.bme.mit.theta.common.container.Containers; - import java.util.Set; -public final class Prod2ExplPredStrengtheningOperator implements - StrengtheningOperator { +public final class Prod2ExplPredStrengtheningOperator + implements StrengtheningOperator { private final Solver solver; @@ -62,7 +59,6 @@ public Collection> strengthen( validStates.add(prod2State); } } - } if (validStates.size() < prod2States.size()) { var removed = Containers.createSet(); @@ -76,4 +72,3 @@ public Collection> strengthen( return validStates; } } - diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3Analysis.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3Analysis.java index 80f3b4f87c..637e27068a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3Analysis.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3Analysis.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -25,30 +25,54 @@ import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; -public final class Prod3Analysis +public final class Prod3Analysis< + S1 extends State, + S2 extends State, + S3 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec> implements Analysis, A, Prod3Prec> { private final PartialOrd> partialOrd; private final InitFunc, Prod3Prec> initFunc; private final TransFunc, A, Prod3Prec> transFunc; - private Prod3Analysis(final Analysis analysis1, - final Analysis analysis2, - final Analysis analysis3) { + private Prod3Analysis( + final Analysis analysis1, + final Analysis analysis2, + final Analysis analysis3) { checkNotNull(analysis1); checkNotNull(analysis2); checkNotNull(analysis3); - partialOrd = Prod3Ord.create(analysis1.getPartialOrd(), analysis2.getPartialOrd(), - analysis3.getPartialOrd()); - initFunc = Prod3InitFunc.create(analysis1.getInitFunc(), analysis2.getInitFunc(), - analysis3.getInitFunc()); - transFunc = Prod3TransFunc.create(analysis1.getTransFunc(), analysis2.getTransFunc(), - analysis3.getTransFunc()); + partialOrd = + Prod3Ord.create( + analysis1.getPartialOrd(), + analysis2.getPartialOrd(), + analysis3.getPartialOrd()); + initFunc = + Prod3InitFunc.create( + analysis1.getInitFunc(), analysis2.getInitFunc(), analysis3.getInitFunc()); + transFunc = + Prod3TransFunc.create( + analysis1.getTransFunc(), + analysis2.getTransFunc(), + analysis3.getTransFunc()); } - public static Prod3Analysis create( - final Analysis analysis1, final Analysis analysis2, - final Analysis analysis3) { + public static < + S1 extends State, + S2 extends State, + S3 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec> + Prod3Analysis create( + final Analysis analysis1, + final Analysis analysis2, + final Analysis analysis3) { return new Prod3Analysis<>(analysis1, analysis2, analysis3); } @@ -66,5 +90,4 @@ public InitFunc, Prod3Prec> getInitFunc() { public TransFunc, A, Prod3Prec> getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3InitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3InitFunc.java index 60eea4c353..85022c1b9a 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3InitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3InitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,30 +18,45 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; +import java.util.Collection; +import java.util.Optional; -final class Prod3InitFunc +final class Prod3InitFunc< + S1 extends State, + S2 extends State, + S3 extends State, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec> implements InitFunc, Prod3Prec> { private final InitFunc initFunc1; private final InitFunc initFunc2; private final InitFunc initFunc3; - private Prod3InitFunc(final InitFunc initFunc1, final InitFunc initFunc2, - final InitFunc initFunc3) { + private Prod3InitFunc( + final InitFunc initFunc1, + final InitFunc initFunc2, + final InitFunc initFunc3) { this.initFunc1 = checkNotNull(initFunc1); this.initFunc2 = checkNotNull(initFunc2); this.initFunc3 = checkNotNull(initFunc3); } - public static Prod3InitFunc create( - final InitFunc initFunc1, final InitFunc initFunc2, - final InitFunc initFunc3) { + public static < + S1 extends State, + S2 extends State, + S3 extends State, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec> + Prod3InitFunc create( + final InitFunc initFunc1, + final InitFunc initFunc2, + final InitFunc initFunc3) { return new Prod3InitFunc<>(initFunc1, initFunc2, initFunc3); } @@ -49,8 +64,8 @@ public static > getInitStates(final Prod3Prec prec) { checkNotNull(prec); final Collection initStates1 = initFunc1.getInitStates(prec.getPrec1()); - final Optional optBottom1 = initStates1.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom1 = + initStates1.stream().filter(State::isBottom).findAny(); if (optBottom1.isPresent()) { final S1 bottom1 = optBottom1.get(); @@ -58,8 +73,8 @@ public Collection> getInitStates(final Prod3Prec initStates2 = initFunc2.getInitStates(prec.getPrec2()); - final Optional optBottom2 = initStates2.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom2 = + initStates2.stream().filter(State::isBottom).findAny(); if (optBottom2.isPresent()) { final S2 bottom2 = optBottom2.get(); @@ -67,8 +82,8 @@ public Collection> getInitStates(final Prod3Prec initStates3 = initFunc3.getInitStates(prec.getPrec3()); - final Optional optBottom3 = initStates3.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom3 = + initStates3.stream().filter(State::isBottom).findAny(); if (optBottom3.isPresent()) { final S3 bottom3 = optBottom3.get(); @@ -77,5 +92,4 @@ public Collection> getInitStates(final Prod3Prec private final PartialOrd partialOrd2; private final PartialOrd partialOrd3; - private Prod3Ord(final PartialOrd partialOrd1, final PartialOrd partialOrd2, - final PartialOrd partialOrd3) { + private Prod3Ord( + final PartialOrd partialOrd1, + final PartialOrd partialOrd2, + final PartialOrd partialOrd3) { this.partialOrd1 = checkNotNull(partialOrd1); this.partialOrd2 = checkNotNull(partialOrd2); this.partialOrd3 = checkNotNull(partialOrd3); } - public static Prod3Ord create( - final PartialOrd partialOrd1, final PartialOrd partialOrd2, - final PartialOrd partialOrd3) { + public static + Prod3Ord create( + final PartialOrd partialOrd1, + final PartialOrd partialOrd2, + final PartialOrd partialOrd3) { return new Prod3Ord<>(partialOrd1, partialOrd2, partialOrd3); } @@ -52,5 +56,4 @@ public boolean isLeq(final Prod3State state1, final Prod3State implements Prec { private static final int HASH_SEED = 4073; @@ -41,8 +40,7 @@ private Prod3Prec(final P1 prec1, final P2 prec2, final P3 prec3) { } public static Prod3Prec of( - final P1 prec1, - final P2 prec2, final P3 prec3) { + final P1 prec1, final P2 prec2, final P3 prec3) { return new Prod3Prec<>(prec1, prec2, prec3); } @@ -77,7 +75,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Prod3Prec that = (Prod3Prec) obj; - return this.prec1.equals(that.prec1) && this.prec2.equals(that.prec2) + return this.prec1.equals(that.prec1) + && this.prec2.equals(that.prec2) && this.prec3.equals(that.prec3); } else { return false; @@ -91,7 +90,10 @@ public String toString() { @Override public Collection> getUsedVars() { - return Streams.concat(prec1.getUsedVars().stream(), prec2.getUsedVars().stream(), - prec3.getUsedVars().stream()).collect(Collectors.toSet()); + return Streams.concat( + prec1.getUsedVars().stream(), + prec2.getUsedVars().stream(), + prec3.getUsedVars().stream()) + .collect(Collectors.toSet()); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3State.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3State.java index 3cc1457c0a..fcb8df8243 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3State.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3State.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,28 +15,25 @@ */ package hu.bme.mit.theta.analysis.prod3; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.ArrayList; import java.util.Collection; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; +public abstract class Prod3State + implements ExprState { -public abstract class Prod3State implements - ExprState { - - private Prod3State() { - } + private Prod3State() {} public static Prod3State of( - final S1 state1, - final S2 state2, final S3 state3) { + final S1 state1, final S2 state2, final S3 state3) { checkNotNull(state1); checkNotNull(state2); checkNotNull(state3); @@ -51,29 +48,31 @@ public static Prod3State< } } - public static Prod3State bottom1( - final S1 state) { + public static + Prod3State bottom1(final S1 state) { return new Bottom1<>(state); } - public static Prod3State bottom2( - final S2 state) { + public static + Prod3State bottom2(final S2 state) { return new Bottom2<>(state); } - public static Prod3State bottom3( - final S3 state) { + public static + Prod3State bottom3(final S3 state) { return new Bottom3<>(state); } - private static Prod3State product( - final S1 state1, final S2 state2, final S3 state3) { + private static + Prod3State product(final S1 state1, final S2 state2, final S3 state3) { return new Product<>(state1, state2, state3); } - public static Collection> cartesian( - final Iterable states1, final Iterable states2, - final Iterable states3) { + public static + Collection> cartesian( + final Iterable states1, + final Iterable states2, + final Iterable states3) { final Collection> result = new ArrayList<>(); for (final S1 state1 : states1) { for (final S2 state2 : states2) { @@ -189,7 +188,8 @@ public boolean isBottom() { @Override public Expr toExpr() { - if (state1 instanceof ExprState && state2 instanceof ExprState + if (state1 instanceof ExprState + && state2 instanceof ExprState && state3 instanceof ExprState) { final ExprState exprState1 = (ExprState) state1; final ExprState exprState2 = (ExprState) state2; @@ -219,7 +219,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Product that = (Product) obj; - return this.state1.equals(that.state1) && this.state2.equals(that.state2) + return this.state1.equals(that.state1) + && this.state2.equals(that.state2) && this.state3.equals(that.state3); } else { return false; @@ -228,20 +229,22 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(Prod3State.class.getSimpleName()).body().add(state1) - .add(state2).add(state3) + return Utils.lispStringBuilder(Prod3State.class.getSimpleName()) + .body() + .add(state1) + .add(state2) + .add(state3) .toString(); } } - private static abstract class Bottom + private abstract static class Bottom extends Prod3State { private static final int HASH_SEED = 3251; private volatile int hashCode = 0; - private Bottom() { - } + private Bottom() {} public abstract int getIndex(); @@ -281,8 +284,8 @@ public final boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Bottom that = (Bottom) obj; - return this.getIndex() == that.getIndex() && this.getState() - .equals(that.getState()); + return this.getIndex() == that.getIndex() + && this.getState().equals(that.getState()); } else { return false; } @@ -290,8 +293,10 @@ public final boolean equals(final Object obj) { @Override public final String toString() { - return Utils.lispStringBuilder(Prod3State.class.getSimpleName()).add(getIndex()) - .add(getState()).toString(); + return Utils.lispStringBuilder(Prod3State.class.getSimpleName()) + .add(getIndex()) + .add(getState()) + .toString(); } } @@ -507,5 +512,4 @@ public Prod3State with3(final S state) { return (Prod3State) this; } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3TransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3TransFunc.java index 0a57124d8d..73d7be9146 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3TransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod3/Prod3TransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,40 +18,54 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; +import java.util.Collection; +import java.util.Optional; -final class Prod3TransFunc +final class Prod3TransFunc< + S1 extends State, + S2 extends State, + S3 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec> implements TransFunc, A, Prod3Prec> { private final TransFunc transFunc1; private final TransFunc transFunc2; private final TransFunc transFunc3; - private Prod3TransFunc(final TransFunc transFunc1, - final TransFunc transFunc2, - final TransFunc transFunc3) { + private Prod3TransFunc( + final TransFunc transFunc1, + final TransFunc transFunc2, + final TransFunc transFunc3) { this.transFunc1 = checkNotNull(transFunc1); this.transFunc2 = checkNotNull(transFunc2); this.transFunc3 = checkNotNull(transFunc3); } - public static Prod3TransFunc create( - final TransFunc transFunc1, - final TransFunc transFunc2, - final TransFunc transFunc3) { + public static < + S1 extends State, + S2 extends State, + S3 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec> + Prod3TransFunc create( + final TransFunc transFunc1, + final TransFunc transFunc2, + final TransFunc transFunc3) { return new Prod3TransFunc<>(transFunc1, transFunc2, transFunc3); } @Override - public Collection> getSuccStates(final Prod3State state, - final A action, - final Prod3Prec prec) { + public Collection> getSuccStates( + final Prod3State state, final A action, final Prod3Prec prec) { checkNotNull(state); checkNotNull(action); checkNotNull(prec); @@ -60,33 +74,30 @@ public Collection> getSuccStates(final Prod3State succStates1 = transFunc1.getSuccStates(state.getState1(), - action, - prec.getPrec1()); - final Optional optBottom1 = succStates1.stream().filter(State::isBottom) - .findAny(); + final Collection succStates1 = + transFunc1.getSuccStates(state.getState1(), action, prec.getPrec1()); + final Optional optBottom1 = + succStates1.stream().filter(State::isBottom).findAny(); if (optBottom1.isPresent()) { final S1 bottom1 = optBottom1.get(); return singleton(Prod3State.bottom1(bottom1)); } - final Collection succStates2 = transFunc2.getSuccStates(state.getState2(), - action, - prec.getPrec2()); - final Optional optBottom2 = succStates2.stream().filter(State::isBottom) - .findAny(); + final Collection succStates2 = + transFunc2.getSuccStates(state.getState2(), action, prec.getPrec2()); + final Optional optBottom2 = + succStates2.stream().filter(State::isBottom).findAny(); if (optBottom2.isPresent()) { final S2 bottom2 = optBottom2.get(); return singleton(Prod3State.bottom2(bottom2)); } - final Collection succStates3 = transFunc3.getSuccStates(state.getState3(), - action, - prec.getPrec3()); - final Optional optBottom3 = succStates3.stream().filter(State::isBottom) - .findAny(); + final Collection succStates3 = + transFunc3.getSuccStates(state.getState3(), action, prec.getPrec3()); + final Optional optBottom3 = + succStates3.stream().filter(State::isBottom).findAny(); if (optBottom3.isPresent()) { final S3 bottom3 = optBottom3.get(); @@ -95,5 +106,4 @@ public Collection> getSuccStates(final Prod3State +public final class Prod4Analysis< + S1 extends State, + S2 extends State, + S3 extends State, + S4 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec, + P4 extends Prec> implements Analysis, A, Prod4Prec> { private final PartialOrd> partialOrd; private final InitFunc, Prod4Prec> initFunc; private final TransFunc, A, Prod4Prec> transFunc; - private Prod4Analysis(final Analysis analysis1, - final Analysis analysis2, - final Analysis analysis3, final Analysis analysis4) { + private Prod4Analysis( + final Analysis analysis1, + final Analysis analysis2, + final Analysis analysis3, + final Analysis analysis4) { checkNotNull(analysis1); checkNotNull(analysis2); checkNotNull(analysis3); checkNotNull(analysis4); - partialOrd = Prod4Ord.create(analysis1.getPartialOrd(), analysis2.getPartialOrd(), - analysis3.getPartialOrd(), - analysis4.getPartialOrd()); - initFunc = Prod4InitFunc.create(analysis1.getInitFunc(), analysis2.getInitFunc(), - analysis3.getInitFunc(), - analysis4.getInitFunc()); - transFunc = Prod4TransFunc.create(analysis1.getTransFunc(), analysis2.getTransFunc(), - analysis3.getTransFunc(), - analysis4.getTransFunc()); + partialOrd = + Prod4Ord.create( + analysis1.getPartialOrd(), + analysis2.getPartialOrd(), + analysis3.getPartialOrd(), + analysis4.getPartialOrd()); + initFunc = + Prod4InitFunc.create( + analysis1.getInitFunc(), + analysis2.getInitFunc(), + analysis3.getInitFunc(), + analysis4.getInitFunc()); + transFunc = + Prod4TransFunc.create( + analysis1.getTransFunc(), + analysis2.getTransFunc(), + analysis3.getTransFunc(), + analysis4.getTransFunc()); } - public static Prod4Analysis create( - final Analysis analysis1, final Analysis analysis2, - final Analysis analysis3, final Analysis analysis4) { + public static < + S1 extends State, + S2 extends State, + S3 extends State, + S4 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec, + P4 extends Prec> + Prod4Analysis create( + final Analysis analysis1, + final Analysis analysis2, + final Analysis analysis3, + final Analysis analysis4) { return new Prod4Analysis<>(analysis1, analysis2, analysis3, analysis4); } @@ -70,5 +102,4 @@ public InitFunc, Prod4Prec> getInitFu public TransFunc, A, Prod4Prec> getTransFunc() { return transFunc; } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4InitFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4InitFunc.java index d1410c40c0..37e2b23eb3 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4InitFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4InitFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,14 +18,21 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.analysis.InitFunc; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; +import java.util.Collection; +import java.util.Optional; -final class Prod4InitFunc +final class Prod4InitFunc< + S1 extends State, + S2 extends State, + S3 extends State, + S4 extends State, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec, + P4 extends Prec> implements InitFunc, Prod4Prec> { private final InitFunc initFunc1; @@ -33,18 +40,31 @@ final class Prod4InitFunc initFunc3; private final InitFunc initFunc4; - private Prod4InitFunc(final InitFunc initFunc1, final InitFunc initFunc2, - final InitFunc initFunc3, final InitFunc initFunc4) { + private Prod4InitFunc( + final InitFunc initFunc1, + final InitFunc initFunc2, + final InitFunc initFunc3, + final InitFunc initFunc4) { this.initFunc1 = checkNotNull(initFunc1); this.initFunc2 = checkNotNull(initFunc2); this.initFunc3 = checkNotNull(initFunc3); this.initFunc4 = checkNotNull(initFunc4); } - public static Prod4InitFunc create( - final InitFunc initFunc1, final InitFunc initFunc2, - final InitFunc initFunc3, - final InitFunc initFunc4) { + public static < + S1 extends State, + S2 extends State, + S3 extends State, + S4 extends State, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec, + P4 extends Prec> + Prod4InitFunc create( + final InitFunc initFunc1, + final InitFunc initFunc2, + final InitFunc initFunc3, + final InitFunc initFunc4) { return new Prod4InitFunc<>(initFunc1, initFunc2, initFunc3, initFunc4); } @@ -53,8 +73,8 @@ public Collection> getInitStates( final Prod4Prec prec) { checkNotNull(prec); final Collection initStates1 = initFunc1.getInitStates(prec.getPrec1()); - final Optional optBottom1 = initStates1.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom1 = + initStates1.stream().filter(State::isBottom).findAny(); if (optBottom1.isPresent()) { final S1 bottom1 = optBottom1.get(); @@ -62,8 +82,8 @@ public Collection> getInitStates( } final Collection initStates2 = initFunc2.getInitStates(prec.getPrec2()); - final Optional optBottom2 = initStates2.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom2 = + initStates2.stream().filter(State::isBottom).findAny(); if (optBottom2.isPresent()) { final S2 bottom2 = optBottom2.get(); @@ -71,8 +91,8 @@ public Collection> getInitStates( } final Collection initStates3 = initFunc3.getInitStates(prec.getPrec3()); - final Optional optBottom3 = initStates3.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom3 = + initStates3.stream().filter(State::isBottom).findAny(); if (optBottom3.isPresent()) { final S3 bottom3 = optBottom3.get(); @@ -80,8 +100,8 @@ public Collection> getInitStates( } final Collection initStates4 = initFunc4.getInitStates(prec.getPrec4()); - final Optional optBottom4 = initStates4.stream().filter(State::isBottom) - .findAny(); + final Optional optBottom4 = + initStates4.stream().filter(State::isBottom).findAny(); if (optBottom4.isPresent()) { final S4 bottom4 = optBottom4.get(); @@ -90,5 +110,4 @@ public Collection> getInitStates( return Prod4State.cartesian(initStates1, initStates2, initStates3, initStates4); } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Ord.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Ord.java index 041c7b1ffb..5f1308ef70 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Ord.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Ord.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -28,24 +28,29 @@ final class Prod4Ord partialOrd3; private final PartialOrd partialOrd4; - private Prod4Ord(final PartialOrd partialOrd1, final PartialOrd partialOrd2, - final PartialOrd partialOrd3, final PartialOrd partialOrd4) { + private Prod4Ord( + final PartialOrd partialOrd1, + final PartialOrd partialOrd2, + final PartialOrd partialOrd3, + final PartialOrd partialOrd4) { this.partialOrd1 = checkNotNull(partialOrd1); this.partialOrd2 = checkNotNull(partialOrd2); this.partialOrd3 = checkNotNull(partialOrd3); this.partialOrd4 = checkNotNull(partialOrd4); } - public static Prod4Ord create( - final PartialOrd partialOrd1, final PartialOrd partialOrd2, - final PartialOrd partialOrd3, - final PartialOrd partialOrd4) { + public static + Prod4Ord create( + final PartialOrd partialOrd1, + final PartialOrd partialOrd2, + final PartialOrd partialOrd3, + final PartialOrd partialOrd4) { return new Prod4Ord<>(partialOrd1, partialOrd2, partialOrd3, partialOrd4); } @Override - public boolean isLeq(final Prod4State state1, - final Prod4State state2) { + public boolean isLeq( + final Prod4State state1, final Prod4State state2) { if (state1.isBottom()) { return true; } else if (state2.isBottom()) { @@ -57,5 +62,4 @@ public boolean isLeq(final Prod4State state1, && partialOrd4.isLeq(state1.getState4(), state2.getState4()); } } - } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Prec.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Prec.java index 7c7a7ce002..8ab0d75fc4 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Prec.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4Prec.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,18 +15,17 @@ */ package hu.bme.mit.theta.analysis.prod4; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.Streams; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.decl.VarDecl; - import java.util.Collection; import java.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class Prod4Prec implements - Prec { +public final class Prod4Prec + implements Prec { private static final int HASH_SEED = 5153; private volatile int hashCode = 0; @@ -43,8 +42,9 @@ private Prod4Prec(final P1 prec1, final P2 prec2, final P3 prec3, final P4 prec4 this.prec4 = checkNotNull(prec4); } - public static Prod4Prec of( - final P1 prec1, final P2 prec2, final P3 prec3, final P4 prec4) { + public static + Prod4Prec of( + final P1 prec1, final P2 prec2, final P3 prec3, final P4 prec4) { return new Prod4Prec<>(prec1, prec2, prec3, prec4); } @@ -84,7 +84,8 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Prod4Prec that = (Prod4Prec) obj; - return this.prec1.equals(that.prec1) && this.prec2.equals(that.prec2) + return this.prec1.equals(that.prec1) + && this.prec2.equals(that.prec2) && this.prec3.equals(that.prec3) && this.prec4.equals(that.prec4); } else { @@ -94,13 +95,21 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder("Prod4Prec").add(prec1).add(prec2).add(prec3).add(prec4) + return Utils.lispStringBuilder("Prod4Prec") + .add(prec1) + .add(prec2) + .add(prec3) + .add(prec4) .toString(); } @Override public Collection> getUsedVars() { - return Streams.concat(prec1.getUsedVars().stream(), prec2.getUsedVars().stream(), - prec3.getUsedVars().stream(), prec4.getUsedVars().stream()).collect(Collectors.toSet()); + return Streams.concat( + prec1.getUsedVars().stream(), + prec2.getUsedVars().stream(), + prec3.getUsedVars().stream(), + prec4.getUsedVars().stream()) + .collect(Collectors.toSet()); } } diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4State.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4State.java index 0014a92b2d..010ded6447 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4State.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4State.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -15,27 +15,27 @@ */ package hu.bme.mit.theta.analysis.prod4; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; + import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.expr.ExprState; import hu.bme.mit.theta.common.Utils; import hu.bme.mit.theta.core.type.Expr; import hu.bme.mit.theta.core.type.booltype.BoolType; - import java.util.ArrayList; import java.util.Collection; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; - -public abstract class Prod4State +public abstract class Prod4State< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> implements ExprState { - private Prod4State() { - } + private Prod4State() {} - public static Prod4State of( - final S1 state1, final S2 state2, final S3 state3, final S4 state4) { + public static + Prod4State of( + final S1 state1, final S2 state2, final S3 state3, final S4 state4) { checkNotNull(state1); checkNotNull(state2); checkNotNull(state3); @@ -53,34 +53,38 @@ public static Prod4State bottom1( - final S1 state) { + public static + Prod4State bottom1(final S1 state) { return new Bottom1<>(state); } - public static Prod4State bottom2( - final S2 state) { + public static + Prod4State bottom2(final S2 state) { return new Bottom2<>(state); } - public static Prod4State bottom3( - final S3 state) { + public static + Prod4State bottom3(final S3 state) { return new Bottom3<>(state); } - public static Prod4State bottom4( - final S4 state) { + public static + Prod4State bottom4(final S4 state) { return new Bottom4<>(state); } - private static Prod4State product( - final S1 state1, final S2 state2, final S3 state3, final S4 state4) { + private static + Prod4State product( + final S1 state1, final S2 state2, final S3 state3, final S4 state4) { return new Product<>(state1, state2, state3, state4); } - public static Collection> cartesian( - final Iterable states1, final Iterable states2, - final Iterable states3, final Iterable states4) { + public static + Collection> cartesian( + final Iterable states1, + final Iterable states2, + final Iterable states3, + final Iterable states4) { final Collection> result = new ArrayList<>(); for (final S1 state1 : states1) { for (final S2 state2 : states2) { @@ -118,7 +122,8 @@ public static Prod4State with4(final S state); - private static final class Product + private static final class Product< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> extends Prod4State { private static final int HASH_SEED = 2297; @@ -227,13 +232,17 @@ public boolean isBottom() { @Override public Expr toExpr() { - if (state1 instanceof ExprState && state2 instanceof ExprState + if (state1 instanceof ExprState + && state2 instanceof ExprState && state3 instanceof ExprState) { final ExprState exprState1 = (ExprState) state1; final ExprState exprState2 = (ExprState) state2; final ExprState exprState3 = (ExprState) state3; final ExprState exprState4 = (ExprState) state4; - return And(exprState1.toExpr(), exprState2.toExpr(), exprState3.toExpr(), + return And( + exprState1.toExpr(), + exprState2.toExpr(), + exprState3.toExpr(), exprState4.toExpr()); } else { throw new UnsupportedOperationException(); @@ -260,8 +269,10 @@ public boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Product that = (Product) obj; - return this.state1.equals(that.state1) && this.state2.equals(that.state2) - && this.state3.equals(that.state3) && this.state4.equals(that.state4); + return this.state1.equals(that.state1) + && this.state2.equals(that.state2) + && this.state3.equals(that.state3) + && this.state4.equals(that.state4); } else { return false; } @@ -269,20 +280,24 @@ public boolean equals(final Object obj) { @Override public String toString() { - return Utils.lispStringBuilder(Prod4State.class.getSimpleName()).body().add(state1) - .add(state2).add(state3) - .add(state4).toString(); + return Utils.lispStringBuilder(Prod4State.class.getSimpleName()) + .body() + .add(state1) + .add(state2) + .add(state3) + .add(state4) + .toString(); } } - private static abstract class Bottom + private abstract static class Bottom< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> extends Prod4State { private static final int HASH_SEED = 4129; private volatile int hashCode = 0; - private Bottom() { - } + private Bottom() {} public abstract int getIndex(); @@ -322,8 +337,8 @@ public final boolean equals(final Object obj) { return true; } else if (obj != null && this.getClass() == obj.getClass()) { final Bottom that = (Bottom) obj; - return this.getIndex() == that.getIndex() && this.getState() - .equals(that.getState()); + return this.getIndex() == that.getIndex() + && this.getState().equals(that.getState()); } else { return false; } @@ -331,12 +346,15 @@ public final boolean equals(final Object obj) { @Override public final String toString() { - return Utils.lispStringBuilder(Prod4State.class.getSimpleName()).add(getIndex()) - .add(getState()).toString(); + return Utils.lispStringBuilder(Prod4State.class.getSimpleName()) + .add(getIndex()) + .add(getState()) + .toString(); } } - private static final class Bottom1 + private static final class Bottom1< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> extends Bottom { private final S1 state; @@ -423,7 +441,8 @@ public Prod4State with4(final S state) { } } - private static final class Bottom2 + private static final class Bottom2< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> extends Bottom { private final S2 state; @@ -510,7 +529,8 @@ public Prod4State with4(final S state) { } } - private static final class Bottom3 + private static final class Bottom3< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> extends Bottom { private final S3 state; @@ -597,7 +617,8 @@ public Prod4State with4(final S state) { } } - private static final class Bottom4 + private static final class Bottom4< + S1 extends State, S2 extends State, S3 extends State, S4 extends State> extends Bottom { private final S4 state; diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4TransFunc.java b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4TransFunc.java index 3a70a6b6ec..81a1ee01b6 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4TransFunc.java +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/prod4/Prod4TransFunc.java @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,15 +18,23 @@ import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Collections.singleton; -import java.util.Collection; -import java.util.Optional; - import hu.bme.mit.theta.analysis.Action; import hu.bme.mit.theta.analysis.Prec; import hu.bme.mit.theta.analysis.State; import hu.bme.mit.theta.analysis.TransFunc; +import java.util.Collection; +import java.util.Optional; -final class Prod4TransFunc +final class Prod4TransFunc< + S1 extends State, + S2 extends State, + S3 extends State, + S4 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec, + P4 extends Prec> implements TransFunc, A, Prod4Prec> { private final TransFunc transFunc1; @@ -34,27 +42,39 @@ final class Prod4TransFunc transFunc3; private final TransFunc transFunc4; - private Prod4TransFunc(final TransFunc transFunc1, - final TransFunc transFunc2, - final TransFunc transFunc3, - final TransFunc transFunc4) { + private Prod4TransFunc( + final TransFunc transFunc1, + final TransFunc transFunc2, + final TransFunc transFunc3, + final TransFunc transFunc4) { this.transFunc1 = checkNotNull(transFunc1); this.transFunc2 = checkNotNull(transFunc2); this.transFunc3 = checkNotNull(transFunc3); this.transFunc4 = checkNotNull(transFunc4); } - public static Prod4TransFunc create( - final TransFunc transFunc1, - final TransFunc transFunc2, - final TransFunc transFunc3, - final TransFunc transFunc4) { + public static < + S1 extends State, + S2 extends State, + S3 extends State, + S4 extends State, + A extends Action, + P1 extends Prec, + P2 extends Prec, + P3 extends Prec, + P4 extends Prec> + Prod4TransFunc create( + final TransFunc transFunc1, + final TransFunc transFunc2, + final TransFunc transFunc3, + final TransFunc transFunc4) { return new Prod4TransFunc<>(transFunc1, transFunc2, transFunc3, transFunc4); } @Override public Collection> getSuccStates( - final Prod4State state, final A action, + final Prod4State state, + final A action, final Prod4Prec prec) { checkNotNull(state); checkNotNull(action); @@ -64,44 +84,40 @@ public Collection> getSuccStates( return singleton(state); } - final Collection succStates1 = transFunc1.getSuccStates(state.getState1(), - action, - prec.getPrec1()); - final Optional optBottom1 = succStates1.stream().filter(State::isBottom) - .findAny(); + final Collection succStates1 = + transFunc1.getSuccStates(state.getState1(), action, prec.getPrec1()); + final Optional optBottom1 = + succStates1.stream().filter(State::isBottom).findAny(); if (optBottom1.isPresent()) { final S1 bottom1 = optBottom1.get(); return singleton(Prod4State.bottom1(bottom1)); } - final Collection succStates2 = transFunc2.getSuccStates(state.getState2(), - action, - prec.getPrec2()); - final Optional optBottom2 = succStates2.stream().filter(State::isBottom) - .findAny(); + final Collection succStates2 = + transFunc2.getSuccStates(state.getState2(), action, prec.getPrec2()); + final Optional optBottom2 = + succStates2.stream().filter(State::isBottom).findAny(); if (optBottom2.isPresent()) { final S2 bottom2 = optBottom2.get(); return singleton(Prod4State.bottom2(bottom2)); } - final Collection succStates3 = transFunc3.getSuccStates(state.getState3(), - action, - prec.getPrec3()); - final Optional optBottom3 = succStates3.stream().filter(State::isBottom) - .findAny(); + final Collection succStates3 = + transFunc3.getSuccStates(state.getState3(), action, prec.getPrec3()); + final Optional optBottom3 = + succStates3.stream().filter(State::isBottom).findAny(); if (optBottom3.isPresent()) { final S3 bottom3 = optBottom3.get(); return singleton(Prod4State.bottom3(bottom3)); } - final Collection succStates4 = transFunc4.getSuccStates(state.getState4(), - action, - prec.getPrec4()); - final Optional optBottom4 = succStates4.stream().filter(State::isBottom) - .findAny(); + final Collection succStates4 = + transFunc4.getSuccStates(state.getState4(), action, prec.getPrec4()); + final Optional optBottom4 = + succStates4.stream().filter(State::isBottom).findAny(); if (optBottom4.isPresent()) { final S4 bottom4 = optBottom4.get(); @@ -110,5 +126,4 @@ public Collection> getSuccStates( return Prod4State.cartesian(succStates1, succStates2, succStates3, succStates4); } - } 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 b75fa112c3..15266cce17 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 f5a4875219..e52a55e086 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. 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 a7c9983c7b..74ee9e4aa2 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 @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. diff --git a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrPrec.kt b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrPrec.kt index ace61e91c7..dcb9ae316e 100644 --- a/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrPrec.kt +++ b/subprojects/common/analysis/src/main/java/hu/bme/mit/theta/analysis/ptr/PtrPrec.kt @@ -1,5 +1,5 @@ /* - * Copyright 2024 Budapest University of Technology and Economics + * Copyright 2025 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. @@ -18,7 +18,8 @@ package hu.bme.mit.theta.analysis.ptr import hu.bme.mit.theta.analysis.Prec import hu.bme.mit.theta.core.decl.VarDecl -data class PtrPrec