Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,8 @@ public static int computeStackSize(RuleApp ruleApp) {
JavaProgramElement element = block.program();
if (element instanceof StatementBlock) {
StatementBlock b = (StatementBlock) block.program();
ImmutableArray<ProgramPrefix> prefix = b.getPrefixElements();
ImmutableArray<PossibleProgramPrefix> prefix =
b.getPrefixElements();
result = CollectionUtil.count(prefix,
element1 -> element1 instanceof MethodFrame);
}
Expand Down Expand Up @@ -4006,7 +4007,8 @@ public static Pair<Integer, SourceElement> computeSecondStatement(
blocks.addFirst((StatementBlock) firstStatement);
}
SourceElement lastStatement = null;
while (firstStatement instanceof ProgramPrefix && lastStatement != firstStatement) {
while (firstStatement instanceof PossibleProgramPrefix
&& lastStatement != firstStatement) {
lastStatement = firstStatement;
firstStatement = firstStatement.getFirstElementIncludingBlocks();
if (lastStatement instanceof MethodFrame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import de.uka.ilkd.key.java.statement.MethodFrame;
import de.uka.ilkd.key.java.visitor.Visitor;
import de.uka.ilkd.key.logic.PosInProgram;
import de.uka.ilkd.key.logic.ProgramPrefix;
import de.uka.ilkd.key.logic.PossibleProgramPrefix;
import de.uka.ilkd.key.rule.MatchConditions;
import de.uka.ilkd.key.rule.inst.SVInstantiations;

Expand Down Expand Up @@ -166,12 +166,12 @@ public MatchConditions match(SourceData source, MatchConditions matchCond) {

ExecutionContext lastExecutionContext = null;

final ProgramPrefix prefix;
final PossibleProgramPrefix prefix;
int pos = -1;
PosInProgram relPos = PosInProgram.TOP;

if (src instanceof ProgramPrefix) {
prefix = (ProgramPrefix) src;
if (src instanceof PossibleProgramPrefix) {
prefix = (PossibleProgramPrefix) src;
final int srcPrefixLength = prefix.getPrefixLength();

if (patternPrefixLength > srcPrefixLength) {
Expand All @@ -180,7 +180,7 @@ public MatchConditions match(SourceData source, MatchConditions matchCond) {

pos = srcPrefixLength - patternPrefixLength;

ProgramPrefix firstActiveStatement = getPrefixElementAt(prefix, pos);
PossibleProgramPrefix firstActiveStatement = getPrefixElementAt(prefix, pos);

relPos = firstActiveStatement.getFirstActiveChildPos();

Expand All @@ -199,8 +199,9 @@ public MatchConditions match(SourceData source, MatchConditions matchCond) {

start = relPos.get(relPos.depth() - 1);
if (relPos.depth() > 1) {
firstActiveStatement = (ProgramPrefix) PosInProgram.getProgramAt(relPos.up(),
firstActiveStatement);
firstActiveStatement =
(PossibleProgramPrefix) PosInProgram.getProgramAt(relPos.up(),
firstActiveStatement);
}
}
newSource = new SourceData(firstActiveStatement, start, services);
Expand Down Expand Up @@ -232,7 +233,7 @@ public MatchConditions match(SourceData source, MatchConditions matchCond) {
* position
*/
private MatchConditions makeContextInfoComplete(MatchConditions matchCond, SourceData newSource,
ProgramPrefix prefix, int pos, PosInProgram relPos, ProgramElement src,
PossibleProgramPrefix prefix, int pos, PosInProgram relPos, ProgramElement src,
Services services) {

final SVInstantiations instantiations = matchCond.getInstantiations();
Expand Down Expand Up @@ -264,7 +265,7 @@ private MatchConditions makeContextInfoComplete(MatchConditions matchCond, Sourc
*/
private MatchConditions matchInnerExecutionContext(MatchConditions matchCond,
final Services services, ExecutionContext lastExecutionContext,
final ProgramPrefix prefix, int pos, final ProgramElement src) {
final PossibleProgramPrefix prefix, int pos, final ProgramElement src) {

// partial context instantiation

Expand Down Expand Up @@ -302,10 +303,11 @@ private MatchConditions matchInnerExecutionContext(MatchConditions matchCond,
* prefix.getPrefixElementAt(pos);
* @return the PosInProgram of the first element, which is not part of the prefix
*/
private PosInProgram matchPrefixEnd(final ProgramPrefix prefix, int pos, PosInProgram relPos) {
private PosInProgram matchPrefixEnd(final PossibleProgramPrefix prefix, int pos,
PosInProgram relPos) {
PosInProgram prefixEnd = PosInProgram.TOP;
if (prefix != null) {
ProgramPrefix currentPrefix = prefix;
PossibleProgramPrefix currentPrefix = prefix;
int i = 0;
while (i <= pos) {
final IntIterator it = currentPrefix.getFirstActiveChildPos().iterator();
Expand All @@ -328,8 +330,8 @@ private PosInProgram matchPrefixEnd(final ProgramPrefix prefix, int pos, PosInPr
return prefixEnd;
}

private static ProgramPrefix getPrefixElementAt(ProgramPrefix prefix, int i) {
ProgramPrefix current = prefix;
private static PossibleProgramPrefix getPrefixElementAt(PossibleProgramPrefix prefix, int i) {
PossibleProgramPrefix current = prefix;
for (int pos = 0; pos < i; pos++) {
current = current.getNextPrefixElement();
}
Expand Down
9 changes: 6 additions & 3 deletions key.core/src/main/java/de/uka/ilkd/key/java/JavaTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import de.uka.ilkd.key.java.visitor.CreatingASTVisitor;
import de.uka.ilkd.key.java.visitor.JavaASTVisitor;
import de.uka.ilkd.key.logic.JavaBlock;
import de.uka.ilkd.key.logic.ProgramPrefix;
import de.uka.ilkd.key.logic.PossibleProgramPrefix;

import org.key_project.util.ExtList;

Expand All @@ -32,12 +32,15 @@ public static SourceElement getActiveStatement(JavaBlock jb) {
assert jb.program() != null;

SourceElement result = jb.program().getFirstElement();
while ((result instanceof ProgramPrefix || result instanceof CatchAllStatement)
&& !(result instanceof StatementBlock && ((StatementBlock) result).isEmpty())) {
while ((result instanceof PossibleProgramPrefix pre && pre.isPrefix())
|| result instanceof CatchAllStatement) {
if (result instanceof LabeledStatement) {
result = ((LabeledStatement) result).getChildAt(1);
} else if (result instanceof CatchAllStatement) {
result = ((CatchAllStatement) result).getBody();
} else if (result == result.getFirstElement()
&& ((PossibleProgramPrefix) result).isPrefix()) {
System.out.println(result);
} else {
result = result.getFirstElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ public static SuperReference superReference() {
* @return a new {@link Switch} block that executes <code>branches</code> depending on the value
* of <code>expression</code>
*/
public static Switch switchBlock(final Expression expression, final Branch[] branches) {
public static Switch switchBlock(final Expression expression, final SwitchBranch[] branches) {
final Switch block = new Switch(expression, branches);

return block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package de.uka.ilkd.key.java;

import de.uka.ilkd.key.java.statement.MethodFrame;
import de.uka.ilkd.key.logic.ProgramPrefix;
import de.uka.ilkd.key.logic.PossibleProgramPrefix;

public class ProgramPrefixUtil {

Expand All @@ -26,7 +26,7 @@ public MethodFrame getInnerMostMethodFrame() {
}
}

public static ProgramPrefixInfo computeEssentials(ProgramPrefix prefix) {
public static ProgramPrefixInfo computeEssentials(PossibleProgramPrefix prefix) {
int length = 1;
MethodFrame mf = (MethodFrame) (prefix instanceof MethodFrame ? prefix : null);
while (prefix.hasNextPrefixElement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private ExtList collectChildrenAndComments(recoder.java.ProgramElement pe) {
* @param se the sourcelement to extract from, not null
* @return the newly created PositionInfo
*/
private PositionInfo positionInfo(recoder.java.SourceElement se) {
protected PositionInfo positionInfo(recoder.java.SourceElement se) {
var relPos = se.getRelativePosition();
var startPos = Position.fromSEPosition(se.getStartPosition());
var endPos = Position.fromSEPosition(se.getEndPosition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public MethodBodyStatement convert(RMethodBodyStatement l) {
return new MethodBodyStatement(tr, resVar, convert(l.getMethodReference()));
}

public ActiveCase convert(de.uka.ilkd.key.java.recoderext.ActiveCase ac) {
ExtList children = collectChildren(ac);
return new ActiveCase(children, positionInfo(ac));
}

/**
* translate Context statement blocks
*/
Expand Down Expand Up @@ -279,13 +284,17 @@ public SchemaVariable convert(CcatchSVWrapper svw) {
return svw.getSV();
}

public SchemaVariable convert(ProgramVariableSVWrapper svw) {
public SchemaVariable convert(de.uka.ilkd.key.java.recoderext.ProgramVariableSVWrapper svw) {
return svw.getSV();
}

public SchemaVariable convert(de.uka.ilkd.key.java.recoderext.SwitchBranchSVWrapper svw) {
return svw.getSV();
}

/**
* for some reason the this and super references have to be treated differently here.
* for some reason the {@code this} and {@code super} references have to be treated differently
* here.
*/

@Override
Expand Down
30 changes: 18 additions & 12 deletions key.core/src/main/java/de/uka/ilkd/key/java/StatementBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import de.uka.ilkd.key.java.statement.MethodFrame;
import de.uka.ilkd.key.java.visitor.Visitor;
import de.uka.ilkd.key.logic.PosInProgram;
import de.uka.ilkd.key.logic.ProgramPrefix;
import de.uka.ilkd.key.logic.PossibleProgramPrefix;
import de.uka.ilkd.key.util.Debug;

import org.key_project.util.ExtList;
Expand All @@ -21,7 +21,7 @@
* Statement block. taken from COMPOST and changed to achieve an immutable structure
*/
public class StatementBlock extends JavaStatement implements StatementContainer,
TypeDeclarationContainer, VariableScope, TypeScope, ProgramPrefix {
TypeDeclarationContainer, VariableScope, TypeScope, PossibleProgramPrefix {

/**
* Body.
Expand Down Expand Up @@ -102,9 +102,9 @@ public boolean equals(Object o) {
}

/** computes the prefix elements for the given array of statment block */
public static ImmutableArray<ProgramPrefix> computePrefixElements(
ImmutableArray<? extends Statement> b, ProgramPrefix current) {
final ArrayList<ProgramPrefix> prefix = new ArrayList<>();
public static ImmutableArray<PossibleProgramPrefix> computePrefixElements(
PossibleProgramPrefix current) {
final ArrayList<PossibleProgramPrefix> prefix = new ArrayList<>();
prefix.add(current);

while (current.hasNextPrefixElement()) {
Expand Down Expand Up @@ -246,23 +246,29 @@ public SourceElement getFirstElementIncludingBlocks() {
}
}

@Override
public boolean isPrefix() {
return !isEmpty();
}

@Override
public boolean hasNextPrefixElement() {
return body.size() != 0 && (body.get(0) instanceof ProgramPrefix);
return body.size() != 0 && (body.get(0) instanceof PossibleProgramPrefix);
}

@Override
public ProgramPrefix getNextPrefixElement() {
public PossibleProgramPrefix getNextPrefixElement() {
if (hasNextPrefixElement()) {
return (ProgramPrefix) body.get(0);
return (PossibleProgramPrefix) body.get(0);
} else {
throw new IndexOutOfBoundsException("No next prefix element " + this);
}
}

@Override
public ProgramPrefix getLastPrefixElement() {
return hasNextPrefixElement() ? ((ProgramPrefix) body.get(0)).getLastPrefixElement() : this;
public PossibleProgramPrefix getLastPrefixElement() {
return hasNextPrefixElement() ? ((PossibleProgramPrefix) body.get(0)).getLastPrefixElement()
: this;
}

@Override
Expand All @@ -276,8 +282,8 @@ public MethodFrame getInnerMostMethodFrame() {
}

@Override
public ImmutableArray<ProgramPrefix> getPrefixElements() {
return computePrefixElements(body, this);
public ImmutableArray<PossibleProgramPrefix> getPrefixElements() {
return computePrefixElements(this);
}

@Override
Expand Down
Loading
Loading