Skip to content

Commit

Permalink
Move FakePointerExpression out of ACSL AST & refactor pointer backtra…
Browse files Browse the repository at this point in the history
…nslation (#708)

- Add a common supertype BacktranslatedACSLValue for BacktranslatedExpression
  and a new FakePointer record (which replaces FakePointerExpression).
  BacktranslatedACSLValue replaces BacktranslatedExpression in the public
  interface of ACSL backtranslation.
- Make BacktranslatedExpression a record.
- CACSL2BoogieBacktranslator: refactor extraction and backtranslation of
  pointer structs. Handle pointer names (now represented by a record
  PointerVariable) and pointer values separately.
  • Loading branch information
maul-esel authored Feb 12, 2025
1 parent 8cbce45 commit 6ef02ff
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 271 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ trunk/examples/concurrent/bpl/weaver-benchmarks/weaver
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/Decreases.java
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/Ensures.java
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/Expression.java
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/FakePointerExpression.java
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/FieldAccessExpression.java
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/FreeableExpression.java
/trunk/source/ACSLParser/src/de/uni_freiburg/informatik/ultimate/model/acsl/ast/FunctionApplication.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.CodeAnnotStmt;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.Ensures;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.Expression;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.FakePointerExpression;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.FieldAccessExpression;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.GhostDeclaration;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.GhostUpdate;
Expand Down Expand Up @@ -111,8 +110,6 @@ private static String printExpression(final Expression expression) {
case final BooleanLiteral boolLit -> "\\" + boolLit.getValue();
case final CastExpression cast ->
"(%s) %s".formatted(cast.getCastedType().getTypeName(), printExpression(cast.getExpression()));
case final FakePointerExpression pointer ->
"{%s:%s}".formatted(printExpression(pointer.getBase()), printExpression(pointer.getOffset()));
case final FieldAccessExpression f -> "(%s).%s".formatted(printExpression(f.getStruct()), f.getField());
// TODO FreeableExpression
// TODO FunctionApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,6 @@ Expression ::=
| { /** This can be used as call forall parameter, or as if or
* while condition. In all other places it is forbidden. */
WildcardExpression }
| { /** This is used to represent addresses in backtranslated program executions.
* There is no corresponding grammar rule for the parser. */
FakePointerExpression }
base : Expression
offset : Expression
);

ACSLType ::=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2024 Frank Schüssele (schuessf@informatik.uni-freiburg.de)
* Copyright (C) 2025 Dominik Klumpp (klumpp@informatik.uni-freiburg.de)
* Copyright (C) 2024-2025 University of Freiburg
*
* This file is part of the ULTIMATE CACSL2BoogieTranslator plug-in.
*
* The ULTIMATE CACSL2BoogieTranslator plug-in is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ULTIMATE CACSL2BoogieTranslator plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ULTIMATE CACSL2BoogieTranslator plug-in. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7:
* If you modify the ULTIMATE CACSL2BoogieTranslator plug-in, or any covered work, by linking
* or combining it with Eclipse RCP (or a modified version of Eclipse RCP),
* containing parts covered by the terms of the Eclipse Public License, the
* licensors of the ULTIMATE CACSL2BoogieTranslator plug-in grant you additional permission
* to convey the resulting work.
*/
package de.uni_freiburg.informatik.ultimate.plugins.generator.cacsl2boogietranslator;

import java.math.BigInteger;
import java.util.Objects;

import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.container.c.CType;
import de.uni_freiburg.informatik.ultimate.model.acsl.ACSLPrettyPrinter;
import de.uni_freiburg.informatik.ultimate.model.acsl.ast.Expression;
import de.uni_freiburg.informatik.ultimate.util.datastructures.BigInterval;

/**
* Represents a value resulting from the backtranslation from Boogie to C/ACSL.
*/
public sealed interface BacktranslatedACSLValue {
/**
* Represents a backtranslated value in the form of an ACSL expression.
*
* Such expressions may be used for the backtranslation of invariants and procedure contracts, as well as for
* program states.
*/
public record BacktranslatedExpression(Expression expression, CType cType, BigInterval range)
implements BacktranslatedACSLValue {
public BacktranslatedExpression(final Expression expression) {
this(expression, null, BigInterval.unbounded());
}

public BacktranslatedExpression {
Objects.requireNonNull(expression);
Objects.requireNonNull(range);
// cType is allowed to be null
}

@Override
public String toString() {
return ACSLPrettyPrinter.print(expression);
}
}

/**
* Represents a backtranslated value for a memory address in our memory model, consisting of a base address and an
* offset.
*
* This is not a real ACSL expression, and should only be used in the backtranslation of program states, not in
* invariants or contracts. Moreover, it must only be used for the values in a program state, not as a key (it does
* not represent a variable).
*
* While these values do not make sense outside of our tool (and thus should never make it into witnesses etc), they
* can be used for log output and can be helpful when debugging a feasible error trace reported by Ultimate.
*/
public record FakePointer(BigInteger base, BigInteger offset) implements BacktranslatedACSLValue {
public FakePointer {
Objects.requireNonNull(base);
Objects.requireNonNull(offset);
}

@Override
public String toString() {
return "{%s:%s}".formatted(base, offset);
}
}
}
Loading

0 comments on commit 6ef02ff

Please sign in to comment.