diff --git a/.gitignore b/.gitignore index df03685c259..6624464d29e 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ bin/ .settings .project .classpath +.factorypath # Files generated by IntelliJ ANTLR plugin key.core/src/main/gen diff --git a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/ProofObligationVars.java b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/ProofObligationVars.java index abc2cc23e97..72515470370 100644 --- a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/ProofObligationVars.java +++ b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/ProofObligationVars.java @@ -7,6 +7,8 @@ import de.uka.ilkd.key.java.JavaInfo; import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.logic.JTerm; import de.uka.ilkd.key.logic.ProgramElementName; import de.uka.ilkd.key.logic.TermBuilder; @@ -47,16 +49,15 @@ public class ProofObligationVars { private final TermBuilder tb; - public ProofObligationVars(IProgramMethod pm, KeYJavaType kjt, Services services) { - this.pre = StateVars.buildMethodContractPreVars(pm, kjt, services); - this.post = StateVars.buildMethodContractPostVars(this.pre, pm, kjt, services); + public ProofObligationVars(IProgramMethod pm, TypeReference typeRef, Services services) { + this.pre = StateVars.buildMethodContractPreVars(pm, typeRef, services); + this.post = StateVars.buildMethodContractPostVars(this.pre, pm, typeRef, services); this.tb = services.getTermBuilder(); this.exceptionParameter = buildExceptionParameter(services); this.formalParams = buildFormalParamVars(services); this.postfix = ""; } - public ProofObligationVars(ProofObligationVars orig, String postfix, Services services) { this.pre = StateVars.buildInfFlowPreVars(orig.pre, postfix, services); this.post = StateVars.buildInfFlowPostVars(orig.pre, orig.post, pre, postfix, services); @@ -66,7 +67,6 @@ public ProofObligationVars(ProofObligationVars orig, String postfix, Services se this.postfix = postfix; } - public ProofObligationVars(StateVars pre, StateVars post, JTerm exceptionParameter, ImmutableList formalParams, Services services) { this.pre = pre; @@ -114,7 +114,6 @@ public ProofObligationVars labelHeapAtPreAsAnonHeapFunc() { } } - /** * Build variable for try statement. * @@ -125,7 +124,7 @@ private JTerm buildExceptionParameter(Services services) { JavaInfo javaInfo = services.getJavaInfo(); final KeYJavaType eType = javaInfo.getTypeByClassName("java.lang.Exception"); final ProgramElementName ePEN = new ProgramElementName("e"); - return tb.var(new LocationVariable(ePEN, eType)); + return tb.var(new LocationVariable(ePEN, new TypeRef(eType))); } /** @@ -139,7 +138,8 @@ private ImmutableList buildFormalParamVars(Services services) for (JTerm param : pre.localVars) { ProgramVariable paramVar = param.op(ProgramVariable.class); ProgramElementName pen = new ProgramElementName("_" + paramVar.name()); - LocationVariable formalParamVar = new LocationVariable(pen, paramVar.getKeYJavaType()); + LocationVariable formalParamVar = + new LocationVariable(pen, paramVar.getTypeReference()); register(formalParamVar, services); JTerm formalParam = tb.var(formalParamVar); formalParamVars = formalParamVars.append(formalParam); diff --git a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/po/InfFlowContractPO.java b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/po/InfFlowContractPO.java index fb2dd1b66f5..19adc1096aa 100644 --- a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/po/InfFlowContractPO.java +++ b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/po/InfFlowContractPO.java @@ -12,6 +12,7 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.StatementBlock; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.logic.JTerm; import de.uka.ilkd.key.logic.op.IProgramMethod; import de.uka.ilkd.key.logic.op.JModality; @@ -50,7 +51,8 @@ public InfFlowContractPO(InitConfig initConfig, InformationFlowContract contract // generate proof obligation variables final IProgramMethod pm = contract.getTarget(); - symbExecVars = new ProofObligationVars(pm, contract.getKJT(), environmentServices); + symbExecVars = + new ProofObligationVars(pm, new TypeRef(contract.getKJT()), environmentServices); assert (symbExecVars.pre.self == null) == (pm.isStatic()); ifVars = new IFProofObligationVars(symbExecVars, environmentServices); diff --git a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/proof/init/StateVars.java b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/proof/init/StateVars.java index 2312879ffae..8c9a0cd0cc4 100644 --- a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/proof/init/StateVars.java +++ b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/proof/init/StateVars.java @@ -6,7 +6,7 @@ import java.util.Iterator; import de.uka.ilkd.key.java.Services; -import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.ldt.HeapLDT; import de.uka.ilkd.key.ldt.JavaDLTheory; import de.uka.ilkd.key.logic.JTerm; @@ -86,13 +86,11 @@ public StateVars(JTerm self, JTerm guard, ImmutableList localVars, JTerm paddedTermList = allTerms; } - public StateVars(JTerm self, ImmutableList localVars, JTerm result, JTerm exception, JTerm heap, JTerm mbyAtPre) { this(self, null, localVars, result, exception, heap, mbyAtPre); } - private ImmutableList appendIfNotNull(ImmutableList list, JTerm t) { if (t != null) { return list.append(t); @@ -101,7 +99,6 @@ private ImmutableList appendIfNotNull(ImmutableList list, JTerm t) } } - private ImmutableList appendIfNotNull(ImmutableList list, ImmutableList list2) { ImmutableList result = list; @@ -111,30 +108,25 @@ private ImmutableList appendIfNotNull(ImmutableList list, return result; } - public StateVars(JTerm self, JTerm guard, ImmutableList localVars, JTerm heap) { this(self, guard, localVars, null, null, heap, null); } - public StateVars(JTerm self, JTerm guard, ImmutableList localVars, JTerm result, JTerm exception, JTerm heap) { this(self, guard, localVars, result, exception, heap, null); } - public StateVars(@Nullable JTerm self, ImmutableList localVars, @Nullable JTerm result, @Nullable JTerm exception, JTerm heap) { this(self, localVars, result, exception, heap, null); } - public StateVars(JTerm self, ImmutableList localVars, JTerm heap) { this(self, localVars, null, null, heap); } - public StateVars(StateVars orig, String postfix, Services services) { this(copyVariable(orig.self, postfix, services), copyVariable(orig.guard, postfix, services), @@ -145,7 +137,6 @@ public StateVars(StateVars orig, String postfix, Services services) { copyFunction(orig.mbyAtPre, postfix, services)); } - private static ImmutableList copyVariables(ImmutableList ts, String postfix, Services services) { ImmutableList result = ImmutableSLList.nil(); @@ -155,7 +146,6 @@ private static ImmutableList copyVariables(ImmutableList ts, Strin return result; } - private static JTerm copyVariable(JTerm t, String postfix, Services services) { if (t != null) { final TermBuilder tb = services.getTermBuilder(); @@ -168,7 +158,6 @@ private static JTerm copyVariable(JTerm t, String postfix, Services services) { } } - private static JTerm newVariable(JTerm t, String name, Services services) { if (t == null) { return null; @@ -185,7 +174,6 @@ private static JTerm newVariable(JTerm t, String name, Services services) { return tb.var(newVar); } - private static JTerm copyHeapSymbol(JTerm t, String postfix, Services services) { if (t != null) { final TermBuilder tb = services.getTermBuilder(); @@ -198,7 +186,6 @@ private static JTerm copyHeapSymbol(JTerm t, String postfix, Services services) } } - private static JTerm newHeapSymbol(JTerm t, String name, Services services) { if (t == null) { return null; @@ -216,7 +203,6 @@ private static JTerm newHeapSymbol(JTerm t, String name, Services services) { } } - private static JTerm newFunction(JTerm t, String name, Services services) { if (t == null) { return null; @@ -227,7 +213,6 @@ private static JTerm newFunction(JTerm t, String name, Services services) { return tb.func(newFunc); } - private static JTerm copyFunction(JTerm t, String postfix, Services services) { if (t != null) { final TermBuilder tb = services.getTermBuilder(); @@ -240,33 +225,30 @@ private static JTerm copyFunction(JTerm t, String postfix, Services services) { } } - - public static StateVars buildMethodContractPreVars(IProgramMethod pm, KeYJavaType kjt, + public static StateVars buildMethodContractPreVars(IProgramMethod pm, TypeReference typeRef, Services services) { ImmutableArray heapLabels = new ImmutableArray<>(ParameterlessTermLabel.ANON_HEAP_LABEL); - return new StateVars(buildSelfVar(services, pm, kjt, ""), buildParamVars(services, "", pm), + return new StateVars(buildSelfVar(services, pm, typeRef, ""), + buildParamVars(services, "", pm), buildResultVar(pm, services, ""), buildExceptionVar(services, "", pm), buildHeapFunc("AtPre", heapLabels, services), buildMbyVar("", services)); } - public static StateVars buildMethodContractPostVars(StateVars preVars, IProgramMethod pm, - KeYJavaType kjt, Services services) { + TypeReference typeRef, Services services) { final String postfix = "AtPost"; // preVars.localVars: no local out variables - return new StateVars(buildSelfVar(services, pm, kjt, postfix), preVars.localVars, + return new StateVars(buildSelfVar(services, pm, typeRef, postfix), preVars.localVars, buildResultVar(pm, services, postfix), buildExceptionVar(services, postfix, pm), buildHeapFunc(postfix, new ImmutableArray<>(), services), preVars.mbyAtPre); } - public static StateVars buildInfFlowPreVars(StateVars origPreVars, String postfix, Services services) { return new StateVars(origPreVars, postfix, services); } - public static StateVars buildInfFlowPostVars(StateVars origPreVars, StateVars origPostVars, StateVars preVars, String postfix, Services services) { // create new post vars if original pre and original post var differ; @@ -297,19 +279,17 @@ public static StateVars buildInfFlowPostVars(StateVars origPreVars, StateVars or return new StateVars(self, guard, localPostVars, result, exception, heap, mbyAtPre); } - - private static JTerm buildSelfVar(Services services, IProgramMethod pm, KeYJavaType kjt, + private static JTerm buildSelfVar(Services services, IProgramMethod pm, TypeReference typeRef, String postfix) { if (pm.isStatic()) { return null; } final TermBuilder tb = services.getTermBuilder(); - JTerm selfVar = tb.var(tb.selfVar(pm, kjt, true, postfix)); + JTerm selfVar = tb.var(tb.selfVar(pm, typeRef, true, postfix)); register(selfVar.op(ProgramVariable.class), services); return selfVar; } - private static ImmutableList buildParamVars(Services services, String postfix, IProgramMethod pm) { final TermBuilder tb = services.getTermBuilder(); @@ -318,7 +298,6 @@ private static ImmutableList buildParamVars(Services services, String pos return paramVars; } - private static JTerm buildResultVar(IProgramMethod pm, Services services, String postfix) { if (pm.isVoid() || pm.isConstructor()) { return null; @@ -329,7 +308,6 @@ private static JTerm buildResultVar(IProgramMethod pm, Services services, String return resultVar; } - private static JTerm buildHeapFunc(String postfix, ImmutableArray labels, Services services) { HeapLDT heapLDT = services.getTypeConverter().getHeapLDT(); @@ -345,7 +323,6 @@ private static JTerm buildHeapFunc(String postfix, ImmutableArray lab } } - private static JTerm buildExceptionVar(Services services, String postfix, IProgramMethod pm) { final TermBuilder tb = services.getTermBuilder(); JTerm excVar = tb.var(tb.excVar("exc" + postfix, pm, true)); @@ -353,7 +330,6 @@ private static JTerm buildExceptionVar(Services services, String postfix, IProgr return excVar; } - private static JTerm buildMbyVar(String postfix, Services services) { final TermBuilder tb = services.getTermBuilder(); final Sort intSort = services.getTypeConverter().getIntegerLDT().targetSort(); @@ -363,7 +339,6 @@ private static JTerm buildMbyVar(String postfix, Services services) { return tb.func(mbyAtPreFunc); } - static void register(ProgramVariable pv, Services services) { Namespace progVarNames = services.getNamespaces().programVariables(); if (pv != null && progVarNames.lookup(pv.name()) == null) { @@ -371,14 +346,12 @@ static void register(ProgramVariable pv, Services services) { } } - static void register(ImmutableList pvs, Services services) { for (ProgramVariable pv : pvs) { register(pv, services); } } - static void register(Function f, Services services) { Namespace functionNames = services.getNamespaces().functions(); if (f != null && functionNames.lookup(f.name()) == null) { @@ -387,7 +360,6 @@ static void register(Function f, Services services) { } } - static ImmutableList ops(ImmutableList terms, Class opClass) throws IllegalArgumentException { ImmutableList ops = ImmutableSLList.nil(); @@ -397,7 +369,6 @@ static ImmutableList ops(ImmutableList terms, Class opClass) return ops; } - @Override public String toString() { return termList.toString(); diff --git a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowBlockContractInternalRule.java b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowBlockContractInternalRule.java index dfbaf9d7d12..3c29c014455 100644 --- a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowBlockContractInternalRule.java +++ b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowBlockContractInternalRule.java @@ -19,8 +19,8 @@ import de.uka.ilkd.key.informationflow.proof.init.StateVars; import de.uka.ilkd.key.informationflow.rule.tacletbuilder.InfFlowBlockContractTacletBuilder; import de.uka.ilkd.key.java.Services; -import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.ast.statement.JavaStatement; import de.uka.ilkd.key.logic.JTerm; import de.uka.ilkd.key.logic.ProgramElementName; @@ -192,7 +192,7 @@ protected void setUpValidityGoal(final ImmutableList result, var app = (InfFlowBlockContractInternalBuiltInRuleApp) application; final ProgramVariable exceptionParameter = - createLocalVariable("e", variables.exception.getKeYJavaType(), services); + createLocalVariable("e", variables.exception.getTypeReference(), services); validityGoal.setBranchLabel("Information Flow Validity"); // clear goal @@ -403,7 +403,7 @@ protected static ImmutableSet filterAppliedContracts( assert varTerm.op() instanceof LocationVariable; final TermBuilder tb = services.getTermBuilder(); - KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); if (!suffix.equalsIgnoreCase("")) { suffix = "_" + suffix; } @@ -426,7 +426,7 @@ protected static ImmutableList buildLocalOutsAtPre(ImmutableList v for (JTerm varTerm : varTerms) { assert varTerm.op() instanceof LocationVariable; - KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); String name = tb.newName(varTerm + "_Before"); LocationVariable varAtPostVar = @@ -448,7 +448,7 @@ protected static ImmutableList buildLocalOutsAtPost(ImmutableList for (JTerm varTerm : varTerms) { assert varTerm.op() instanceof LocationVariable; - KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); String name = tb.newName(varTerm + "_After"); LocationVariable varAtPostVar = diff --git a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowWhileInvariantRule.java b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowWhileInvariantRule.java index 63d9096654f..0c260a2df1c 100644 --- a/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowWhileInvariantRule.java +++ b/key.core.infflow/src/main/java/de/uka/ilkd/key/informationflow/rule/InfFlowWhileInvariantRule.java @@ -15,7 +15,7 @@ import de.uka.ilkd.key.informationflow.proof.init.StateVars; import de.uka.ilkd.key.informationflow.rule.tacletbuilder.InfFlowLoopInvariantTacletBuilder; import de.uka.ilkd.key.java.Services; -import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.ldt.HeapLDT; import de.uka.ilkd.key.logic.*; import de.uka.ilkd.key.logic.label.ParameterlessTermLabel; @@ -251,7 +251,7 @@ private static JTerm buildAtPostVar(JTerm varTerm, String suffix, Services servi assert varTerm.op() instanceof LocationVariable; final TermBuilder tb = services.getTermBuilder(); - final KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + final TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); if (!suffix.equalsIgnoreCase("")) { suffix = "_" + suffix; } @@ -269,7 +269,7 @@ private static JTerm buildBeforeVar(JTerm varTerm, Services services) { assert varTerm.op() instanceof LocationVariable; final TermBuilder tb = services.getTermBuilder(); - final KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + final TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); final String name = tb.newName(varTerm + "_Before"); final LocationVariable varAtPreVar = new LocationVariable(new ProgramElementName(name), resultType); @@ -284,7 +284,7 @@ private static JTerm buildAfterVar(JTerm varTerm, Services services) { assert varTerm.op() instanceof LocationVariable; final TermBuilder tb = services.getTermBuilder(); - final KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + final TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); final String name = tb.newName(varTerm + "_After"); final LocationVariable varAtPostVar = new LocationVariable(new ProgramElementName(name), resultType); @@ -302,7 +302,7 @@ private static ImmutableList buildLocalOutsAtPre(ImmutableList var for (final JTerm varTerm : varTerms) { assert varTerm.op() instanceof LocationVariable; - final KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + final TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); final String name = tb.newName(varTerm + "_Before"); final LocationVariable varAtPostVar = @@ -324,7 +324,7 @@ private static ImmutableList buildLocalOutsAtPost(ImmutableList va for (final JTerm varTerm : varTerms) { assert varTerm.op() instanceof LocationVariable; - final KeYJavaType resultType = ((LocationVariable) varTerm.op()).getKeYJavaType(); + final TypeReference resultType = ((LocationVariable) varTerm.op()).getTypeReference(); final String name = tb.newName(varTerm + "_After"); final LocationVariable varAtPostVar = diff --git a/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/model/impl/ExecutionMethodReturn.java b/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/model/impl/ExecutionMethodReturn.java index 1df059ea03d..af5ba39c17f 100644 --- a/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/model/impl/ExecutionMethodReturn.java +++ b/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/model/impl/ExecutionMethodReturn.java @@ -12,6 +12,7 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.SourceElement; import de.uka.ilkd.key.java.ast.reference.MethodReference; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.statement.MethodBodyStatement; import de.uka.ilkd.key.logic.JTerm; import de.uka.ilkd.key.logic.ProgramElementName; @@ -244,7 +245,7 @@ protected IExecutionMethodReturnValue[] lazyComputeReturnValues() throws ProofIn if (!pm.isVoid()) { resultVar = new LocationVariable( new ProgramElementName(services.getTermBuilder().newName("TmpResultVar")), - pm.getReturnType()); + new TypeRef(pm.getReturnType())); } } if (resultVar != null) { diff --git a/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/strategy/breakpoint/AbstractConditionalBreakpoint.java b/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/strategy/breakpoint/AbstractConditionalBreakpoint.java index 90b169143b8..a634003892e 100644 --- a/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/strategy/breakpoint/AbstractConditionalBreakpoint.java +++ b/key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/symbolic_execution/strategy/breakpoint/AbstractConditionalBreakpoint.java @@ -13,6 +13,7 @@ import de.uka.ilkd.key.java.ast.abstraction.*; import de.uka.ilkd.key.java.ast.declaration.*; import de.uka.ilkd.key.java.ast.reference.IExecutionContext; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.visitor.ProgramVariableCollector; import de.uka.ilkd.key.logic.*; import de.uka.ilkd.key.logic.op.*; @@ -297,7 +298,7 @@ private JTerm computeTermForCondition(String condition) { // collect all variables needed to parse the condition setSelfVar(new LocationVariable( new ProgramElementName(getProof().getServices().getTermBuilder().newName("self")), - containerType, null, false, false)); + new TypeRef(containerType), null, false, false)); ImmutableList varsForCondition = ImmutableSLList.nil(); if (getPm() != null) { // collect parameter variables diff --git a/key.core.wd/src/main/java/de/uka/ilkd/key/wd/po/WellDefinednessPO.java b/key.core.wd/src/main/java/de/uka/ilkd/key/wd/po/WellDefinednessPO.java index 597cf841da4..646854f6d03 100644 --- a/key.core.wd/src/main/java/de/uka/ilkd/key/wd/po/WellDefinednessPO.java +++ b/key.core.wd/src/main/java/de/uka/ilkd/key/wd/po/WellDefinednessPO.java @@ -8,6 +8,7 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.ldt.HeapLDT; import de.uka.ilkd.key.logic.*; import de.uka.ilkd.key.logic.label.ParameterlessTermLabel; @@ -84,9 +85,9 @@ private static Function createAnonHeap(LocationVariable heap, Services services) private static LocationVariable createSelf(IProgramMethod pm, KeYJavaType selfKJT, TermServices services) { if (pm == null) { - return services.getTermBuilder().selfVar(selfKJT, false); + return services.getTermBuilder().selfVar(new TypeRef(selfKJT), false); } else { - return services.getTermBuilder().selfVar(pm, selfKJT, true); + return services.getTermBuilder().selfVar(pm, new TypeRef(selfKJT), true); } } diff --git a/key.core/src/main/antlr4/KeYLexer.g4 b/key.core/src/main/antlr4/KeYLexer.g4 index 3b2dd941696..2b9435d13c5 100644 --- a/key.core/src/main/antlr4/KeYLexer.g4 +++ b/key.core/src/main/antlr4/KeYLexer.g4 @@ -160,6 +160,7 @@ MAXEXPANDMETHOD : '\\mayExpandMethod'; STRICT : '\\strict'; TYPEOF : '\\typeof'; INSTANTIATE_GENERIC : '\\instantiateGeneric'; +HAS_ANNOTATION: '\\hasAnnotation'; // Quantifiers, binding, substitution FORALL : '\\forall' | '\u2200'; diff --git a/key.core/src/main/antlr4/KeYParser.g4 b/key.core/src/main/antlr4/KeYParser.g4 index 5832a7238f7..2dff0359125 100644 --- a/key.core/src/main/antlr4/KeYParser.g4 +++ b/key.core/src/main/antlr4/KeYParser.g4 @@ -736,6 +736,7 @@ varexpId: // weigl, 2021-03-12: This will be later just an arbitrary identifier. | GET_VARIANT | IS_LABELED | ISINSTRICTFP + | HAS_ANNOTATION ; varexp_argument diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/KeYJavaASTFactory.java b/key.core/src/main/java/de/uka/ilkd/key/java/KeYJavaASTFactory.java index 0523878dbb1..091ec3f1bbf 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/KeYJavaASTFactory.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/KeYJavaASTFactory.java @@ -12,6 +12,7 @@ import de.uka.ilkd.key.java.ast.declaration.Modifier; import de.uka.ilkd.key.java.ast.declaration.ParameterDeclaration; import de.uka.ilkd.key.java.ast.declaration.VariableSpecification; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.ArrayInitializer; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.expression.ParenthesizedExpression; @@ -103,7 +104,6 @@ public static CopyAssignment assign(Expression lhs, Expression rhs, PositionInfo * @return a new {@link CopyAssignment} as defined by parameters */ public static CopyAssignment assign(final ExtList parameters) { - return new CopyAssignment(parameters); } @@ -114,14 +114,6 @@ public static Expression attribute(ReferencePrefix prefix, ProgramVariable field return new FieldReference(field, prefix); } - /** - * creates a local variable declaration typeRef name; - */ - public static LocalVariableDeclaration declare(ProgramElementName name, TypeReference typeRef) { - return new LocalVariableDeclaration(typeRef, - new VariableSpecification(new LocationVariable(name, typeRef.getKeYJavaType()))); - } - /** * Create a local variable declaration without initialization. * @@ -131,15 +123,14 @@ public static LocalVariableDeclaration declare(ProgramElementName name, TypeRefe * * @param name * the {@link ProgramElementName} of the variable to be declared - * @param type - * the static {@link KeYJavaType} of the variable to be declared + * @param typeRef + * the static {@link TypeReference} of the variable to be declared * @return a new {@link LocalVariableDeclaration} of a variable with static type * type and name name */ public static LocalVariableDeclaration declare(final ProgramElementName name, - final KeYJavaType type) { - - return declare(name, null, type); + final TypeReference typeRef) { + return declare(name, null, typeRef); } /** @@ -149,9 +140,10 @@ public static LocalVariableDeclaration declare(final ProgramElementName name, */ public static LocalVariableDeclaration declare(ProgramElementName name, @Nullable Expression init, - KeYJavaType type) { - return new LocalVariableDeclaration(new TypeRef(type), - new VariableSpecification(new LocationVariable(name, type), init, type)); + TypeReference typeRef) { + return new LocalVariableDeclaration(typeRef, + new VariableSpecification(new LocationVariable(name, typeRef), init, + typeRef.getKeYJavaType())); } /** @@ -165,14 +157,14 @@ public static LocalVariableDeclaration declare(ProgramElementName name, * the named and typed {@link IProgramVariable} to be declared * @param init * the {@link Expression} var is initialized with - * @param type - * the static {@link KeYJavaType} of var + * @param typeRef + * the static {@link TypeReference} of var * @return a {@link LocalVariableDeclaration} of var with static type * type and initial value init */ public static LocalVariableDeclaration declare(IProgramVariable var, Expression init, - KeYJavaType type) { - return declare(new Modifier[0], var, init, type); + TypeReference typeRef) { + return declare(new Modifier[0], var, init, typeRef); } /** @@ -189,17 +181,17 @@ public static LocalVariableDeclaration declare(IProgramVariable var, Expression * the {@link String} on which the variable's unique name is based * @param initializer * the {@link Expression} the declared variable is initialized with - * @param type - * the static {@link KeYJavaType} of the to be declared variable + * @param typeRef + * the static {@link TypeReference} of the to be declared variable * @return a {@link LocalVariableDeclaration} of variable named uniquely after name * with static type type and initial value initializer */ public static LocalVariableDeclaration declare(final Services services, final String name, - final Expression initializer, final KeYJavaType type) { + final Expression initializer, final TypeReference typeRef) { final ProgramElementName uniqueName = services.getVariableNamer().getTemporaryNameProposal(name); - return declare(uniqueName, initializer, type); + return declare(uniqueName, initializer, typeRef); } /** @@ -211,31 +203,31 @@ public static LocalVariableDeclaration declare(final Services services, final St * * @param var * the named and typed {@link IProgramVariable} to be declared - * @param type - * the static {@link KeYJavaType} of var + * @param typeRef + * the static {@link TypeReference} of var * @return a {@link LocalVariableDeclaration} of var with static type * type */ - public static LocalVariableDeclaration declare(IProgramVariable var, KeYJavaType type) { - return declare(var, null, type); + public static LocalVariableDeclaration declare(IProgramVariable var, TypeReference typeRef) { + return declare(var, null, typeRef); } /** * create a local variable declaration */ - public static LocalVariableDeclaration declare(String name, KeYJavaType type) { - return new LocalVariableDeclaration(new TypeRef(type), - new VariableSpecification(new LocationVariable(new ProgramElementName(name), type))); + public static LocalVariableDeclaration declare(String name, TypeReference typeRef) { + return new LocalVariableDeclaration(typeRef, + new VariableSpecification(new LocationVariable(new ProgramElementName(name), typeRef))); } /** * create a parameter declaration */ - - public static ParameterDeclaration parameterDeclaration(JavaInfo javaInfo, KeYJavaType kjt, + public static ParameterDeclaration parameterDeclaration(JavaInfo javaInfo, + TypeReference typeRef, String name) { - return new ParameterDeclaration(new Modifier[0], javaInfo.createTypeReference(kjt), - new VariableSpecification(localVariable(name, kjt)), false); + return new ParameterDeclaration(new Modifier[0], typeRef, + new VariableSpecification(localVariable(name, typeRef)), false); } /** @@ -253,17 +245,18 @@ public static ParameterDeclaration parameterDeclaration(JavaInfo javaInfo, KeYJa * the named and typed {@link IProgramVariable} to be declared as parameter * @return a {@link ParameterDeclaration} of var with static type kjt */ - public static ParameterDeclaration parameterDeclaration(JavaInfo javaInfo, KeYJavaType kjt, + public static ParameterDeclaration parameterDeclaration(JavaInfo javaInfo, + TypeReference typeRef, IProgramVariable var) { - return new ParameterDeclaration(new Modifier[0], javaInfo.createTypeReference(kjt), + return new ParameterDeclaration(new Modifier[0], typeRef, new VariableSpecification(var), false); } public static ParameterDeclaration parameterDeclaration(JavaInfo javaInfo, String type, String name) { - KeYJavaType kjt = javaInfo.getKeYJavaType(type); - return new ParameterDeclaration(new Modifier[0], javaInfo.createTypeReference(kjt), - new VariableSpecification(localVariable(name, kjt)), false); + TypeReference typeRef = new TypeRef(javaInfo.getKeYJavaType(type)); + return new ParameterDeclaration(new Modifier[0], typeRef, + new VariableSpecification(localVariable(name, typeRef)), false); } /** @@ -297,15 +290,15 @@ public static PassiveExpression passiveExpression(final Expression expression) { /** * create a local variable */ - public static ProgramVariable localVariable(String name, KeYJavaType kjt) { - return localVariable(new ProgramElementName(name), kjt); + public static ProgramVariable localVariable(String name, TypeReference typeRef) { + return localVariable(new ProgramElementName(name), typeRef); } /** * create a local variable */ - public static LocationVariable localVariable(ProgramElementName name, KeYJavaType kjt) { - return new LocationVariable(name, kjt); + public static LocationVariable localVariable(ProgramElementName name, TypeReference typeRef) { + return new LocationVariable(name, typeRef); } /** @@ -315,26 +308,26 @@ public static LocationVariable localVariable(ProgramElementName name, KeYJavaTyp * the {@link Services} whose {@link VariableNamer} is used * @param name * the {@link String} on which the variable's unique name is based - * @param type - * the variable's static {@link KeYJavaType} + * @param typeRef + * the variable's static {@link TypeReference} * @return a new {@link ProgramVariable} of static type type and with a unique name * based on name */ public static ProgramVariable localVariable(final Services services, final String name, - final KeYJavaType type) { + final TypeReference typeRef) { // first check for a saved name for this variable final NameRecorder nameRecorder = services.getNameRecorder(); for (var prop : nameRecorder.getSetProposals()) { if (prop.toString().startsWith(name + VariableNamer.TEMP_INDEX_SEPARATOR)) { return localVariable(new ProgramElementName(prop.toString()), - type); + typeRef); } } final ProgramElementName uniqueName = services.getVariableNamer().getTemporaryNameProposal(name); nameRecorder.addProposal(new Name(uniqueName.getProgramName())); - return localVariable(uniqueName, type); + return localVariable(uniqueName, typeRef); } /** @@ -429,17 +422,16 @@ public static Catch catchClause(final ParameterDeclaration parameter, * the {@link JavaInfo} containing kjt * @param param * the {@link String} name of the exception object variable - * @param kjt - * the {@link KeYJavaType} of the exception object variable + * @param typeRef + * the {@link TypeReference} of the exception object variable * @param body * the {@link StatementBlock} catch clause body * @return a new {@link Catch} with parameter param of static type kjt * and body body */ - public static Catch catchClause(JavaInfo javaInfo, String param, KeYJavaType kjt, + public static Catch catchClause(JavaInfo javaInfo, String param, TypeReference typeRef, StatementBlock body) { - - return new Catch(parameterDeclaration(javaInfo, kjt, param), body); + return new Catch(parameterDeclaration(javaInfo, typeRef, param), body); } /** @@ -464,8 +456,7 @@ public static Catch catchClause(JavaInfo javaInfo, String param, KeYJavaType kjt */ public static Catch catchClause(JavaInfo javaInfo, String param, String type, StatementBlock body) { - - return catchClause(javaInfo, param, javaInfo.getKeYJavaType(type), body); + return catchClause(javaInfo, param, new TypeRef(javaInfo.getKeYJavaType(type)), body); } /** @@ -941,18 +932,18 @@ public static Instanceof instanceOf(final Expression expression, final KeYJavaTy * type variable = 0; * * - * @param type - * the static {@link KeYJavaType} of variable + * @param typeRef + * the static {@link TypeReference} of variable * @param variable * the named and typed {@link IProgramVariable} to be declared * @return a new {@link LocalVariableDeclaration} of variable with static type * type and initial value zero */ - public static LocalVariableDeclaration declareZero(final KeYJavaType type, + public static LocalVariableDeclaration declareZero(final TypeReference typeRef, final IProgramVariable variable) { final IntLiteral zeroLiteral = zeroLiteral(); - return declare(variable, zeroLiteral, type); + return declare(variable, zeroLiteral, typeRef); } /** @@ -962,8 +953,8 @@ public static LocalVariableDeclaration declareZero(final KeYJavaType type, * type variable = reference.method(); * * - * @param type - * the static {@link KeYJavaType} of variable + * @param typeRef + * the static {@link TypeReference} of variable * @param variable * the named and typed {@link IProgramVariable} to be declared * @param reference @@ -973,11 +964,11 @@ public static LocalVariableDeclaration declareZero(final KeYJavaType type, * @return a new {@link LocalVariableDeclaration} of variable with static type * type and initial value reference.method() */ - public static LocalVariableDeclaration declareMethodCall(final KeYJavaType type, + public static LocalVariableDeclaration declareMethodCall(final TypeReference typeRef, final IProgramVariable variable, final ReferencePrefix reference, final String method) { final MethodReference call = methodCall(reference, method); - return declare(variable, call, type); + return declare(variable, call, typeRef); } /** @@ -1150,15 +1141,16 @@ public static ILoopInit loopInit(final LoopInitializer init) { * type variable = 0 * * - * @param type - * the static {@link KeYJavaType} of variable + * @param typeRef + * the static {@link TypeReference} of variable * @param variable * the named and typed {@link IProgramVariable} to be declared * @return a new {@link ILoopInit} that declares variable variable with static type * type and initial value zero */ - public static ILoopInit loopInitZero(final KeYJavaType type, final IProgramVariable variable) { - final LoopInitializer initializer = declareZero(type, variable); + public static ILoopInit loopInitZero(final TypeReference typeRef, + final IProgramVariable variable) { + final LoopInitializer initializer = declareZero(typeRef, variable); return loopInit(initializer); } @@ -1498,7 +1490,6 @@ public static CopyAssignment assignArrayField(final ProgramVariable variable, * @return a new {@link LocalVariableDeclaration} as defined by parameters */ public static LocalVariableDeclaration declare(final ExtList parameters) { - return new LocalVariableDeclaration(parameters); } @@ -1517,7 +1508,6 @@ public static LocalVariableDeclaration declare(final ExtList parameters) { * @return a new {@link LocalVariableDeclaration} of variable */ public static LocalVariableDeclaration declare(final IProgramVariable variable) { - return declare(variable, (Expression) null); } @@ -1539,9 +1529,9 @@ public static LocalVariableDeclaration declare(final IProgramVariable variable) */ public static LocalVariableDeclaration declare(final IProgramVariable variable, final Expression init) { - final KeYJavaType type = variable.getKeYJavaType(); + final TypeReference typeRef = variable.getTypeReference(); - return declare(variable, init, type); + return declare(variable, init, typeRef); } /** @@ -1557,16 +1547,16 @@ public static LocalVariableDeclaration declare(final IProgramVariable variable, * the named and typed {@link IProgramVariable} to be declared * @param init * the {@link Expression} variable is initialized with - * @param type - * the static {@link KeYJavaType} of variable + * @param typeRef + * the static {@link TypeReference} of variable * @return a new {@link LocalVariableDeclaration} of variable with static type * type and initial value init */ public static LocalVariableDeclaration declare(final Modifier modifier, - final IProgramVariable variable, final Expression init, final KeYJavaType type) { + final IProgramVariable variable, final Expression init, final TypeReference typeRef) { final ImmutableArray modifiers = new ImmutableArray<>(modifier); - return declare(modifiers, variable, init, type); + return declare(modifiers, variable, init, typeRef); } /** @@ -1582,41 +1572,16 @@ public static LocalVariableDeclaration declare(final Modifier modifier, * the named and typed {@link IProgramVariable} to be declared * @param init * the {@link Expression} variable is initialized with - * @param type - * the static {@link KeYJavaType} of variable + * @param typeRef + * the static {@link TypeReference} of variable * @return a new {@link LocalVariableDeclaration} of variable with static type * type and initial value init */ public static LocalVariableDeclaration declare(final Modifier[] modifiers, - final IProgramVariable variable, final Expression init, final KeYJavaType type) { + final IProgramVariable variable, final Expression init, final TypeReference typeRef) { final ImmutableArray m = new ImmutableArray<>(modifiers); - return declare(m, variable, init, type); - } - - /** - * Create a local variable declaration with an arbitrary number of modifiers. - * - *
-     * modifiers type variable = init;
-     * 
- * - * @param modifiers - * the {@link Modifier}s - * @param variable - * the named and typed {@link IProgramVariable} to be declared - * @param init - * the {@link Expression} variable is initialized with - * @param type - * the static {@link KeYJavaType} of variable - * @return a new {@link LocalVariableDeclaration} of variable with static type - * type and initial value init - */ - public static LocalVariableDeclaration declare(final ImmutableArray modifiers, - final IProgramVariable variable, final Expression init, final KeYJavaType type) { - final TypeRef typeRef = new TypeRef(type); - - return declare(modifiers, variable, init, typeRef); + return declare(m, variable, init, typeRef); } /** @@ -1996,6 +1961,8 @@ public static Finally finallyBlock(final StatementBlock body) { * the type's {@link ProgramElementName} * @param dimensions * the type's dimensions + * @param annotations + * the type's annotations * @param typePrefix * the type's {@link ReferencePrefix} * @param baseType @@ -2006,8 +1973,10 @@ public static Finally finallyBlock(final StatementBlock body) { public static ProgramElement declare(final ImmutableArray modifiers, final IProgramVariable variable, final Expression init, final ProgramElementName typeName, final int dimensions, + final ImmutableArray annotations, final ReferencePrefix typePrefix, final KeYJavaType baseType) { - final TypeRef typeRef = new TypeRef(typeName, dimensions, typePrefix, baseType); + final TypeRef typeRef = + new TypeRef(typeName, annotations, dimensions, typePrefix, baseType); return declare(modifiers, variable, init, typeRef); } @@ -2700,11 +2669,13 @@ public static TypeRef typeRef(final KeYJavaType type) { * the base {@link KeYJavaType} * @param dimensions * the number of dimensions + * @param annotations + * the {@link ImmutableArray} of {@link AnnotationExpression}s * @return a new {@link TypeRef} for dimensions dimensions of type */ - public static TypeRef typeRef(final KeYJavaType type, final int dimensions) { - - return new TypeRef(type, dimensions); + public static TypeRef typeRef(final KeYJavaType type, final int dimensions, + final ImmutableArray annotations) { + return new TypeRef(type, annotations, dimensions); } /** diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/KeYProgModelInfo.java b/key.core/src/main/java/de/uka/ilkd/key/java/KeYProgModelInfo.java index a0342b15026..f0215c676d0 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/KeYProgModelInfo.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/KeYProgModelInfo.java @@ -43,6 +43,7 @@ import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.DefaultConstructorDeclaration; +import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserAnnotationDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration; import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; @@ -93,7 +94,11 @@ public Collection allTypes() { private List getAllMethods(KeYJavaType kjt) { var type = rec2key().resolveType(kjt); if (type.isReferenceType()) { - return type.asReferenceType().getAllMethods(); + var tr = type.asReferenceType(); + + if (!tr.getTypeDeclaration().orElseThrow().isAnnotation()) { + return tr.getAllMethods(); + } } return Collections.emptyList(); } @@ -166,6 +171,10 @@ public boolean isFinal(KeYJavaType kjt) { // Interfaces can't be final return false; } + if (td.isAnnotation()) { + // Interfaces can't be final + return false; + } if (td instanceof ResolvedLogicalType) { // Logic types are not final? Just following primitive types here return false; @@ -226,7 +235,18 @@ public List getAllProgramMethodsLocallyDeclared(KeYJavaType ct) { if (!type.isReferenceType()) { return result; } - var rml = type.asReferenceType().getDeclaredMethods(); + + var refType = type.asReferenceType(); + + // methods for annotation declarations are currently not implemented in + // javaparser + if (refType.getTypeDeclaration() + .map(d -> d instanceof JavaParserAnnotationDeclaration) + .orElse(false)) { + return result; + } + + var rml = refType.getDeclaredMethods(); result.ensureCapacity(rml.size()); for (MethodUsage methodUsage : rml) { if (methodUsage.getDeclaration() instanceof JavaParserMethodDeclaration) { diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/Annotation.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/Annotation.java new file mode 100644 index 00000000000..13af3c22f27 --- /dev/null +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/Annotation.java @@ -0,0 +1,32 @@ +/* This file is part of KeY - https://key-project.org + * KeY is licensed under the GNU General Public License Version 2 + * SPDX-License-Identifier: GPL-2.0-only */ +package de.uka.ilkd.key.java.ast; + +import de.uka.ilkd.key.java.visitor.Visitor; + +public abstract class Annotation extends JavaNonTerminalProgramElement { + protected final String name; + + public Annotation(String name) { + this.name = name; + } + + @Override + public void visit(Visitor v) { + v.performActionOnAnnotation(this); + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + return ((Annotation) o).name.equals(name) && super.equals(o); + } +} diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/KeYJavaType.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/KeYJavaType.java index 8540b1d53cf..dada936367e 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/KeYJavaType.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/KeYJavaType.java @@ -74,7 +74,7 @@ public void setSort(@Nullable Sort s) { * * @return the default value of the given type according to JLS Sect. 4.5.5 */ - public Literal getDefaultValue() { + public @Nullable Literal getDefaultValue() { if (javaType == null) { return null; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/NullType.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/NullType.java index 36fa7c46194..3da8b5dc069 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/NullType.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/NullType.java @@ -6,6 +6,7 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.expression.literal.Literal; +import org.key_project.util.collection.ImmutableArray; import org.key_project.util.collection.ImmutableList; /** @@ -198,7 +199,6 @@ public Package getPackage() { return null; } - /** * returns the default value of the given type according to JLS Sect. 4.5.5 * diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/Type.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/Type.java index 50f31843bd7..4d458734394 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/Type.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/abstraction/Type.java @@ -3,6 +3,7 @@ * SPDX-License-Identifier: GPL-2.0-only */ package de.uka.ilkd.key.java.ast.abstraction; + import de.uka.ilkd.key.java.ast.expression.literal.Literal; /** @@ -19,5 +20,4 @@ public interface Type extends ProgramModelElement { * @return the default value of the given type according to JLS Sect. 4.5.5 */ Literal getDefaultValue(); - } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/annotation/MarkerAnnotation.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/annotation/MarkerAnnotation.java new file mode 100644 index 00000000000..aab9dc1a7ab --- /dev/null +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/annotation/MarkerAnnotation.java @@ -0,0 +1,22 @@ +/* This file is part of KeY - https://key-project.org + * KeY is licensed under the GNU General Public License Version 2 + * SPDX-License-Identifier: GPL-2.0-only */ +package de.uka.ilkd.key.java.ast.annotation; + +import de.uka.ilkd.key.java.ast.*; + +public class MarkerAnnotation extends Annotation { + public MarkerAnnotation(String name) { + super(name); + } + + @Override + public int getChildCount() { + return 0; + } + + @Override + public ProgramElement getChildAt(int index) { + throw new ArrayIndexOutOfBoundsException(); + } +} diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/AnnotationInterfaceDeclaration.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/AnnotationInterfaceDeclaration.java new file mode 100644 index 00000000000..3afdd89cf4b --- /dev/null +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/AnnotationInterfaceDeclaration.java @@ -0,0 +1,92 @@ +/* This file is part of KeY - https://key-project.org + * KeY is licensed under the GNU General Public License Version 2 + * SPDX-License-Identifier: GPL-2.0-only */ +package de.uka.ilkd.key.java.ast.declaration; + +import java.util.List; + +import de.uka.ilkd.key.java.ast.*; +import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.visitor.Visitor; +import de.uka.ilkd.key.logic.ProgramElementName; +import de.uka.ilkd.key.speclang.jml.pretranslation.TextualJMLConstruct; + +import org.key_project.util.collection.ImmutableArray; +import org.key_project.util.collection.ImmutableList; + +import org.jspecify.annotations.NonNull; + + +public class AnnotationInterfaceDeclaration extends TypeDeclaration { + public AnnotationInterfaceDeclaration( + PositionInfo pi, List comments, + @NonNull ImmutableArray modArray, + ProgramElementName name, ProgramElementName fullName, + ImmutableArray members, boolean parentIsInterfaceDeclaration, + boolean isLibrary, List jmlAttachments) { + super(pi, comments, modArray, name, fullName, members, parentIsInterfaceDeclaration, + isLibrary, ImmutableList.fromList(jmlAttachments)); + } + + /** + * returns the local declared supertypes + */ + public ImmutableList getSupertypes() { + return ImmutableList.of(); + } + + /** + * calls the corresponding method of a visitor in order to + * perform some action/transformation on this element + * + * @param v the Visitor + */ + public void visit(Visitor v) { + v.performActionOnAnnotationInterfaceDeclaration(this); + } + + /** + * Returns the number of children of this node. + * + * @return an int giving the number of children of this node + */ + public int getChildCount() { + int result = 0; + if (modArray != null) + result += modArray.size(); + if (name != null) + result++; + if (members != null) + result += members.size(); + return result; + } + + /** + * Returns the child at the specified index in this node's "virtual" child array + * + * @param index an index into this node's "virtual" child array + * @return the program element at the given position + * @throws ArrayIndexOutOfBoundsException if index is out of bounds + */ + public ProgramElement getChildAt(int index) { + int len; + if (modArray != null) { + len = modArray.size(); + if (len > index) + return modArray.get(index); + index -= len; + } + if (name != null) { + if (index == 0) + return name; + index--; + } + if (members != null) + return members.get(index); + throw new ArrayIndexOutOfBoundsException(); + } + + public boolean isInterface() { + return true; + } +} diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/ArrayDeclaration.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/ArrayDeclaration.java index cee7f4a0b62..a805d607890 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/ArrayDeclaration.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/ArrayDeclaration.java @@ -14,6 +14,9 @@ import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableSLList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * KeY used to model arrays using only the {@link ArrayType}. As * the only attribute of an array has been the length attribute, it has been handled in a different @@ -27,6 +30,7 @@ public class ArrayDeclaration extends TypeDeclaration implements ArrayType { + private static final Logger LOGGER = LoggerFactory.getLogger(ArrayDeclaration.class); /** * reference to the type the elements of this array must subclass @@ -213,13 +217,14 @@ public static ProgramElementName createName(TypeReference basetype) { return null; } - public String getAlternativeNameRepresentation() { if (altNameRepresentation == null) { final StringBuilder alt = new StringBuilder(); Type baseType = this.baseType.getKeYJavaType().getJavaType(); - if (baseType instanceof ArrayType) { + if (baseType == null) { + alt.append(this.baseType.getKeYJavaType().getName()); + } else if (baseType instanceof ArrayType) { alt.append(((ArrayType) baseType).getAlternativeNameRepresentation()); } else { if (baseType instanceof ClassType) { @@ -234,7 +239,6 @@ public String getAlternativeNameRepresentation() { return altNameRepresentation; } - /** * returns the local declared supertypes */ diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/TypeDeclaration.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/TypeDeclaration.java index 56b7eb8c87b..9a774a7dadd 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/TypeDeclaration.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/TypeDeclaration.java @@ -9,6 +9,7 @@ import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.abstraction.*; import de.uka.ilkd.key.java.ast.abstraction.Package; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.literal.NullLiteral; import de.uka.ilkd.key.logic.ProgramElementName; import de.uka.ilkd.key.speclang.jml.JMLInfoExtractor; @@ -168,6 +169,16 @@ public NullLiteral getDefaultValue() { return NullLiteral.NULL; } + /** + * returns the annotations of the type resulting from the type declaration, + * which is no annotations. + * + * @return the annotations of the type declaration + */ + public ImmutableArray getAnnotations() { + return new ImmutableArray<>(); + } + /** * Get ProgramElementName. * diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/VariableDeclaration.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/VariableDeclaration.java index c51580e7788..19a1c55b590 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/VariableDeclaration.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/VariableDeclaration.java @@ -28,7 +28,6 @@ public abstract class VariableDeclaration extends JavaDeclaration /** * Type reference. */ - protected final TypeReference typeReference; /** @@ -41,7 +40,6 @@ public abstract class VariableDeclaration extends JavaDeclaration /** * Variable declaration. */ - protected VariableDeclaration() { typeReference = null; parentIsInterfaceDeclaration = false; diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/AnnotationUseSpecification.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/AnnotationUseSpecification.java deleted file mode 100644 index 28acee43b25..00000000000 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/AnnotationUseSpecification.java +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of KeY - https://key-project.org - * KeY is licensed under the GNU General Public License Version 2 - * SPDX-License-Identifier: GPL-2.0-only */ -package de.uka.ilkd.key.java.ast.declaration.modifier; - -import de.uka.ilkd.key.java.ast.ProgramElement; -import de.uka.ilkd.key.java.ast.declaration.Modifier; -import de.uka.ilkd.key.java.ast.reference.TypeReference; -import de.uka.ilkd.key.java.ast.reference.TypeReferenceContainer; - -public class AnnotationUseSpecification extends Modifier implements TypeReferenceContainer { - - protected final TypeReference tr; - - public AnnotationUseSpecification(TypeReference tr) { - super(); - this.tr = tr; - } - - protected String getSymbol() { - return "@" + tr.toString(); - } - - public TypeReference getTypeReferenceAt(int index) { - if (index == 0) { - return tr; - } - throw new ArrayIndexOutOfBoundsException(); - } - - public int getTypeReferenceCount() { - return 1; - } - - public ProgramElement getChildAt(int index) { - if (index == 0) { - return tr; - } - throw new ArrayIndexOutOfBoundsException(); - } - - public int getChildCount() { - return 1; - } - -} diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/package-info.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/package-info.java index 573a2c02dcc..3f9cca9abe8 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/package-info.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/modifier/package-info.java @@ -1,6 +1,4 @@ /** - * This package collects all Java modifiers. The sole abstraction beneath - * the parent {@link recoder.java.declaration.Modifier} is the - * {@link recoder.java.declaration.modifier.VisibilityModifier}. + * This package collects all Java modifiers. */ -package de.uka.ilkd.key.java.declaration.modifier; +package de.uka.ilkd.key.java.ast.declaration.modifier; diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/DLEmbeddedExpression.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/DLEmbeddedExpression.java index db245659e60..031b4d9b939 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/DLEmbeddedExpression.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/DLEmbeddedExpression.java @@ -121,7 +121,7 @@ public void check(Services javaServ, KeYJavaType containingClass) throws Convert final ProgramElementName programName = qualifier.isEmpty() ? new ProgramElementName(name) : new ProgramElementName(name, qualifier); - TypeRef tr = new TypeRef(programName, 0, null, containingClass); + TypeRef tr = new TypeRef(programName, new ImmutableArray<>(), 0, null, containingClass); ExecutionContext ec = new ExecutionContext(tr, null, null); for (int i = 0; i < actual; i++) { diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/New.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/New.java index 4f803d4aa11..38a083f527d 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/New.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/New.java @@ -80,7 +80,6 @@ public New(ExtList children, ReferencePrefix rp, PositionInfo pi) { accessPath = rp; } - /** * Constructor for the transformation of COMPOST ASTs to KeY. * @@ -210,6 +209,7 @@ public ProgramElement getChildAt(int index) { if (index == 0) { return anonymousClass; } + index--; } throw new ArrayIndexOutOfBoundsException(); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/NewArray.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/NewArray.java index 6f8621e366f..355314b54ba 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/NewArray.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/NewArray.java @@ -210,6 +210,7 @@ public ProgramElement getChildAt(int index) { if (index == 0) { return arrayInitializer; } + index--; } throw new ArrayIndexOutOfBoundsException(); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/TypeOperator.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/TypeOperator.java index 2612257790f..59ea05c30a8 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/TypeOperator.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/TypeOperator.java @@ -31,7 +31,6 @@ public abstract class TypeOperator extends Operator implements TypeReferenceCont */ protected final TypeReference typeReference; - /** * Constructor for the transformation of COMPOST ASTs to KeY. * @@ -121,6 +120,4 @@ public KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec) { public KeYJavaType getKeYJavaType(Services javaServ) { return getTypeReference().getKeYJavaType(); } - - } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/ReferencePrefix.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/ReferencePrefix.java index c99cac7c3a1..ad00443a7a5 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/ReferencePrefix.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/ReferencePrefix.java @@ -13,5 +13,4 @@ public interface ReferencePrefix extends ProgramElement { ReferencePrefix getReferencePrefix(); - } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchemaTypeReference.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchemaTypeReference.java index 8f1211de06b..fb05f1d8c2c 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchemaTypeReference.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchemaTypeReference.java @@ -12,13 +12,15 @@ import de.uka.ilkd.key.rule.AbstractProgramElement; import de.uka.ilkd.key.rule.MatchConditions; +import org.key_project.util.collection.ImmutableArray; + public class SchemaTypeReference extends TypeReferenceImp implements AbstractProgramElement { private final String fullName; public SchemaTypeReference(ProgramElementName name, int dimension, ReferencePrefix prefix) { - super(name, dimension, prefix); + super(name, new ImmutableArray<>(), dimension, prefix); final StringBuilder sb = new StringBuilder(); // as no inner classes prefix must be package reference @@ -31,6 +33,7 @@ public SchemaTypeReference(ProgramElementName name, int dimension, ReferencePref fullName = sb.toString(); } + @Override public KeYJavaType getKeYJavaType() { return null; } @@ -42,10 +45,12 @@ public KeYJavaType getKeYJavaType(Services services) { return kjt; } + @Override public ProgramElement getConcreteProgramElement(Services services) { return new TypeRef(getKeYJavaType(services)); } + @Override public MatchConditions match(SourceData source, MatchConditions matchCond) { ProgramElement t = source.getSource(); if (t instanceof TypeReference) { @@ -65,6 +70,7 @@ public MatchConditions match(SourceData source, MatchConditions matchCond) { * @param v * the Visitor */ + @Override public void visit(Visitor v) { v.performActionOnAbstractProgramElement(this); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchematicFieldReference.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchematicFieldReference.java index 0a83f703864..39fae03c8bc 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchematicFieldReference.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/SchematicFieldReference.java @@ -22,8 +22,7 @@ * * @author AutoDoc */ -public class SchematicFieldReference extends FieldReference - implements MemberReference, ReferenceSuffix, TypeReferenceContainer, ExpressionContainer { +public class SchematicFieldReference extends FieldReference { private static final ProgramVariable SCHEMA_VARIABLE = new LocationVariable(new ProgramElementName("SCHEMA_VARIABLE_IGNORE"), JavaDLTheory.ANY); @@ -95,7 +94,6 @@ public ReferenceSuffix getReferenceSuffix() { return (ProgramSV) schemaVariable; } - /** * Set reference prefix. * @@ -105,7 +103,6 @@ public ReferencePrefix setReferencePrefix(ReferencePrefix rp) { return new SchematicFieldReference(schemaVariable, rp); } - /** * Return the type reference at the specified index in this node's "virtual" type reference * array. @@ -164,7 +161,6 @@ public void visit(Visitor v) { v.performActionOnSchematicFieldReference(this); } - public MatchConditions match(SourceData source, MatchConditions matchCond) { ProgramElement src = source.getSource(); if (!(src instanceof FieldReference)) { diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeRef.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeRef.java index a008f4a6170..2d7f6f38355 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeRef.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeRef.java @@ -3,14 +3,16 @@ * SPDX-License-Identifier: GPL-2.0-only */ package de.uka.ilkd.key.java.ast.reference; - +import static de.uka.ilkd.key.java.KeYJavaASTFactory.throwClause; import java.util.Objects; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.logic.ProgramElementName; import org.key_project.util.ExtList; +import org.key_project.util.collection.ImmutableArray; import org.jspecify.annotations.NonNull; @@ -21,33 +23,36 @@ public class TypeRef extends TypeReferenceImp { /** * creates a type reference for the given KeYJavaType with dimension 0 and creates a suitable * package reference prefix from the KeYJavaType. If this is not desired use the constructor - * TypeRef(ProgramElementName, int, ReferencePrefix, KeYJavaType) and take null as last + * TypeRef(ProgramElementName, ImmutableArray, int, ReferencePrefix, + * KeYJavaType) and take null as last * argument. */ public TypeRef(@NonNull KeYJavaType kjt) { - this(kjt, 0); + this(kjt, new ImmutableArray<>(), 0); } /** * creates a type reference for the given KeYJavaType and the given dimension and creates a * suitable package reference prefix from the KeYJavaType. If this is not desired use the - * constructor TypeRef(ProgramElementName, int, ReferencePrefix, KeYJavaType) and take null as + * constructor TypeRef(ProgramElementName, ImmutableArray, int, + * ReferencePrefix, KeYJavaType) and take null as * last argument. */ - public TypeRef(@NonNull KeYJavaType kjt, int dim) { - super(new ProgramElementName(kjt.getName()), dim, kjt.createPackagePrefix()); + public TypeRef(@NonNull KeYJavaType kjt, ImmutableArray annotations, + int dim) { + super(new ProgramElementName(kjt.getName()), annotations, dim, kjt.createPackagePrefix()); this.kjt = kjt; } - public TypeRef(ExtList children, KeYJavaType kjt, int dim) { super(children, dim); this.kjt = kjt; } - public TypeRef(ProgramElementName name, int dimension, ReferencePrefix prefix, + public TypeRef(ProgramElementName name, ImmutableArray annotations, + int dimension, ReferencePrefix prefix, KeYJavaType kjt) { - super(name, dimension, prefix); + super(name, annotations, dimension, prefix); this.kjt = kjt; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReference.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReference.java index e28114bea09..9c4472cee03 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReference.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReference.java @@ -3,11 +3,12 @@ * SPDX-License-Identifier: GPL-2.0-only */ package de.uka.ilkd.key.java.ast.reference; -import de.uka.ilkd.key.java.ast.NonTerminalProgramElement; -import de.uka.ilkd.key.java.ast.SourceElement; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.logic.ProgramElementName; +import org.key_project.util.collection.ImmutableArray; + /** * TypeReferences reference Types by name. A TypeReference can refer to * an outer or inner type and hence can also be a {@link MemberReference}, but does not have to. A @@ -16,7 +17,7 @@ * {@link TypeReferenceContainer}. */ public interface TypeReference extends TypeReferenceInfix, TypeReferenceContainer, - PackageReferenceContainer, MemberReference, NonTerminalProgramElement, SourceElement { + PackageReferenceContainer, MemberReference { String getName(); @@ -27,4 +28,6 @@ public interface TypeReference extends TypeReferenceInfix, TypeReferenceContaine int getDimensions(); KeYJavaType getKeYJavaType(); + + ImmutableArray getAnnotations(); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReferenceImp.java b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReferenceImp.java index a0d4f71f143..c50ffad716f 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReferenceImp.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/ast/reference/TypeReferenceImp.java @@ -5,12 +5,14 @@ import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.visitor.Visitor; import de.uka.ilkd.key.logic.ProgramElementName; import de.uka.ilkd.key.rule.MatchConditions; import org.key_project.util.ExtList; +import org.key_project.util.collection.ImmutableArray; /** * TypeReferences reference Types by name. A TypeReference can refer to @@ -23,7 +25,6 @@ public abstract class TypeReferenceImp extends JavaNonTerminalProgramElement implements TypeReference { - /** * Prefix. */ @@ -39,6 +40,11 @@ public abstract class TypeReferenceImp extends JavaNonTerminalProgramElement */ protected final ProgramElementName name; + /** + * Annotations. + */ + protected final ImmutableArray annotations; + /** * Constructor for the transformation of RECODER ASTs to KeY. @@ -54,21 +60,28 @@ protected TypeReferenceImp(ExtList children, int dim) { super(children); prefix = children.get(ReferencePrefix.class); name = children.get(ProgramElementName.class); + annotations = new ImmutableArray<>( + children.collect(Annotation.class)); dimensions = dim; } protected TypeReferenceImp(ProgramElementName name) { - this(name, 0, null); + this(name, new ImmutableArray<>(), 0, null); } - protected TypeReferenceImp(ProgramElementName name, int dimension, ReferencePrefix prefix) { + protected TypeReferenceImp( + ProgramElementName name, + ImmutableArray annotations, + int dimension, + ReferencePrefix prefix) { this.name = name; + this.annotations = annotations; this.dimensions = dimension; this.prefix = prefix; } - + @Override public SourceElement getFirstElement() { return (prefix == null) ? name : prefix.getFirstElement(); } @@ -83,6 +96,7 @@ public SourceElement getFirstElementIncludingBlocks() { * * @return an int giving the number of children of this node */ + @Override public int getChildCount() { int result = 0; if (prefix != null) { @@ -103,6 +117,7 @@ public int getChildCount() { * @exception ArrayIndexOutOfBoundsException * if index is out of bounds */ + @Override public ProgramElement getChildAt(int index) { if (prefix != null) { if (index == 0) { @@ -118,11 +133,17 @@ public ProgramElement getChildAt(int index) { throw new ArrayIndexOutOfBoundsException(); } + @Override + public ImmutableArray getAnnotations() { + return annotations; + } + /** * Get the number of type references in this container. * * @return the number of type references. */ + @Override public int getTypeReferenceCount() { return (prefix instanceof TypeReference) ? 1 : 0; } @@ -137,6 +158,7 @@ public int getTypeReferenceCount() { * * @exception ArrayIndexOutOfBoundsException if index is out of bounds. */ + @Override public TypeReference getTypeReferenceAt(int index) { if (prefix instanceof TypeReference && index == 0) { return (TypeReference) prefix; @@ -149,6 +171,7 @@ public TypeReference getTypeReferenceAt(int index) { * * @return the number of expressions. */ + @Override public int getExpressionCount() { return (prefix instanceof Expression) ? 1 : 0; } @@ -162,6 +185,7 @@ public int getExpressionCount() { * * @exception ArrayIndexOutOfBoundsException if index is out of bounds. */ + @Override public Expression getExpressionAt(int index) { if (prefix instanceof Expression && index == 0) { return (Expression) prefix; @@ -174,6 +198,7 @@ public Expression getExpressionAt(int index) { * * @return the reference prefix. */ + @Override public ReferencePrefix getReferencePrefix() { return prefix; } @@ -183,6 +208,7 @@ public ReferencePrefix getReferencePrefix() { * * @return the package reference. */ + @Override public PackageReference getPackageReference() { return (prefix instanceof PackageReference) ? (PackageReference) prefix : null; } @@ -192,6 +218,7 @@ public PackageReference getPackageReference() { * * @return the int value. */ + @Override public int getDimensions() { return dimensions; } @@ -201,10 +228,12 @@ public int getDimensions() { * * @return the string. */ + @Override public final String getName() { return (name == null) ? null : name.toString(); } + @Override public abstract KeYJavaType getKeYJavaType(); /** @@ -212,12 +241,11 @@ public final String getName() { * * @return the identifier. */ - + @Override public ProgramElementName getProgramElementName() { return name; } - /** * calls the corresponding method of a visitor in order to perform some action/transformation on * this element @@ -225,11 +253,12 @@ public ProgramElementName getProgramElementName() { * @param v * the Visitor */ + @Override public void visit(Visitor v) { v.performActionOnTypeReference(this); } - + @Override public MatchConditions match(SourceData source, MatchConditions matchCond) { final ProgramElement pe = source.getSource(); if (!(pe instanceof TypeReference) diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/loader/CreateArrayMethodBuilder.java b/key.core/src/main/java/de/uka/ilkd/key/java/loader/CreateArrayMethodBuilder.java index 7275fe5f2b0..f3baf580794 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/loader/CreateArrayMethodBuilder.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/loader/CreateArrayMethodBuilder.java @@ -52,12 +52,16 @@ import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableSLList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This class creates the <createArray> method for array creation and in * particular its helper method <createArrayHelper>. This class should be * replaced by a recoder transformation as soon as we port our array data structures to RecodeR. */ public final class CreateArrayMethodBuilder extends KeYJavaASTFactory { + public static final Logger LOGGER = LoggerFactory.getLogger(CreateArrayMethodBuilder.class); public static final String IMPLICIT_ARRAY_CREATE = "$createArray"; @@ -71,7 +75,7 @@ public final class CreateArrayMethodBuilder extends KeYJavaASTFactory { /** * keeps the currently used integer type */ - private final KeYJavaType integerType; + private final TypeReference integerType; /** * stores the currently used object type @@ -87,7 +91,7 @@ public final class CreateArrayMethodBuilder extends KeYJavaASTFactory { /** create the method builder for array implict creation methods */ public CreateArrayMethodBuilder(KeYJavaType integerType, KeYJavaType objectType, Sort heapSort, int heapCount) { - this.integerType = integerType; + this.integerType = new TypeRef(integerType); this.objectType = objectType; this.heapSort = heapSort; this.heapCount = heapCount; @@ -218,7 +222,7 @@ public IProgramMethod getArrayInstanceAllocatorMethod(TypeReference arrayTypeRef new LocationVariable(new ProgramElementName("length"), integerType, true); final ParameterDeclaration param = new ParameterDeclaration(new Modifier[0], - new TypeRef(integerType), new VariableSpecification(paramLength), false); + integerType, new VariableSpecification(paramLength), false); final MethodDeclaration md = new MethodDeclaration(modifiers, arrayTypeReference, new ProgramElementName(PipelineConstants.IMPLICIT_INSTANCE_ALLOCATE), @@ -341,7 +345,7 @@ public IProgramMethod getCreateArrayMethod(TypeReference arrayTypeReference, new LocationVariable(new ProgramElementName("length"), integerType); final ParameterDeclaration param = new ParameterDeclaration(new Modifier[0], - new TypeRef(integerType), new VariableSpecification(paramLength), false); + integerType, new VariableSpecification(paramLength), false); final MethodDeclaration md = new MethodDeclaration(modifiers, arrayTypeReference, new ProgramElementName(IMPLICIT_ARRAY_CREATE), new ParameterDeclaration[] { param }, diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYConverter.java b/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYConverter.java index 0820a14a8d2..6381dc0ee02 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYConverter.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYConverter.java @@ -21,6 +21,7 @@ import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.expression.ParenthesizedExpression; import de.uka.ilkd.key.java.ast.expression.PassiveExpression; +import de.uka.ilkd.key.java.ast.annotation.MarkerAnnotation; import de.uka.ilkd.key.java.ast.expression.literal.*; import de.uka.ilkd.key.java.ast.expression.operator.*; import de.uka.ilkd.key.java.ast.expression.operator.adt.*; @@ -29,6 +30,7 @@ import de.uka.ilkd.key.java.transformations.ConstantExpressionEvaluator; import de.uka.ilkd.key.java.transformations.EvaluationException; import de.uka.ilkd.key.java.transformations.MarkerStatementHelper; +import de.uka.ilkd.key.java.transformations.pipeline.AnnotationInterfaceDeclarationNode; import de.uka.ilkd.key.java.transformations.pipeline.JMLTransformer; import de.uka.ilkd.key.ldt.HeapLDT; import de.uka.ilkd.key.ldt.JavaDLTheory; @@ -72,7 +74,6 @@ import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration; import com.github.javaparser.resolution.model.typesystem.ReferenceTypeImpl; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.resolution.types.ResolvedVoidType; import com.github.javaparser.symbolsolver.JavaSymbolSolver; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserVariableDeclaration; @@ -346,9 +347,12 @@ public Object visit(ClassOrInterfaceDeclaration n, Void arg) { Extends extending = new Extends(e); Implements implementing = new Implements(i); - TypeDeclaration td; - if (n.isInterface()) { + if (n instanceof AnnotationInterfaceDeclarationNode) { + td = new AnnotationInterfaceDeclaration( + pi, c, modArray, name, fullName, members, + parentIsInterface, isLibrary, getClassSpec(n)); + } else if (n.isInterface()) { td = new InterfaceDeclaration( pi, c, modArray, name, fullName, members, parentIsInterface, isLibrary, extending, getClassSpec(n)); @@ -707,8 +711,7 @@ public Object visit(FieldAccessExpr n, Void arg) { } } catch (UnsolvedSymbolException e) { try { - ResolvedType type = n.calculateResolvedType(); - var keyType = getKeYJavaType(type); + var keyType = getKeYJavaType(n.calculateResolvedType()); return new TypeRef(keyType); } catch (UnsolvedSymbolException e1) { throw new ParserException("Name could not be resolved '" + n + "'", @@ -719,14 +722,12 @@ public Object visit(FieldAccessExpr n, Void arg) { @Override public Object visit(TypeExpr n, Void arg) { - var rt = n.calculateResolvedType(); - var kjt = getKeYJavaType(rt); - return new TypeRef(kjt); + return new TypeRef(getKeYJavaType(n.getType().resolve()), map(n.getType().getAnnotations()), + 0); } - private KeYJavaType getCachedKeYJavaType(ResolvedType rtype) { - return typeConverter.getKeYJavaType(rtype, true); + return typeConverter.getKeYJavaType(rtype, false); } private KeYJavaType getKeYJavaType(ResolvedType rtype) { @@ -1008,8 +1009,7 @@ public Object visit(NameExpr n, Void arg) { target = n.resolve(); } catch (UnsolvedSymbolException e) { try { - ResolvedType type = n.calculateResolvedType(); - var keyType = getKeYJavaType(type); + var keyType = getKeYJavaType(n.calculateResolvedType()); return new TypeRef(keyType); } catch (UnsolvedSymbolException e1) { throw new ParserException("Name could not be resolved '" + n + "'", @@ -1139,8 +1139,8 @@ private static ReferencePrefix convertScopeToReferencePrefix(ClassOrInterfaceTyp ReferencePrefix prefix = type.getScope().map(JP2KeYVisitor::convertScopeToReferencePrefix).orElse(null); var name = createProgramElementName(type.getName()); - var resolvedType = getKeYJavaType(type.resolve()); - return new TypeRef(name, 0, prefix, resolvedType); + KeYJavaType resolvedType = getKeYJavaType(type.resolve()); + return new TypeRef(name, map(type.getAnnotations()), 0, prefix, resolvedType); } private ParameterDeclaration visitNoMap(Parameter n) { @@ -1163,7 +1163,7 @@ private ParameterDeclaration visitNoMap(Parameter n) { pv = (IProgramVariable) lookupSchemaVariable(n.getName()); } else { var name = VariableNamer.parseName(n.getName().asString()); - pv = new LocationVariable(name, type.getKeYJavaType(), n.isFinal()); + pv = new LocationVariable(name, type, n.isFinal()); } var spec = new VariableSpecification(pi, c, null, pv, 0, type.getKeYJavaType()); var isInInterface = parentIsInterface(n); @@ -1179,7 +1179,7 @@ public Object visit(Parameter n, Void arg) { @Override public TypeReference visit(PrimitiveType n, Void arg) { - return new TypeRef(getKeYJavaType(n.resolve())); + return new TypeRef(getKeYJavaType(n.resolve()), map(n.getAnnotations()), 0); } @Override @@ -1204,7 +1204,7 @@ public Object visit(ArrayType n, Void arg) { } catch (IllegalStateException e) { System.out.println(e); } - return new TypeRef(getKeYJavaType(n.resolve())); + return new TypeRef(getKeYJavaType(n.resolve()), map(n.getAnnotations()), 0); } @Override @@ -1387,16 +1387,16 @@ private VariableSpecification visitVariableSpecification(TypeReference type, var c = createComments(v); Expression init = accepto(v.getInitializer()); IProgramVariable pv; - KeYJavaType kjt = type.getKeYJavaType(); if (v.getNameAsString().startsWith("#")) { pv = (IProgramVariable) lookupSchemaVariable(v.getNameAsString(), v); } else { var name = VariableNamer.parseName(v.getNameAsString()); - pv = new LocationVariable(name, kjt, modifiers.hasModifier(JML_GHOST), + pv = new LocationVariable(name, type, modifiers.hasModifier(JML_GHOST), modifiers.hasModifier(FINAL)); } - return addToMapping(v, new VariableSpecification(pi, c, init, pv, 0, kjt)); + return addToMapping(v, + new VariableSpecification(pi, c, init, pv, 0, type.getKeYJavaType())); } /** @@ -1471,7 +1471,7 @@ private ProgramVariable getProgramVariableForFieldSpecification(FullVariableDecl var spec = decl.decl; var varSpec = mapping.nodeToKeY(spec); if (varSpec == null) { - var t = spec.getType().resolve(); + var t = spec.getType(); var classNode = findContainingClass(spec).orElseThrow(); var classType = new ReferenceTypeImpl(classNode.resolve()); final ProgramElementName pen = @@ -1481,11 +1481,11 @@ private ProgramVariable getProgramVariableForFieldSpecification(FullVariableDecl final Literal compileTimeConstant = getCompileTimeConstantInitializer(decl); if (compileTimeConstant == null) { - pv = new LocationVariable(pen, getKeYJavaType(t), + pv = new LocationVariable(pen, accept(t), getKeYJavaType(classType), decl.isStatic, decl.isModel, decl.isGhost, decl.isFinal); } else { - pv = new ProgramConstant(pen, getKeYJavaType(t), + pv = new ProgramConstant(pen, accept(t), getKeYJavaType(classType), decl.isStatic, compileTimeConstant); } @@ -1515,8 +1515,8 @@ private FieldSpecification visitFieldSpecification(FullVariableDeclarator v) { var pi = createPositionInfo(v.decl); var c = createComments(v.decl); Expression init = accepto(v.decl.getInitializer()); - var type = getKeYJavaType(v.decl.getType().resolve()); var pv = getProgramVariableForFieldSpecification(v); + KeYJavaType type = ((TypeReference)accept(v.decl.getType())).getKeYJavaType(); return new FieldSpecification(pi, c, init, pv, 0, type); } @@ -1528,7 +1528,7 @@ public Object visit(VariableDeclarator n, Void arg) { @Override public Object visit(VoidType n, Void arg) { - return new TypeRef(getKeYJavaType(ResolvedVoidType.INSTANCE)); + return new TypeRef(getKeYJavaType(n.resolve()), map(n.annotations()), 0); } @Override @@ -1560,8 +1560,7 @@ public Object visit(ImportDeclaration n, Void arg) { // TODO: is the lookup correct? Seems to work in small examples ... String typename = n.getName().asString(); KeYJavaType kjt = typeConverter.getKeYJavaType(typename); - TypeReference typeRef = new TypeRef(kjt); - return new Import(typeRef, n.isAsterisk(), pi, c); + return new Import(new TypeRef(kjt), n.isAsterisk(), pi, c); } } @@ -2092,7 +2091,7 @@ public Object visit(TraditionalJavadocComment n, Void arg) { @Override public Object visit(MarkerAnnotationExpr n, Void arg) { - return reportUnsupportedElement(n); + return new MarkerAnnotation(n.getNameAsString()); } @Override @@ -2158,7 +2157,7 @@ public Object visit(ReceiverParameter n, Void arg) { @Override public Object visit(VarType n, Void arg) { - return getKeYJavaType(n.resolve()); + return new TypeRef(getKeYJavaType(n.resolve()), map(n.getAnnotations()), 0); } @Override diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYTypeConverter.java b/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYTypeConverter.java index 278ced1684e..f936c1696ab 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYTypeConverter.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/loader/JP2KeYTypeConverter.java @@ -183,7 +183,6 @@ public KeYJavaType createKeYJavaType(ReferenceTypeImpl ref) { return getObjectType(); } - { // lookup in the cache var kjt = jp2KeY.resolvedTypeToKeY(type, services.getJavaService()); @@ -398,6 +397,7 @@ private ArrayDeclaration createArrayType(KeYJavaType baseType, KeYJavaType array baseTypeRef = new TypeRef(baseType); } else { baseTypeRef = new TypeRef(new ProgramElementName(baseType.getSort().name().toString()), + new ImmutableArray<>(), 0, null, baseType); } @@ -421,7 +421,7 @@ private KeYJavaType createSuperArrayType() { var superArrayType = new KeYJavaType(); var specLength = new FieldSpecification(new LocationVariable(new ProgramElementName("length"), - integerType, superArrayType, false, false, false, true)); + new TypeRef(integerType), superArrayType, false, false, false, true)); var f = new FieldDeclaration(new Modifier[] { new Public(), new Final() }, new TypeRef(integerType), new FieldSpecification[] { specLength }, false); superArrayType.setJavaType(new SuperArrayDeclaration(f)); @@ -442,7 +442,7 @@ private void addImplicitArrayMembers(ExtList members, KeYJavaType parent, KeYJav int dimension = base instanceof ArrayType ? ((ArrayType) base).getDimension() + 1 : 1; TypeRef parentReference = new TypeRef(new ProgramElementName(String.valueOf(parent.getSort().name())), - dimension, null, parent); + new ImmutableArray<>(), dimension, null, parent); // add methods // the only situation where base can be null is in case of a diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/transformations/KeYJavaPipeline.java b/key.core/src/main/java/de/uka/ilkd/key/java/transformations/KeYJavaPipeline.java index a5fd03e0dcd..232ef860d82 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/transformations/KeYJavaPipeline.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/transformations/KeYJavaPipeline.java @@ -40,6 +40,7 @@ public static KeYJavaPipeline createDefault(TransformationPipelineServices pipel KeYJavaPipeline p = new KeYJavaPipeline(pipelineServices); p.add(new TextblockTransformer()); p.add(new EnumClassBuilder(pipelineServices)); + p.add(new AnnotationInterfaceBuilder(pipelineServices)); p.add(new RecordClassBuilder(pipelineServices)); p.add(new JMLTransformer(pipelineServices)); p.add(new JmlDocRemoval(pipelineServices)); diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/transformations/pipeline/AnnotationInterfaceBuilder.java b/key.core/src/main/java/de/uka/ilkd/key/java/transformations/pipeline/AnnotationInterfaceBuilder.java new file mode 100644 index 00000000000..0138a90a6cd --- /dev/null +++ b/key.core/src/main/java/de/uka/ilkd/key/java/transformations/pipeline/AnnotationInterfaceBuilder.java @@ -0,0 +1,38 @@ +/* This file is part of KeY - https://key-project.org + * KeY is licensed under the GNU General Public License Version 2 + * SPDX-License-Identifier: GPL-2.0-only */ +package de.uka.ilkd.key.java.transformations.pipeline; + +import java.util.LinkedHashMap; +import java.util.Map; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.body.AnnotationDeclaration; + +/** + * This class converts {@link AnnotationDeclaration}s to + * {@link AnnotationInterfaceDeclaration}s + * + * @author PiIsRational + */ +public class AnnotationInterfaceBuilder extends JavaTransformerAbstract { + /** + * a mapping of {@link AnnotationDeclarations} to + * {@link AnnotationInterfaceDeclarations} */ + final Map substitutes = new LinkedHashMap<>(); + + public AnnotationInterfaceBuilder( + TransformationPipelineServices pipelineServices) { + super(pipelineServices); + } + + @Override + public void apply(CompilationUnit cu) { + cu.walk(AnnotationDeclaration.class, it -> { + substitutes.put(it, new AnnotationInterfaceDeclarationNode(it)); + }); + for (var e : substitutes.entrySet()) { + e.getKey().replace(e.getValue()); + } + } +} diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/transformations/pipeline/AnnotationInterfaceDeclarationNode.java b/key.core/src/main/java/de/uka/ilkd/key/java/transformations/pipeline/AnnotationInterfaceDeclarationNode.java new file mode 100644 index 00000000000..e7c9d4a824e --- /dev/null +++ b/key.core/src/main/java/de/uka/ilkd/key/java/transformations/pipeline/AnnotationInterfaceDeclarationNode.java @@ -0,0 +1,47 @@ +/* This file is part of KeY - https://key-project.org + * KeY is licensed under the GNU General Public License Version 2 + * SPDX-License-Identifier: GPL-2.0-only */ +package de.uka.ilkd.key.java.transformations.pipeline; + +import com.github.javaparser.ast.Modifier; +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.body.*; +import com.github.javaparser.ast.expr.*; + +/** + * This class is used to have a more or less equivalent representation of an annotation + * interface declaration as an interface declaration. + * + * @author PiIsRational + */ +public class AnnotationInterfaceDeclarationNode extends ClassOrInterfaceDeclaration { + + public AnnotationInterfaceDeclarationNode() { + super(); + } + + public AnnotationInterfaceDeclarationNode(AnnotationDeclaration ad) { + setName(ad.getName().clone()); + + var modifiers = new NodeList(); + for (var m : ad.modifiers()) { + modifiers.add(m.clone()); + } + setModifiers(modifiers); + setInterface(true); + + var annotations = new NodeList(); + for (var annot : ad.annotations()) { + annotations.add(annot.clone()); + } + setAnnotations(annotations); + + if (ad.getComment().isPresent()) { + setComment(ad.getComment().get().clone()); + } + + for (var m : ad.members()) { + addMember(m.clone()); + } + } +} diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/visitor/JavaASTVisitor.java b/key.core/src/main/java/de/uka/ilkd/key/java/visitor/JavaASTVisitor.java index fb6a24e4824..7a46da00a45 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/visitor/JavaASTVisitor.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/visitor/JavaASTVisitor.java @@ -7,6 +7,7 @@ import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.ccatch.*; import de.uka.ilkd.key.java.ast.declaration.*; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.ArrayInitializer; import de.uka.ilkd.key.java.ast.expression.ParenthesizedExpression; import de.uka.ilkd.key.java.ast.expression.PassiveExpression; @@ -468,6 +469,11 @@ public void performActionOnInterfaceDeclaration(InterfaceDeclaration x) { doDefaultAction(x); } + @Override + public void performActionOnAnnotationInterfaceDeclaration(AnnotationInterfaceDeclaration x) { + doDefaultAction(x); + } + @Override public void performActionOnIntLiteral(IntLiteral x) { doDefaultAction(x); @@ -626,6 +632,11 @@ public void performActionOnParenthesizedExpression(ParenthesizedExpression x) { doDefaultAction(x); } + @Override + public void performActionOnAnnotation(Annotation x) { + doDefaultAction(x); + } + @Override public void performActionOnPassiveExpression(PassiveExpression x) { doDefaultAction(x); diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/visitor/OuterBreakContinueAndReturnReplacer.java b/key.core/src/main/java/de/uka/ilkd/key/java/visitor/OuterBreakContinueAndReturnReplacer.java index 1890954ca7a..3f10903b512 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/visitor/OuterBreakContinueAndReturnReplacer.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/visitor/OuterBreakContinueAndReturnReplacer.java @@ -448,7 +448,7 @@ public void performActionOnFinally(final Finally x) { // Remember current flags. for (Entry entry : oldFlags.entrySet()) { newStatements.add(KeYJavaASTFactory.declare(entry.getValue(), entry.getKey(), - entry.getValue().getKeYJavaType())); + entry.getValue().getTypeReference())); } // Reset flags. @@ -479,7 +479,7 @@ private void addOldFlag(Map oldFlags, ProgramV new LocationVariable( new ProgramElementName( flag.getProgramElementName().toString() + "__BEFORE_FINALLY"), - flag.getKeYJavaType())); + flag.getTypeReference())); } private void changed() { diff --git a/key.core/src/main/java/de/uka/ilkd/key/java/visitor/Visitor.java b/key.core/src/main/java/de/uka/ilkd/key/java/visitor/Visitor.java index e5299c49298..f2f92b3d9e0 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/java/visitor/Visitor.java +++ b/key.core/src/main/java/de/uka/ilkd/key/java/visitor/Visitor.java @@ -6,6 +6,7 @@ import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.ccatch.*; import de.uka.ilkd.key.java.ast.declaration.*; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.ArrayInitializer; import de.uka.ilkd.key.java.ast.expression.ParenthesizedExpression; import de.uka.ilkd.key.java.ast.expression.PassiveExpression; @@ -118,6 +119,8 @@ public interface Visitor { void performActionOnInterfaceDeclaration(InterfaceDeclaration x); + void performActionOnAnnotationInterfaceDeclaration(AnnotationInterfaceDeclaration x); + void performActionOnFieldDeclaration(FieldDeclaration x); void performActionOnLocalVariableDeclaration(LocalVariableDeclaration x); @@ -326,6 +329,8 @@ public interface Visitor { void performActionOnLoopInit(LoopInit x); + void performActionOnAnnotation(Annotation annot); + void performActionOnAssert(Assert assert1); void performActionOnProgramConstant(ProgramConstant constant); diff --git a/key.core/src/main/java/de/uka/ilkd/key/ldt/JavaDLTheory.java b/key.core/src/main/java/de/uka/ilkd/key/ldt/JavaDLTheory.java index 3f841bfd2a5..84592744eed 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/ldt/JavaDLTheory.java +++ b/key.core/src/main/java/de/uka/ilkd/key/ldt/JavaDLTheory.java @@ -23,7 +23,7 @@ import org.key_project.util.collection.ImmutableList; /** - * The JavaDL theory class provides access to function symvols, sorts that are part of the core + * The JavaDL theory class provides access to function symbols, sorts that are part of the core * logic * like cast or instanceof functions. */ diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/InnerVariableNamer.java b/key.core/src/main/java/de/uka/ilkd/key/logic/InnerVariableNamer.java index eb0edc7087c..f3fb7ee33a2 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/InnerVariableNamer.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/InnerVariableNamer.java @@ -69,7 +69,7 @@ public LocationVariable rename(LocationVariable var, Goal goal, PosInOccurrence LocationVariable newvar = var; if (!newname.equals(name)) { - newvar = new LocationVariable(newname, var.getKeYJavaType()); + newvar = new LocationVariable(newname, var.getTypeReference()); map.put(var, newvar); renamingHistory = map; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/TermBuilder.java b/key.core/src/main/java/de/uka/ilkd/key/logic/TermBuilder.java index f9b363ee86a..5362261e244 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/TermBuilder.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/TermBuilder.java @@ -12,6 +12,8 @@ import de.uka.ilkd.key.java.TypeConverter; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.abstraction.PrimitiveType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.ldt.*; import de.uka.ilkd.key.logic.label.OriginTermLabel; import de.uka.ilkd.key.logic.label.OriginTermLabelFactory; @@ -38,6 +40,8 @@ import org.key_project.logic.sort.Sort; import org.key_project.util.collection.*; +import static de.uka.ilkd.key.java.KeYJavaASTFactory.typeRef; + /** *

* Use this class if you intend to build complex terms by hand. It is more convenient than @@ -183,38 +187,40 @@ public String newName(Sort sort) { /** * Creates a program variable for "self". Take care to register it in the namespaces! */ - public LocationVariable selfVar(KeYJavaType kjt, boolean makeNameUnique) { - return selfVar(kjt, makeNameUnique, ""); + public LocationVariable selfVar(TypeReference typeRef, boolean makeNameUnique) { + return selfVar(typeRef, makeNameUnique, ""); } /** * Creates a program variable for "self". Take care to register it in the namespaces! */ - public LocationVariable selfVar(KeYJavaType kjt, boolean makeNameUnique, String postfix) { + public LocationVariable selfVar(TypeReference typeRef, boolean makeNameUnique, String postfix) { String name = "self" + postfix; - return locationVariable(name, kjt, makeNameUnique); + return locationVariable(name, typeRef, makeNameUnique); } /** * Creates a program variable for "self". Take care to register it in the namespaces! */ - public LocationVariable selfVar(IProgramMethod pm, KeYJavaType kjt, boolean makeNameUnique, + public LocationVariable selfVar(IProgramMethod pm, TypeReference typeRef, + boolean makeNameUnique, String postfix) { if (pm.isStatic()) { return null; } else { - return selfVar(kjt, makeNameUnique, postfix); + return selfVar(typeRef, makeNameUnique, postfix); } } /** * Creates a program variable for "self". Take care to register it in the namespaces! */ - public LocationVariable selfVar(IProgramMethod pm, KeYJavaType kjt, boolean makeNameUnique) { + public LocationVariable selfVar(IProgramMethod pm, TypeReference typeRef, + boolean makeNameUnique) { if (pm.isStatic()) { return null; } else { - return selfVar(kjt, makeNameUnique); + return selfVar(typeRef, makeNameUnique); } } @@ -233,7 +239,8 @@ public ImmutableList paramVars(IObserverFunction obs, } else { name = String.valueOf(paramType.getSort().name().toString().charAt(0)); } - final LocationVariable paramVar = locationVariable(name, paramType, makeNamesUnique); + final LocationVariable paramVar = + locationVariable(name, new TypeRef(paramType), makeNamesUnique); result = result.append(paramVar); } return result; @@ -248,7 +255,8 @@ public ImmutableList paramVars(String postfix, IObserverFuncti ImmutableList result = ImmutableSLList.nil(); for (LocationVariable paramVar : paramVars) { ProgramElementName pen = new ProgramElementName(paramVar.name() + postfix); - LocationVariable formalParamVar = new LocationVariable(pen, paramVar.getKeYJavaType()); + LocationVariable formalParamVar = + new LocationVariable(pen, paramVar.getTypeReference()); result = result.append(formalParamVar); } return result; @@ -270,7 +278,7 @@ public LocationVariable resultVar(String name, IProgramMethod pm, boolean makeNa return null; } else { name += "_" + pm.getName(); - return locationVariable(name, pm.getReturnType(), makeNameUnique); + return locationVariable(name, new TypeRef(pm.getReturnType()), makeNameUnique); } } @@ -288,7 +296,8 @@ public LocationVariable excVar(IProgramMethod pm, boolean makeNameUnique) { */ public LocationVariable excVar(String name, IProgramMethod pm, boolean makeNameUnique) { return locationVariable(name, - services.getJavaInfo().getTypeByClassName(JAVA_LANG_THROWABLE), makeNameUnique); + new TypeRef(services.getJavaInfo().getTypeByClassName(JAVA_LANG_THROWABLE)), + makeNameUnique); } /** @@ -313,7 +322,7 @@ public LocationVariable atPreVar(String baseName, Sort sort, boolean makeNameUni if (kjt == null) { kjt = new KeYJavaType(sort); } - return atPreVar(baseName, kjt, makeNameUnique); + return atPreVar(baseName, new TypeRef(kjt), makeNameUnique); } /** @@ -321,12 +330,13 @@ public LocationVariable atPreVar(String baseName, Sort sort, boolean makeNameUni * namespaces. * * @param baseName the base name to use - * @param kjt the type of the variable + * @param typeRef the type of the variable * @param makeNameUnique whether to change the base name to be unique * @return a location variable for the given name and type */ - public LocationVariable atPreVar(String baseName, KeYJavaType kjt, boolean makeNameUnique) { - return locationVariable(baseName + "AtPre", kjt, makeNameUnique); + public LocationVariable atPreVar(String baseName, TypeReference typeRef, + boolean makeNameUnique) { + return locationVariable(baseName + "AtPre", typeRef, makeNameUnique); } /** @@ -339,7 +349,7 @@ public LocationVariable atPreVar(String baseName, KeYJavaType kjt, boolean makeN * @return a location variable for the given name and type */ public LocationVariable locationVariable(String baseName, Sort sort, boolean makeNameUnique) { - return locationVariable(baseName, new KeYJavaType(sort), makeNameUnique); + return locationVariable(baseName, new TypeRef(new KeYJavaType(sort)), makeNameUnique); } /** @@ -347,16 +357,16 @@ public LocationVariable locationVariable(String baseName, Sort sort, boolean mak * the namespaces. * * @param baseName the base name to use - * @param kjt the type of the variable + * @param typeRef the type of the variable * @param makeNameUnique whether to change the base name to be unique * @return a location variable for the given name and type */ - public LocationVariable locationVariable(String baseName, KeYJavaType kjt, + public LocationVariable locationVariable(String baseName, TypeReference typeRef, boolean makeNameUnique) { if (makeNameUnique) { baseName = newName(baseName); } - return new LocationVariable(new ProgramElementName(baseName), kjt); + return new LocationVariable(new ProgramElementName(baseName), typeRef); } // ------------------------------------------------------------------------- diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/IProgramVariable.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/IProgramVariable.java index 68c4d837564..a6726f5fc6c 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/IProgramVariable.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/IProgramVariable.java @@ -7,16 +7,17 @@ import de.uka.ilkd.key.java.ast.TerminalProgramElement; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; +import de.uka.ilkd.key.java.ast.reference.TypeReference; -import org.key_project.logic.op.Operator; import org.key_project.logic.op.SortedOperator; - public interface IProgramVariable - extends TerminalProgramElement, SortedOperator, Operator { + extends TerminalProgramElement, SortedOperator { KeYJavaType getKeYJavaType(); KeYJavaType getKeYJavaType(Services javaServ); KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec); + + TypeReference getTypeReference(); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/JAbstractSortedOperator.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/JAbstractSortedOperator.java index 3375c5108fe..15917981e89 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/JAbstractSortedOperator.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/JAbstractSortedOperator.java @@ -11,7 +11,6 @@ import org.key_project.logic.TermCreationException; import org.key_project.logic.op.AbstractSortedOperator; import org.key_project.logic.op.Modifier; -import org.key_project.logic.op.Operator; import org.key_project.logic.sort.Sort; import org.key_project.util.collection.ImmutableArray; @@ -20,7 +19,7 @@ * Abstract sorted operator class offering some common functionality. */ public abstract class JAbstractSortedOperator extends AbstractSortedOperator - implements Sorted, Operator { + implements Sorted { protected JAbstractSortedOperator(Name name, ImmutableArray argSorts, Sort sort, ImmutableArray whereToBind, Modifier modifier) { diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/JOperatorSV.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/JOperatorSV.java index 98ecfdfd983..b8ae89c1f07 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/JOperatorSV.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/JOperatorSV.java @@ -4,11 +4,9 @@ package de.uka.ilkd.key.logic.op; import org.key_project.logic.Name; -import org.key_project.logic.Named; import org.key_project.logic.Term; import org.key_project.logic.TermCreationException; import org.key_project.logic.op.sv.OperatorSV; -import org.key_project.logic.op.sv.SchemaVariable; import org.key_project.logic.sort.Sort; import org.key_project.util.collection.ImmutableArray; @@ -16,7 +14,7 @@ * Abstract base class for schema variables. */ public abstract class JOperatorSV extends JAbstractSortedOperator - implements OperatorSV, SchemaVariable, Named { + implements OperatorSV { private final boolean isStrict; diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/LocationVariable.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/LocationVariable.java index 3406cbc3ac1..57bfadc61a3 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/LocationVariable.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/LocationVariable.java @@ -5,6 +5,7 @@ import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.visitor.Visitor; import de.uka.ilkd.key.logic.ProgramElementName; @@ -16,29 +17,30 @@ * description of the superclass ProgramVariable for more information. */ public final class LocationVariable extends ProgramVariable implements UpdateableOperator { - public LocationVariable(ProgramElementName name, KeYJavaType t, KeYJavaType containingType, + public LocationVariable(ProgramElementName name, TypeReference t, KeYJavaType containingType, boolean isStatic, boolean isModel, boolean isGhost, boolean isFinal) { - super(name, t.getSort(), t, containingType, isStatic, isModel, isGhost, isFinal); + super(name, t.getKeYJavaType().getSort(), t, containingType, isStatic, isModel, isGhost, + isFinal); } - public LocationVariable(ProgramElementName name, KeYJavaType t, KeYJavaType containingType, + public LocationVariable(ProgramElementName name, TypeReference t, KeYJavaType containingType, boolean isStatic, boolean isModel) { - super(name, t.getSort(), t, containingType, isStatic, isModel, false); + super(name, t.getKeYJavaType().getSort(), t, containingType, isStatic, isModel, false); } - public LocationVariable(ProgramElementName name, KeYJavaType t) { - super(name, t.getSort(), t, null, false, false, false); + public LocationVariable(ProgramElementName name, TypeReference t) { + super(name, t.getKeYJavaType().getSort(), t, null, false, false, false); } - public LocationVariable(ProgramElementName name, KeYJavaType t, boolean isFinal) { - super(name, t.getSort(), t, null, false, false, false, isFinal); + public LocationVariable(ProgramElementName name, TypeReference t, boolean isFinal) { + super(name, t.getKeYJavaType().getSort(), t, null, false, false, false, isFinal); } - public LocationVariable(ProgramElementName name, KeYJavaType t, boolean isGhost, + public LocationVariable(ProgramElementName name, TypeReference t, boolean isGhost, boolean isFinal) { - super(name, t.getSort(), t, null, false, false, isGhost, isFinal); + super(name, t.getKeYJavaType().getSort(), t, null, false, false, isGhost, isFinal); } @@ -61,7 +63,7 @@ public void visit(Visitor v) { */ public static LocationVariable fromProgramVariable(ProgramVariable variable, ProgramElementName name) { - return new LocationVariable(name, variable.getKeYJavaType(), variable.getContainerType(), + return new LocationVariable(name, variable.getTypeReference(), variable.getContainerType(), variable.isStatic(), variable.isModel(), variable.isGhost(), variable.isFinal()); } } diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramConstant.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramConstant.java index e07d49745ca..de2dc97452e 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramConstant.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramConstant.java @@ -5,6 +5,7 @@ import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.expression.literal.Literal; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.visitor.Visitor; import de.uka.ilkd.key.logic.ProgramElementName; @@ -19,13 +20,12 @@ public final class ProgramConstant extends ProgramVariable { // a compile-time constant, null otherwise private final Literal compileTimeConstant; - public ProgramConstant(ProgramElementName name, KeYJavaType t, KeYJavaType containingType, + public ProgramConstant(ProgramElementName name, TypeReference t, KeYJavaType containingType, boolean isStatic, Literal compileTimeConstant) { - super(name, t.getSort(), t, containingType, isStatic, false, false); + super(name, t.getKeYJavaType().getSort(), t, containingType, isStatic, false, false); this.compileTimeConstant = compileTimeConstant; } - /** * @return the value of the initializer as a literal, if this variable is a compile-time * constant, null otherwise @@ -34,7 +34,6 @@ public Literal getCompileTimeConstant() { return compileTimeConstant; } - @Override public void visit(Visitor v) { v.performActionOnProgramConstant(this); diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramSV.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramSV.java index 34d4455925e..3c34d9bdc87 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramSV.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramSV.java @@ -9,6 +9,7 @@ import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.declaration.*; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; import de.uka.ilkd.key.java.ast.reference.PackageReference; @@ -104,6 +105,11 @@ public ReferencePrefix getReferencePrefix() { return null; } + @Override + public ImmutableArray getAnnotations() { + return new ImmutableArray<>(); + } + @Override public int getDimensions() { return 0; diff --git a/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramVariable.java b/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramVariable.java index a044ae28454..bc9fdf143f0 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramVariable.java +++ b/key.core/src/main/java/de/uka/ilkd/key/logic/op/ProgramVariable.java @@ -44,7 +44,7 @@ public abstract class ProgramVariable extends JAbstractSortedOperator ParsableVariable, ReferenceSuffix, ProgramInLogic { public static final Logger LOGGER = LoggerFactory.getLogger(ProgramVariable.class); - private final KeYJavaType type; + private final TypeReference type; private final boolean isStatic; private final boolean isModel; private final boolean isGhost; @@ -54,10 +54,10 @@ public abstract class ProgramVariable extends JAbstractSortedOperator // the program variable denotes a field private final KeYJavaType containingType; - protected ProgramVariable(ProgramElementName name, Sort s, KeYJavaType t, + protected ProgramVariable(ProgramElementName name, Sort s, TypeReference t, KeYJavaType containingType, boolean isStatic, boolean isModel, boolean isGhost, boolean isFinal) { - super(name, s == null ? t.getSort() : s, false); + super(name, s == null ? t.getKeYJavaType().getSort() : s, false); this.type = t; this.containingType = containingType; this.isStatic = isStatic; @@ -70,18 +70,16 @@ protected ProgramVariable(ProgramElementName name, Sort s, KeYJavaType t, assert sort() != JavaDLTheory.UPDATE; } - protected ProgramVariable(ProgramElementName name, Sort s, KeYJavaType t, + protected ProgramVariable(ProgramElementName name, Sort s, TypeReference t, KeYJavaType containingType, boolean isStatic, boolean isModel, boolean isGhost) { this(name, s, t, containingType, isStatic, isModel, isGhost, false); } - /** @return name of the ProgramVariable */ public ProgramElementName getProgramElementName() { return (ProgramElementName) name(); } - /** * returns true iff the program variable has been declared as static */ @@ -89,7 +87,6 @@ public boolean isStatic() { return isStatic; } - /** * returns true iff the program variable has been declared as model */ @@ -104,7 +101,6 @@ public boolean isGhost() { return isGhost; } - /** * returns true iff the program variable has been declared as final */ @@ -112,7 +108,6 @@ public boolean isFinal() { return isFinal; } - /** * returns true iff the program variable is a member */ @@ -120,7 +115,6 @@ public boolean isMember() { return containingType != null; } - /** * returns the KeYJavaType where the program variable is declared or null if the program * variable denotes not a field @@ -129,7 +123,6 @@ public KeYJavaType getContainerType() { return containingType; } - @Override public SourceElement getFirstElement() { return this; @@ -145,19 +138,16 @@ public SourceElement getLastElement() { return this; } - @Override public Comment[] getComments() { return new Comment[0]; } - @Override public void visit(Visitor v) { v.performActionOnProgramVariable(this); } - @Override public Position getStartPosition() { return Position.UNDEFINED; @@ -175,33 +165,29 @@ public PositionInfo getPositionInfo() { return PositionInfo.UNDEFINED; } - @Override - public KeYJavaType getKeYJavaType() { + public TypeReference getTypeReference() { return type; } + @Override + public KeYJavaType getKeYJavaType() { + return type != null ? type.getKeYJavaType() : null; + } @Override public KeYJavaType getKeYJavaType(Services javaServ) { return getKeYJavaType(); } - @Override public KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec) { return getKeYJavaType(); } - - /** - * We do not have a prefix, so fake it! This way we implement ReferencePrefix - * - * @author VK - */ @Override public ReferencePrefix getReferencePrefix() { - return null; + return type.getReferencePrefix(); } @Override @@ -213,16 +199,15 @@ public Expression convertToProgram(JTerm t, ExtList l) { } } - public String proofToString() { - final Type javaType = type.getJavaType(); + final Type javaType = getKeYJavaType().getJavaType(); final String typeName; if (javaType instanceof ArrayType) { typeName = ((ArrayType) javaType).getAlternativeNameRepresentation(); } else if (javaType != null) { typeName = javaType.getFullName(); } else { - typeName = type.getSort().name().toString(); + typeName = getKeYJavaType().getSort().name().toString(); } return typeName + " " + name() + ";\n"; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/macros/HeapSimplificationMacro.java b/key.core/src/main/java/de/uka/ilkd/key/macros/HeapSimplificationMacro.java index 4df46543999..27ca065334f 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/macros/HeapSimplificationMacro.java +++ b/key.core/src/main/java/de/uka/ilkd/key/macros/HeapSimplificationMacro.java @@ -63,6 +63,35 @@ public String getDescription() { "wellFormedAnonEQ", "wellFormedMemsetArrayObjectEQ", "wellFormedMemsetArrayPrimitiveEQ", "wellFormedMemsetObjectEQ", "wellFormedMemsetLocSetEQ", "wellFormedMemsetPrimitiveEQ", + // universe rules + "createdRepfpElement", + + "dismissSelectOfDominatedObject", "dismissSelectOfDominatingObject", + "dismissSelectOfDominatedAnon", "dismissSelectOfDominatedCreatedAnon", + + "dismissSelectOfSelfRepfpComplementAnon", "dismissSelectOfSelfCreatedRepfpComplementAnon", + "dismissSelectOfDominatingRepfpComplementAnon", + "dismissSelectOfDominatingCreatedRepfpComplementAnon", + + "dismissSelectOfDominatedObjectEQ", "dismissSelectOfDominatingObjectEQ", + "dismissSelectOfDominatedAnonEQ", "dismissSelectOfDominatedCreatedAnonEQ", + + "dismissSelectOfSelfRepfpComplementAnonEQ", + "dismissSelectOfSelfCreatedRepfpComplementAnonEQ", + "dismissSelectOfDominatingRepfpComplementAnonEQ", + "dismissSelectOfDominatingCreatedRepfpComplementAnonEQ", + + "simplifySelectOfDominatedAnon", "simplifySelectOfDominatedCreatedAnon", + "simplifySelectOfSelfRepfpComplementAnon", "simplifySelectOfSelfCreatedRepfpComplementAnon", + "simplifySelectOfDominatingRepfpComplementAnon", + "simplifySelectOfDominatingCreatedRepfpComplementAnon", + + "simplifySelectOfDominatedAnonEQ", "simplifySelectOfDominatedCreatedAnonEQ", + "simplifySelectOfSelfRepfpComplementAnonEQ", + "simplifySelectOfSelfCreatedRepfpComplementAnonEQ", + "simplifySelectOfDominatingRepfpComplementAnonEQ", + "simplifySelectOfDominatingCreatedRepfpComplementAnonEQ", + // locset rules "elementOfEmpty", "elementOfAllLocs", "elementOfSingleton", "elementOfUnion", "elementOfIntersect", "elementOfSetMinus", "elementOfAllFields", "elementOfAllObjects", diff --git a/key.core/src/main/java/de/uka/ilkd/key/nparser/builder/DeclarationBuilder.java b/key.core/src/main/java/de/uka/ilkd/key/nparser/builder/DeclarationBuilder.java index b9d4c467101..375ae0b4168 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/nparser/builder/DeclarationBuilder.java +++ b/key.core/src/main/java/de/uka/ilkd/key/nparser/builder/DeclarationBuilder.java @@ -7,6 +7,7 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.ldt.JavaDLTheory; import de.uka.ilkd.key.logic.*; import de.uka.ilkd.key.logic.op.LocationVariable; @@ -106,10 +107,10 @@ public Object visitProg_var_decls(KeYParser.Prog_var_declsContext ctx) { // getColumn()) if (!(name instanceof ProgramVariable) || !((ProgramVariable) name).getKeYJavaType().equals(kjt)) { - programVariables().add(new LocationVariable(pvName, kjt)); + programVariables().add(new LocationVariable(pvName, new TypeRef(kjt))); } } else { - programVariables().add(new LocationVariable(pvName, kjt)); + programVariables().add(new LocationVariable(pvName, new TypeRef(kjt))); } } } diff --git a/key.core/src/main/java/de/uka/ilkd/key/nparser/varexp/TacletBuilderManipulators.java b/key.core/src/main/java/de/uka/ilkd/key/nparser/varexp/TacletBuilderManipulators.java index 67065ce497c..048606476b0 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/nparser/varexp/TacletBuilderManipulators.java +++ b/key.core/src/main/java/de/uka/ilkd/key/nparser/varexp/TacletBuilderManipulators.java @@ -270,6 +270,8 @@ public VariableCondition build(Object[] arguments, List parameters, new ConstructorBasedBuilder("static", StaticReferenceCondition.class, SV); public static final TacletBuilderCommand DIFFERENT_FIELDS = new ConstructorBasedBuilder("differentFields", DifferentFields.class, SV, SV); + public static final AbstractConditionBuilder HAS_ANNOTATION = + new ConstructorBasedBuilder("hasAnnotation", HasAnnotationCondition.class, SV, S); public static final AbstractConditionBuilder SAME_OBSERVER = new ConstructorBasedBuilder("sameObserver", SameObserverCondition.class, PV, PV); public static final AbstractConditionBuilder applyUpdateOnRigid = new ConstructorBasedBuilder( @@ -382,7 +384,8 @@ public IsLabeledCondition build(Object[] arguments, List parameters, applyUpdateOnRigid, DROP_EFFECTLESS_ELEMENTARIES, SIMPLIFY_ITE_UPDATE, SUBFORMULAS, STATIC_FIELD, MODEL_FIELD, SUBFORMULA, DROP_EFFECTLESS_STORES, EQUAL_UNIQUE, META_DISJOINT, - IS_OBSERVER, CONSTANT, HAS_SORT, LABEL, NEW_LABEL, HAS_ELEM_SORT, IS_IN_STRICTFP); + IS_OBSERVER, CONSTANT, HAS_SORT, LABEL, NEW_LABEL, HAS_ELEM_SORT, IS_IN_STRICTFP, + HAS_ANNOTATION); register(STORE_TERM_IN, STORE_STMT_IN, HAS_INVARIANT, GET_INVARIANT, GET_FREE_INVARIANT, GET_VARIANT, IS_LABELED); loadWithServiceLoader(); diff --git a/key.core/src/main/java/de/uka/ilkd/key/pp/PrettyPrinter.java b/key.core/src/main/java/de/uka/ilkd/key/pp/PrettyPrinter.java index 5551e134e2d..e2a56b4aaa4 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/pp/PrettyPrinter.java +++ b/key.core/src/main/java/de/uka/ilkd/key/pp/PrettyPrinter.java @@ -174,7 +174,7 @@ protected static String encodeUnicodeChars(String str) { * * @param list a program element list. */ - protected void writeKeywordList(ImmutableArray list) { + protected void writeKeywordList(ImmutableArray list) { for (int i = 0; i < list.size(); i++) { if (i != 0) { layouter.brk(); @@ -616,8 +616,16 @@ public void performActionOnTypeReference(TypeReference x) { public void performActionOnTypeReference(TypeReference x, boolean fullTypeNames) { if (x.getKeYJavaType() != null && x.getKeYJavaType().getJavaType() instanceof ArrayDeclaration) { + for (Annotation annot: x.getAnnotations()) { + performActionOnAnnotation(annot); + } + performActionOnArrayDeclaration((ArrayDeclaration) x.getKeYJavaType().getJavaType()); } else if (x.getProgramElementName() != null) { + for (Annotation expr : x.getAnnotations()) { + performActionOnAnnotation(expr); + } + printTypeReference(x.getReferencePrefix(), x.getKeYJavaType(), x.getProgramElementName(), fullTypeNames); } @@ -735,6 +743,32 @@ public void performActionOnClassDeclaration(ClassDeclaration x) { performActionOnMemberDeclarations(x.getMembers()); } + @Override + public void performActionOnAnnotationInterfaceDeclaration(AnnotationInterfaceDeclaration x) { + layouter.beginC(); + layouter.beginC(0); + ImmutableArray mods = x.getModifiers(); + boolean hasMods = mods != null && !mods.isEmpty(); + if (hasMods) { + writeKeywordList(mods); + } + if (x.getProgramElementName() != null) { + if (hasMods) { + layouter.print(" "); + } + layouter.keyWord("@interface").print(" "); + performActionOnProgramElementName(x.getProgramElementName()); + } + layouter.end(); + // not an anonymous class + if (x.getProgramElementName() != null) { + layouter.print(" "); + } + layouter.end(); + + performActionOnMemberDeclarations(x.getMembers()); + } + private void performActionOnMemberDeclarations( @Nullable ImmutableArray members) { if (members != null && !members.isEmpty()) { @@ -1453,6 +1487,7 @@ public void performActionOnNewArray(NewArray x) { if (addParentheses) { layouter.print("("); } + layouter.print("new "); x.getTypeReference().visit(this); @@ -1713,6 +1748,12 @@ public void performActionOnThen(Then x) { handleBlockOrSingleStatement(x.getBody()); } + @Override + public void performActionOnAnnotation(Annotation x) { + layouter.print("@"); + layouter.print(x.getName()); + } + @Override public void performActionOnElse(Else x) { layouter.keyWord("else"); diff --git a/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractOperationPO.java b/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractOperationPO.java index 1ea6eb95518..56e3e80b1d8 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractOperationPO.java +++ b/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractOperationPO.java @@ -16,6 +16,7 @@ import de.uka.ilkd.key.java.ast.declaration.VariableSpecification; import de.uka.ilkd.key.java.ast.expression.literal.NullLiteral; import de.uka.ilkd.key.java.ast.expression.operator.CopyAssignment; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.ast.statement.*; import de.uka.ilkd.key.java.ast.statement.Try; @@ -41,6 +42,8 @@ import com.github.javaparser.ast.key.KeyTransactionStatement; import org.jspecify.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** *

@@ -79,6 +82,7 @@ * @author Martin Hentschel */ public abstract class AbstractOperationPO extends AbstractPO { + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractOperationPO.class); private static final String JAVA_LANG_THROWABLE = "java.lang.Throwable"; protected InitConfig proofConfig; @@ -398,7 +402,8 @@ public void readProblem() throws ProofInputException { // prepare variables, program method boolean makeNamesUnique = isMakeNamesUnique(); final ImmutableList paramVars = tb.paramVars(pm, makeNamesUnique); - final LocationVariable selfVar = tb.selfVar(pm, getCalleeKeYJavaType(), makeNamesUnique); + final LocationVariable selfVar = + tb.selfVar(pm, new TypeRef(getCalleeKeYJavaType()), makeNamesUnique); final LocationVariable resultVar = tb.resultVar(pm, makeNamesUnique); final LocationVariable exceptionVar = tb.excVar(pm, makeNamesUnique); @@ -899,7 +904,7 @@ protected JavaBlock buildJavaBlock(ImmutableList formalParVars final KeYJavaType eType = javaInfo.getTypeByClassName(JAVA_LANG_THROWABLE); final TypeReference excTypeRef = javaInfo.createTypeReference(eType); final ProgramElementName ePEN = new ProgramElementName("e"); - final ProgramVariable eVar = new LocationVariable(ePEN, eType); + final ProgramVariable eVar = new LocationVariable(ePEN, new TypeRef(eType)); final StatementBlock sb2; if (exceptionVar == null) { @@ -1010,7 +1015,7 @@ private ImmutableList createFormalParamVars( if (isCopyOfMethodArgumentsUsed()) { ProgramElementName pen = new ProgramElementName("_" + paramVar.name()); LocationVariable formalParamVar = - new LocationVariable(pen, paramVar.getKeYJavaType()); + new LocationVariable(pen, paramVar.getTypeReference()); formalParamVars = formalParamVars.append(formalParamVar); register(formalParamVar, proofServices); } else { diff --git a/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractPO.java b/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractPO.java index 054ff20a142..b2092922690 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractPO.java +++ b/key.core/src/main/java/de/uka/ilkd/key/proof/init/AbstractPO.java @@ -32,11 +32,14 @@ import org.key_project.util.collection.ImmutableSet; import org.key_project.util.collection.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * An abstract proof obligation implementing common functionality. */ public abstract class AbstractPO implements IPersistablePO { + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPO.class); protected TermBuilder tb; protected final InitConfig environmentConfig; diff --git a/key.core/src/main/java/de/uka/ilkd/key/proof/init/DependencyContractPO.java b/key.core/src/main/java/de/uka/ilkd/key/proof/init/DependencyContractPO.java index 06d7558df20..d983d1c6f29 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/proof/init/DependencyContractPO.java +++ b/key.core/src/main/java/de/uka/ilkd/key/proof/init/DependencyContractPO.java @@ -7,6 +7,7 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.logic.JTerm; import de.uka.ilkd.key.logic.TermBuilder; import de.uka.ilkd.key.logic.label.ParameterlessTermLabel; @@ -133,7 +134,8 @@ public void readProblem() throws ProofInputException { // prepare variables final LocationVariable selfVar = - !contract.getTarget().isStatic() ? tb.selfVar(contract.getKJT(), true) : null; + !contract.getTarget().isStatic() ? tb.selfVar(new TypeRef(contract.getKJT()), true) + : null; final ImmutableList paramVars = tb.paramVars(target, true); final boolean twoState = (contract.getTarget().getStateCount() == 2); diff --git a/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalBlockContractPO.java b/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalBlockContractPO.java index 4531162a8e3..bf2a6c92aba 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalBlockContractPO.java +++ b/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalBlockContractPO.java @@ -31,6 +31,7 @@ import org.key_project.logic.Name; import org.key_project.logic.op.Function; +import org.key_project.util.collection.ImmutableArray; import org.key_project.util.collection.ImmutableSet; import org.key_project.util.java.ArrayUtil; @@ -272,7 +273,8 @@ public void readProblem() { final IProgramMethod pm = getProgramMethod(); final StatementBlock block = getBlock(); - final LocationVariable selfVar = tb.selfVar(pm, getCalleeKeYJavaType(), makeNamesUnique); + final LocationVariable selfVar = + tb.selfVar(pm, new TypeRef(getCalleeKeYJavaType()), makeNamesUnique); register(selfVar, services); final JTerm selfTerm = selfVar == null ? null : tb.var(selfVar); @@ -296,7 +298,7 @@ public void readProblem() { .createAndRegister(selfTerm, false, contract.getBlock()); final ProgramVariable exceptionParameter = KeYJavaASTFactory.localVariable( services.getVariableNamer().getTemporaryNameProposal("e"), - variables.exception.getKeYJavaType()); + variables.exception.getTypeReference()); final ConditionsAndClausesBuilder conditionsAndClausesBuilder = new ConditionsAndClausesBuilder(contract.getAuxiliaryContract(), heaps, variables, @@ -394,7 +396,8 @@ private GoalsConfigurator setUpGoalConfigurator(final StatementBlock block, final BlockContract.Variables variables, final Services services, final TermBuilder tb) { final KeYJavaType kjt = getCalleeKeYJavaType(); - final TypeRef typeRef = new TypeRef(new ProgramElementName(kjt.getName()), 0, selfVar, kjt); + final TypeRef typeRef = new TypeRef(new ProgramElementName(kjt.getName()), + new ImmutableArray<>(), 0, selfVar, kjt); final ExecutionContext ec = new ExecutionContext(typeRef, getProgramMethod(), selfVar); JModality.JavaModalityKind kind = contract.getModalityKind(); JavaBlock jb = JavaBlock.createJavaBlock(new StatementBlock()); diff --git a/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalLoopContractPO.java b/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalLoopContractPO.java index 544cd1da17d..d480f5ca5d2 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalLoopContractPO.java +++ b/key.core/src/main/java/de/uka/ilkd/key/proof/init/FunctionalLoopContractPO.java @@ -31,6 +31,7 @@ import org.key_project.logic.Name; import org.key_project.logic.op.Function; +import org.key_project.util.collection.ImmutableArray; import org.key_project.util.collection.ImmutableSet; import org.key_project.util.java.ArrayUtil; @@ -131,7 +132,8 @@ public void readProblem() { contract.replaceEnhancedForVariables(services); - final LocationVariable selfVar = tb.selfVar(pm, getCalleeKeYJavaType(), makeNamesUnique); + final LocationVariable selfVar = + tb.selfVar(pm, new TypeRef(getCalleeKeYJavaType()), makeNamesUnique); register(selfVar, services); final JTerm selfTerm = selfVar == null ? null : tb.var(selfVar); @@ -368,7 +370,8 @@ private GoalsConfigurator createGoalConfigurator(final ProgramVariable selfVar, final TermBuilder tb) { final TermLabelState termLabelState = new TermLabelState(); final KeYJavaType kjt = getCalleeKeYJavaType(); - final TypeRef ref = new TypeRef(new ProgramElementName(kjt.getName()), 0, selfVar, kjt); + final TypeRef ref = new TypeRef(new ProgramElementName(kjt.getName()), + new ImmutableArray<>(), 0, selfVar, kjt); final ExecutionContext ec = new ExecutionContext(ref, getProgramMethod(), selfVar); // TODO (DD): HACK @@ -413,7 +416,7 @@ private JTerm setUpValidityGoal(final JTerm selfTerm, final List */ public class FunctionalOperationContractPO extends AbstractOperationPO implements ContractPO { + private static final Logger LOGGER = + LoggerFactory.getLogger(FunctionalOperationContractPO.class); public static final Map TRANSACTION_TAGS = new LinkedHashMap<>(); @@ -151,7 +155,7 @@ protected ImmutableList buildOperationBlocks( // construct what would be produced from rule instanceCreationAssignment final Expression init = (Expression) (new CreateObject(n)).transform(n, services, svInst)[0]; - final Statement assignTmp = declare(selfVar, init, type); + final Statement assignTmp = declare(selfVar, init, new TypeRef(type)); result[0] = new StatementBlock(assignTmp); // try block diff --git a/key.core/src/main/java/de/uka/ilkd/key/proof/mgt/SpecificationRepository.java b/key.core/src/main/java/de/uka/ilkd/key/proof/mgt/SpecificationRepository.java index 455e5a2a48f..748d5aa6c59 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/proof/mgt/SpecificationRepository.java +++ b/key.core/src/main/java/de/uka/ilkd/key/proof/mgt/SpecificationRepository.java @@ -16,6 +16,7 @@ import de.uka.ilkd.key.java.ast.declaration.ClassDeclaration; import de.uka.ilkd.key.java.ast.declaration.modifier.Private; import de.uka.ilkd.key.java.ast.declaration.modifier.VisibilityModifier; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.statement.LoopStatement; import de.uka.ilkd.key.java.ast.statement.MergePointStatement; import de.uka.ilkd.key.logic.*; @@ -856,7 +857,7 @@ public ImmutableSet getClassAxioms(KeYJavaType selfKjt) { continue; // only non-private classes } final ImmutableSet myInvs = getClassInvariants(kjt); - final LocationVariable selfVar = tb.selfVar(kjt, false); + final LocationVariable selfVar = tb.selfVar(new TypeRef(kjt), false); JTerm invDef = tb.tt(); JTerm staticInvDef = tb.tt(); @@ -948,7 +949,8 @@ private ImmutableSet getModelMethodAxioms() { ImmutableSet result = DefaultImmutableSet.nil(); for (KeYJavaType kjt : services.getJavaInfo().getAllKeYJavaTypes()) { for (IProgramMethod pm : services.getJavaInfo().getAllProgramMethods(kjt)) { - final LocationVariable selfVar = pm.isStatic() ? null : tb.selfVar(kjt, false); + final LocationVariable selfVar = + pm.isStatic() ? null : tb.selfVar(new TypeRef(kjt), false); if (!pm.isVoid() && pm.isModel()) { pm = services.getJavaInfo().getToplevelPM(kjt, pm); ImmutableList paramVars = tb.paramVars(pm, false); diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractAuxiliaryContractRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractAuxiliaryContractRule.java index 790dafb48d8..4f09f6028f7 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractAuxiliaryContractRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractAuxiliaryContractRule.java @@ -7,8 +7,8 @@ import de.uka.ilkd.key.java.KeYJavaASTFactory; import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.*; -import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.ast.statement.*; import de.uka.ilkd.key.ldt.JavaDLTheory; import de.uka.ilkd.key.logic.JTerm; @@ -139,14 +139,14 @@ protected static JTerm createLocalAnonUpdate(ImmutableSet loca /** * * @param nameBase a base name. - * @param type a type. + * @param typeRef a {@link TypeReference}. * @param services services. * @return a new local variable with the specified base name of the specified type. */ protected static LocationVariable createLocalVariable(final String nameBase, - final KeYJavaType type, final Services services) { + final TypeReference typeRef, final Services services) { return KeYJavaASTFactory.localVariable( - services.getVariableNamer().getTemporaryNameProposal(nameBase), type); + services.getVariableNamer().getTemporaryNameProposal(nameBase), typeRef); } /** diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractLoopInvariantRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractLoopInvariantRule.java index 126ef455d22..af3017975e6 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractLoopInvariantRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/AbstractLoopInvariantRule.java @@ -207,7 +207,8 @@ protected static JTerm createBeforeLoopUpdate(Services services, for (ProgramVariable pv : localOuts) { final String pvBeforeLoopName = tb.newName(pv.name() + "Before_LOOP"); final LocationVariable pvBeforeLoop = - new LocationVariable(new ProgramElementName(pvBeforeLoopName), pv.getKeYJavaType()); + new LocationVariable(new ProgramElementName(pvBeforeLoopName), + pv.getTypeReference()); progVarNS.addSafely(pvBeforeLoop); beforeLoopUpdate = tb.parallel(beforeLoopUpdate, tb.elementary(pvBeforeLoop, tb.var(pv))); diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/AuxiliaryContractBuilders.java b/key.core/src/main/java/de/uka/ilkd/key/rule/AuxiliaryContractBuilders.java index d78676170aa..609a7a3b17b 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/AuxiliaryContractBuilders.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/AuxiliaryContractBuilders.java @@ -17,6 +17,8 @@ import de.uka.ilkd.key.java.ast.expression.literal.*; import de.uka.ilkd.key.java.ast.expression.literal.BooleanLiteral; import de.uka.ilkd.key.java.ast.expression.operator.NotEquals; +import de.uka.ilkd.key.java.ast.reference.TypeRef; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.ast.statement.*; import de.uka.ilkd.key.java.ast.statement.Catch; import de.uka.ilkd.key.java.ast.statement.LabeledStatement; @@ -181,7 +183,7 @@ private void declareFlagsFalse() { statements.add(KeYJavaASTFactory.assign(flag, BooleanLiteral.FALSE)); } else { statements.add(KeYJavaASTFactory.declare(flag, BooleanLiteral.FALSE, - services.getJavaInfo().getKeYJavaType("boolean"))); + new TypeRef(services.getJavaInfo().getKeYJavaType("boolean")))); } } @@ -190,7 +192,7 @@ private void declareFlagsFalse() { statements.add(KeYJavaASTFactory.assign(flag, BooleanLiteral.FALSE)); } else { statements.add(KeYJavaASTFactory.declare(flag, BooleanLiteral.FALSE, - services.getJavaInfo().getKeYJavaType("boolean"))); + new TypeRef(services.getJavaInfo().getKeYJavaType("boolean")))); } } if (variables.returnFlag != null) { @@ -199,7 +201,8 @@ private void declareFlagsFalse() { KeYJavaASTFactory.assign(variables.returnFlag, BooleanLiteral.FALSE)); } else { statements.add(KeYJavaASTFactory.declare(variables.returnFlag, - BooleanLiteral.FALSE, services.getJavaInfo().getKeYJavaType("boolean"))); + BooleanLiteral.FALSE, + new TypeRef(services.getJavaInfo().getKeYJavaType("boolean")))); } } } @@ -215,9 +218,9 @@ private void declareResultDefault() { statements.add( KeYJavaASTFactory.assign(variables.result, resultType.getDefaultValue())); } else { - KeYJavaType resultType = variables.result.getKeYJavaType(); + TypeReference resultType = variables.result.getTypeReference(); statements.add(KeYJavaASTFactory.declare(variables.result, - resultType.getDefaultValue(), resultType)); + resultType.getKeYJavaType().getDefaultValue(), resultType)); } } } @@ -239,7 +242,7 @@ private void declareExceptionNull() { statements.add(KeYJavaASTFactory.assign(variables.exception, NullLiteral.NULL)); } else { statements.add(KeYJavaASTFactory.declare(variables.exception, NullLiteral.NULL, - variables.exception.getKeYJavaType())); + variables.exception.getTypeReference())); } } @@ -295,7 +298,7 @@ private Statement wrapInTryCatch(final Statement labeledBlock, final ProgramVariable exceptionParameter) { Catch katch = KeYJavaASTFactory.catchClause( KeYJavaASTFactory.parameterDeclaration(services.getJavaInfo(), - exceptionParameter.getKeYJavaType(), exceptionParameter), + exceptionParameter.getTypeReference(), exceptionParameter), new StatementBlock( KeYJavaASTFactory.assign(variables.exception, exceptionParameter))); return new Try(new StatementBlock(labeledBlock), new Branch[] { katch }); @@ -443,7 +446,7 @@ private Map appendSuffix(final Map String newName = services.getTermBuilder().newName(value.name() + suffix); LocationVariable newValue = - new LocationVariable(new ProgramElementName(newName), value.getKeYJavaType()); + new LocationVariable(new ProgramElementName(newName), value.getTypeReference()); result.put(key, newValue); } @@ -493,7 +496,7 @@ private LocationVariable createAndRegisterVariable( String newName = services.getTermBuilder().newName(placeholderVariable.name().toString()); LocationVariable newVariable = new LocationVariable(new ProgramElementName(newName), - placeholderVariable.getKeYJavaType()); + placeholderVariable.getTypeReference()); if (goal != null) { goal.addProgramVariable(newVariable); @@ -1193,14 +1196,15 @@ public GoalsConfigurator(final AbstractAuxiliaryContractBuiltInRuleApp applicati */ private static LocationVariable[] createLoopVariables(final Services services) { LocationVariable conditionVariable = AbstractAuxiliaryContractRule.createLocalVariable( - "cond", services.getJavaInfo().getKeYJavaType("boolean"), services); + "cond", new TypeRef(services.getJavaInfo().getKeYJavaType("boolean")), services); LocationVariable brokeLoopVariable = AbstractAuxiliaryContractRule.createLocalVariable( - "brokeLoop", services.getJavaInfo().getKeYJavaType("boolean"), services); + "brokeLoop", new TypeRef(services.getJavaInfo().getKeYJavaType("boolean")), + services); LocationVariable continuedLoopVariable = AbstractAuxiliaryContractRule.createLocalVariable("continuedLoop", - services.getJavaInfo().getKeYJavaType("boolean"), services); + new TypeRef(services.getJavaInfo().getKeYJavaType("boolean")), services); final LocationVariable[] loopVariables = { conditionVariable, brokeLoopVariable, continuedLoopVariable }; return loopVariables; diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/BlockContractInternalRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/BlockContractInternalRule.java index e041d235090..5fc00968782 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/BlockContractInternalRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/BlockContractInternalRule.java @@ -315,7 +315,7 @@ protected void setUpValidityGoal(final ImmutableList result, final Services services) { Goal validityGoal = result.tail().tail().head(); final ProgramVariable exceptionParameter = - createLocalVariable("e", variables.exception.getKeYJavaType(), services); + createLocalVariable("e", variables.exception.getTypeReference(), services); configurator.setUpValidityGoal(validityGoal, new JTerm[] { updates[0], updates[1] }, preconditions, new JTerm[] { assumptions[0], frameCondition }, exceptionParameter, conditionsAndClausesBuilder.terms); diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/LoopContractInternalRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/LoopContractInternalRule.java index 213804a89b3..d4132d21757 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/LoopContractInternalRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/LoopContractInternalRule.java @@ -321,7 +321,7 @@ public LoopContractInternalBuiltInRuleApp createApp(final PosInOccurrence occurr configurator.setUpUsageGoal(result.head(), updates, ArrayUtil.add(usageAssumptions, freePostcondition)); final LocationVariable exceptionParameter = - createLocalVariable("e", vars[0].exception.getKeYJavaType(), services); + createLocalVariable("e", vars[0].exception.getTypeReference(), services); configurator.setUpLoopValidityGoal(goal, contract, context, updates[1], nextRemembranceUpdate, anonOutHeaps, modifiableClauses, freeModifiableClauses, diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/LoopScopeInvariantRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/LoopScopeInvariantRule.java index 9a1a248c4e6..3fe1b72ff3c 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/LoopScopeInvariantRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/LoopScopeInvariantRule.java @@ -13,6 +13,7 @@ import de.uka.ilkd.key.java.ast.Statement; import de.uka.ilkd.key.java.ast.StatementBlock; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.statement.LabeledStatement; import de.uka.ilkd.key.java.ast.statement.LoopScopeBlock; import de.uka.ilkd.key.java.ast.statement.While; @@ -249,7 +250,8 @@ private ProgramVariable loopScopeIdxVar(Services services) { final ProgramVariable loopScopeIdxVar = // KeYJavaASTFactory.localVariable( // - services.getVariableNamer().getTemporaryNameProposal("x"), booleanType); + services.getVariableNamer().getTemporaryNameProposal("x"), + new TypeRef(booleanType)); return loopScopeIdxVar; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/QueryExpand.java b/key.core/src/main/java/de/uka/ilkd/key/rule/QueryExpand.java index 7c9c327582e..6c40c2d6188 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/QueryExpand.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/QueryExpand.java @@ -156,12 +156,14 @@ public Pair queryEvalTerm(Services services, JTerm query, callee = null; offset = 0; } else { - callee = new LocationVariable(new ProgramElementName(calleeName), calleeType); + callee = + new LocationVariable(new ProgramElementName(calleeName), new TypeRef(calleeType)); offset = 1; } final ProgramVariable result = - new LocationVariable(new ProgramElementName(progResultName), progResultType); + new LocationVariable(new ProgramElementName(progResultName), + new TypeRef(progResultType)); final MethodReference mr = @@ -197,7 +199,7 @@ public Pair queryEvalTerm(Services services, JTerm query, ArrayList stmnt = new ArrayList<>(); - stmnt.add(KeYJavaASTFactory.declare(result, progResultType)); + stmnt.add(KeYJavaASTFactory.declare(result, new TypeRef(progResultType))); final CopyAssignment assignment = new CopyAssignment(result, mr); @@ -255,7 +257,7 @@ private ImmutableArray getRegisteredArgumentVariables( final String newName = services.getTermBuilder().newName(baseName); final ProgramElementName argVarName = new ProgramElementName(newName); args[i] = new LocationVariable(argVarName, - pdecl.getVariableSpecification().getProgramVariable().getKeYJavaType()); + pdecl.getVariableSpecification().getProgramVariable().getTypeReference()); progvarsNS.addSafely(args[i]); i++; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/TacletApp.java b/key.core/src/main/java/de/uka/ilkd/key/rule/TacletApp.java index 226512729bd..6968b7f50be 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/TacletApp.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/TacletApp.java @@ -12,6 +12,7 @@ import de.uka.ilkd.key.java.ast.ProgramElement; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.expression.Expression; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.logic.*; import de.uka.ilkd.key.logic.ClashFreeSubst.VariableCollectVisitor; @@ -1164,13 +1165,13 @@ public ProgramElement getProgramElement(String instantiation, ProgramSV sv, } else if (svSort == ProgramSVSort.VARIABLE) { final NewVarcond nvc = (NewVarcond) taclet.varDeclaredNew(sv); if (nvc != null) { - KeYJavaType kjt; + TypeReference typeRef; Object o = nvc.getTypeDefiningObject(); if (o instanceof SchemaVariable peerSV) { final TypeConverter tc = services.getTypeConverter(); final Object peerInst = instantiations().getInstantiation(peerSV); if (peerInst instanceof TypeReference) { - kjt = ((TypeReference) peerInst).getKeYJavaType(); + typeRef = (TypeReference) peerInst; } else { Expression peerInstExpr; if (peerInst instanceof JTerm peerTerm) { @@ -1178,14 +1179,14 @@ public ProgramElement getProgramElement(String instantiation, ProgramSV sv, } else { peerInstExpr = (Expression) peerInst; } - kjt = tc.getKeYJavaType(peerInstExpr, - instantiations().getContextInstantiation().activeStatementContext()); + typeRef = new TypeRef(tc.getKeYJavaType(peerInstExpr, + instantiations().getContextInstantiation().activeStatementContext())); } } else { - kjt = (KeYJavaType) o; + typeRef = new TypeRef((KeYJavaType) o); } - assert kjt != null : "could not find kjt for: " + o; - return new LocationVariable(VariableNamer.parseName(instantiation), kjt); + assert typeRef != null : "could not find TypeReference for: " + o; + return new LocationVariable(VariableNamer.parseName(instantiation), typeRef); } } return null; diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/UseOperationContractRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/UseOperationContractRule.java index 3780c359933..e464eb0a053 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/UseOperationContractRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/UseOperationContractRule.java @@ -612,7 +612,7 @@ public static ImmutableList computeParams(JTerm baseHeapTerm, */ public static ProgramVariable computeResultVar(Instantiation inst, TermServices services) { final TermBuilder tb = services.getTermBuilder(); - return inst.pm.isConstructor() ? tb.selfVar(inst.staticType, true) + return inst.pm.isConstructor() ? tb.selfVar(new TypeRef(inst.staticType), true) : tb.resultVar(inst.pm, true); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/WhileInvariantRule.java b/key.core/src/main/java/de/uka/ilkd/key/rule/WhileInvariantRule.java index e727678997f..075547e8aac 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/WhileInvariantRule.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/WhileInvariantRule.java @@ -301,7 +301,7 @@ public WhileInvariantRuleApplier(Goal goal, LoopInvariantBuiltInRuleApp ruleA final String pvBeforeLoopName = tb.newName(pv.name() + "Before_LOOP"); final LocationVariable pvBeforeLoop = new LocationVariable(new ProgramElementName(pvBeforeLoopName), - pv.getKeYJavaType()); + pv.getTypeReference()); services.getNamespaces().programVariables().addSafely(pvBeforeLoop); beforeLoopUpdate = tb.parallel(beforeLoopUpdate, tb.elementary(pvBeforeLoop, tb.var(pv))); @@ -606,7 +606,8 @@ protected Guard prepareGuard(final Instantiation inst, final TermServices services) { final TermBuilder tb = services.getTermBuilder(); final ProgramElementName guardVarName = new ProgramElementName(tb.newName("b")); - final LocationVariable guardVar = new LocationVariable(guardVarName, booleanKJT); + final LocationVariable guardVar = + new LocationVariable(guardVarName, new TypeRef(booleanKJT)); services.getNamespaces().programVariables().addSafely(guardVar); loopRuleApp.setGuard(tb.var(guardVar)); final VariableSpecification guardVarSpec = diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/HasAnnotationCondition.java b/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/HasAnnotationCondition.java new file mode 100644 index 00000000000..216b7c6a656 --- /dev/null +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/HasAnnotationCondition.java @@ -0,0 +1,97 @@ +/* This file is part of KeY - https://key-project.org + * KeY is licensed under the GNU General Public License Version 2 + * SPDX-License-Identifier: GPL-2.0-only */ +package de.uka.ilkd.key.rule.conditions; + +import de.uka.ilkd.key.java.Services; +import de.uka.ilkd.key.java.ast.ProgramElement; +import de.uka.ilkd.key.java.ast.declaration.*; +import de.uka.ilkd.key.ldt.HeapLDT; +import de.uka.ilkd.key.logic.JTerm; +import de.uka.ilkd.key.logic.op.LocationVariable; +import de.uka.ilkd.key.rule.VariableConditionAdapter; +import de.uka.ilkd.key.rule.inst.SVInstantiations; + +import org.key_project.logic.SyntaxElement; +import org.key_project.logic.op.Function; +import org.key_project.logic.op.sv.SchemaVariable; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class HasAnnotationCondition extends VariableConditionAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(HasAnnotationCondition.class); + + private final SchemaVariable variable; + private final String annot; + + public HasAnnotationCondition(SchemaVariable variable, String annot) { + this.variable = variable; + this.annot = annot; + } + + @Override + public boolean check(SchemaVariable var, SyntaxElement subst, + SVInstantiations svInst, Services services) { + + if (var != variable) + return true; + + Object inst = svInst.getInstantiation(variable); + + if (!(inst instanceof JTerm)) + return false; + + var op = ((JTerm) inst).op(); + + if (op.arity() != 0) + return false; + + if (op instanceof Function) { + LOGGER.info("field {}", op); + return matchesField(services, (Function) op); + } else if (op instanceof ProgramElement) { + if (op instanceof LocationVariable) { + //LOGGER.info("type ref {}", ((LocationVariable)op).getTypeReference()); + //LOGGER.info("annotations {}", ((LocationVariable)op).getTypeReference().getAnnotations()); + } + } + + return false; + } + + public boolean matchesField(Services services, Function op) { + HeapLDT.SplitFieldName name = HeapLDT.trySplitFieldName(op); + + if (name == null) + return false; + + var classType = ((Services) services).getJavaInfo() + .getTypeByName(name.className()); + + if (classType == null || + !(classType.getJavaType() instanceof ClassDeclaration)) + return false; + + var classDecl = (ClassDeclaration)classType.getJavaType(); + + var fields = classDecl.getAllFields(services); + + // this is a bit too brittle for me + var field = fields.stream() + .filter(f -> f.getName().split("::")[1].equals(name.attributeName())) + .findFirst() + .orElse(null); + + if (field == null) return false; + + var fieldType = field.getProgramVariable().getTypeReference(); + var declAnnotations = fieldType.getAnnotations(); + return declAnnotations.stream().anyMatch(a -> a.getName().equals(annot)); + } + + @Override + public String toString() { + return "\\hasAnnotation(" + variable + ", " + annot + ")"; + } +} diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/NewLocalVarsCondition.java b/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/NewLocalVarsCondition.java index 7b564bae403..41f69da2d66 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/NewLocalVarsCondition.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/conditions/NewLocalVarsCondition.java @@ -11,7 +11,7 @@ import de.uka.ilkd.key.java.ast.Statement; import de.uka.ilkd.key.java.ast.abstraction.*; import de.uka.ilkd.key.java.ast.declaration.*; -import de.uka.ilkd.key.java.ast.reference.TypeRef; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.logic.JTerm; import de.uka.ilkd.key.logic.op.LocationVariable; import de.uka.ilkd.key.rule.inst.SVInstantiations; @@ -85,14 +85,10 @@ public MatchResultInfo check(SchemaVariable var, SyntaxElement instCandidate, for (var v : vars) { final var newName = services.getVariableNamer().getTemporaryNameProposal(v.name() + "_before"); - KeYJavaType type = v.getKeYJavaType(); - var locVar = new LocationVariable(newName, type); + TypeReference typeRef = v.getTypeReference(); + var locVar = new LocationVariable(newName, typeRef); var spec = new VariableSpecification(locVar); - int dim = 0; - if (type.getJavaType() instanceof ArrayType at) { - dim = at.getDimension(); - } - decls.add(new LocalVariableDeclaration(new TypeRef(type, dim), spec)); + decls.add(new LocalVariableDeclaration(typeRef, spec)); updatesBefore = updatesBefore.append(tb.elementary(tb.var(locVar), tb.var(v))); updatesFrame = updatesFrame.append(tb.elementary(tb.var(v), tb.var(locVar))); } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchProgramSVInstruction.java b/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchProgramSVInstruction.java index e333548393c..04c2c33414b 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchProgramSVInstruction.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchProgramSVInstruction.java @@ -98,4 +98,9 @@ public MatchResultInfo match(SyntaxElement actualElement, } return result; } + + @Override + public String toString() { + return "MatchProgramSVInstruction"; + } } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchTermLabelInstruction.java b/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchTermLabelInstruction.java index 3d0eb0622e0..a8171ced355 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchTermLabelInstruction.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchTermLabelInstruction.java @@ -68,4 +68,9 @@ public MatchResultInfo match(SyntaxElement actualElement, MatchResultInfo matchC return result; } + @Override + public String toString() { + return "MatchTermLabelInstruction"; + } + } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchVariableSVInstruction.java b/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchVariableSVInstruction.java index fcd7aed1c31..f5ff0ed9342 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchVariableSVInstruction.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/match/vm/instructions/MatchVariableSVInstruction.java @@ -32,5 +32,4 @@ public MatchResultInfo match(SyntaxElement actualElement, MatchResultInfo mc, } return null; } - } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ArrayPostDecl.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ArrayPostDecl.java index 4d332418ce1..1162c798325 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ArrayPostDecl.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ArrayPostDecl.java @@ -43,6 +43,7 @@ public ProgramElement[] transform(ProgramElement pe, Services services, return new ProgramElement[] { KeYJavaASTFactory.declare(modifiers, variable, var.getInitializer(), originalTypeReference.getProgramElementName(), originalTypeReference.getDimensions() + var.getDimensions(), + originalTypeReference.getAnnotations(), originalTypeReference.getReferencePrefix(), variable.getKeYJavaType()) }; } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EnhancedForElimination.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EnhancedForElimination.java index efb484735f1..998832bd19e 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EnhancedForElimination.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EnhancedForElimination.java @@ -193,14 +193,15 @@ private ProgramElement makeArrayForLoop(EnhancedFor enhancedFor, TransformationD final JavaInfo ji = services.getJavaInfo(); // T[] arr = exp; - final KeYJavaType arrayType = expression.getKeYJavaType(services, data.execContext()); + final TypeReference arrayType = + new TypeRef(expression.getKeYJavaType(services, data.execContext())); final ProgramVariable arrayVar = KeYJavaASTFactory.localVariable(services, ARR, arrayType); final Statement arrAssignment = KeYJavaASTFactory.declare(arrayVar, expression); data.setHead(KeYJavaASTFactory.block(arrAssignment)); // for(int i; i < arr.length; i++) - final KeYJavaType intType = ji.getPrimitiveKeYJavaType("int"); + final TypeReference intType = new TypeRef(ji.getPrimitiveKeYJavaType("int")); data.setIndexVariable(KeYJavaASTFactory.localVariable(services, INDEX, intType)); final ILoopInit inits = KeYJavaASTFactory.loopInitZero(intType, data.indexVariable()); final IGuard guard = @@ -243,13 +244,13 @@ private ProgramElement makeIterableForLoop(EnhancedFor enhancedFor, Transformati ImmutableSLList.nil(), data.execContext().getTypeReference().getKeYJavaType()); // local variable "it" - final KeYJavaType iteratorType = iteratorMethod.getReturnType(); + final TypeReference iteratorType = new TypeRef(iteratorMethod.getReturnType()); ProgramVariable iteratorVariable = KeYJavaASTFactory.localVariable(services, IT, iteratorType); // local variable "values" - final KeYJavaType seqType = - services.getTypeConverter().getKeYJavaType(PrimitiveType.JAVA_SEQ); + final TypeReference seqType = + new TypeRef(services.getTypeConverter().getKeYJavaType(PrimitiveType.JAVA_SEQ)); data.setValuesVariable(KeYJavaASTFactory.localVariable(services, VALUES, seqType)); // ghost \seq values = \seq_empty diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EvaluateArgs.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EvaluateArgs.java index 647738134c8..180feb48ccf 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EvaluateArgs.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/EvaluateArgs.java @@ -11,7 +11,6 @@ import de.uka.ilkd.key.java.Services; import de.uka.ilkd.key.java.ast.ProgramElement; import de.uka.ilkd.key.java.ast.Statement; -import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.declaration.LocalVariableDeclaration; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.expression.operator.CopyAssignment; @@ -24,6 +23,8 @@ import de.uka.ilkd.key.java.ast.reference.SuperReference; import de.uka.ilkd.key.java.ast.reference.ThisConstructorReference; import de.uka.ilkd.key.java.ast.reference.ThisReference; +import de.uka.ilkd.key.java.ast.reference.TypeRef; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.logic.ProgramElementName; import de.uka.ilkd.key.logic.VariableNamer; import de.uka.ilkd.key.logic.op.ProgramVariable; @@ -60,7 +61,7 @@ public static ProgramVariable evaluate(Expression e, List bodyStmnts, Expressio services.getJavaInfo().getKeYJavaType(PrimitiveType.JAVA_INT); final ProgramElementName name = varNamer.getTemporaryNameProposal("i"); final LocalVariableDeclaration forInit = - KeYJavaASTFactory.declare(name, KeYJavaASTFactory.zeroLiteral(), intType); + KeYJavaASTFactory.declare(name, KeYJavaASTFactory.zeroLiteral(), + new TypeRef(intType)); final ProgramVariable pv = (ProgramVariable) forInit.getVariables().get(0).getProgramVariable(); diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/IntroAtPreDefsOp.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/IntroAtPreDefsOp.java index 86a6ba85cf9..dec5c6c2906 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/IntroAtPreDefsOp.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/IntroAtPreDefsOp.java @@ -271,7 +271,7 @@ public void addNeededVariables(Collection variables) { continue; } final LocationVariable l = tb.locationVariable(var.name() + "Before_" + methodName, - var.getKeYJavaType(), true); + var.getTypeReference(), true); services.getNamespaces().programVariables().addSafely(l); final JTerm u = tb.elementary(l, tb.var(var)); diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/MethodCall.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/MethodCall.java index 9d889a2b8e4..63d7857d79b 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/MethodCall.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/MethodCall.java @@ -327,7 +327,7 @@ private Statement makeMbs(KeYJavaType t, Services services) { if (newContextAsExp.getKeYJavaType(services, execContext) != targetType) { castedThisVar = KeYJavaASTFactory.declare( new ProgramElementName(services.getTermBuilder().newName("target")), - KeYJavaASTFactory.cast(newContextAsExp, targetType), targetType); + KeYJavaASTFactory.cast(newContextAsExp, targetType), new TypeRef(targetType)); localContext = (ReferencePrefix) castedThisVar.getVariableSpecifications().get(0) .getProgramVariable(); @@ -380,7 +380,7 @@ private VariableSpecification[] createParamSpecs(Services services) { final IProgramVariable paramVar = KeYJavaASTFactory.localVariable(services, originalParamVar.getProgramElementName().toString(), - originalParamVar.getKeYJavaType()); + originalParamVar.getTypeReference()); // this condition checks whether this is the last formal parameter // and is used diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ProgramTransformer.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ProgramTransformer.java index 79ab2757adc..04bb8b3e20c 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ProgramTransformer.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/ProgramTransformer.java @@ -6,6 +6,7 @@ import de.uka.ilkd.key.java.*; import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; import de.uka.ilkd.key.java.ast.reference.PackageReference; @@ -18,6 +19,7 @@ import org.key_project.logic.Name; import org.key_project.logic.op.sv.SchemaVariable; +import org.key_project.util.collection.ImmutableArray; import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableSLList; @@ -155,6 +157,7 @@ public ProgramElement getChildAt(int index) { // -------------some methods to pretend being a type reference -------- + @Override public ReferencePrefix getReferencePrefix() { return null; } @@ -163,37 +166,49 @@ public ReferencePrefix setReferencePrefix(ReferencePrefix r) { return this; } + @Override + public ImmutableArray getAnnotations() { + return new ImmutableArray<>(); + } + @Override public int getDimensions() { return 0; } + @Override public int getTypeReferenceCount() { return 0; } + @Override public TypeReference getTypeReferenceAt(int index) { return this; } + @Override public PackageReference getPackageReference() { return null; } + @Override public int getExpressionCount() { return 0; } + @Override public Expression getExpressionAt(int index) { return null; } + @Override public ProgramElementName getProgramElementName() { return new ProgramElementName(toString()); } + @Override public String getName() { return toString(); } @@ -204,15 +219,18 @@ public String getName() { * * @param v the Visitor */ + @Override public void visit(Visitor v) { v.performActionOnProgramMetaConstruct(this); } /** to String */ + @Override public String toString() { return name + "( " + body + ");"; } + @Override public KeYJavaType getKeYJavaType() { return null; } @@ -221,6 +239,7 @@ public KeYJavaType getKeYJavaType(TermServices javaServ) { return getKeYJavaType(); } + @Override public KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec) { return getKeYJavaType(); } @@ -245,5 +264,4 @@ public ImmutableList needs() { public ImmutableList neededInstantiations(SVInstantiations svInst) { return ImmutableSLList.nil(); } - } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/SwitchToIf.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/SwitchToIf.java index dea977c4653..0742e3a0786 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/SwitchToIf.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/SwitchToIf.java @@ -18,6 +18,7 @@ import de.uka.ilkd.key.java.ast.expression.operator.Equals; import de.uka.ilkd.key.java.ast.expression.operator.New; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.statement.*; import de.uka.ilkd.key.logic.ProgramElementName; import de.uka.ilkd.key.logic.VariableNamer; @@ -59,9 +60,11 @@ public ProgramElement[] transform(ProgramElement pe, Services services, final ExecutionContext ec = insts.getExecutionContext(); ProgramVariable exV = - KeYJavaASTFactory.localVariable(name, sw.getExpression().getKeYJavaType(services, ec)); + KeYJavaASTFactory.localVariable(name, + new TypeRef(sw.getExpression().getKeYJavaType(services, ec))); Statement s = - KeYJavaASTFactory.declare(name, sw.getExpression().getKeYJavaType(services, ec)); + KeYJavaASTFactory.declare(name, + new TypeRef(sw.getExpression().getKeYJavaType(services, ec))); final var changeBreakResult = changeBreaks(sw, newBreak, true); sw = (Switch) changeBreakResult.result; diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/TypeOf.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/TypeOf.java index 1cc9337ecb3..4fb2b226448 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/TypeOf.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/TypeOf.java @@ -9,11 +9,14 @@ import de.uka.ilkd.key.java.ast.abstraction.ArrayType; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.abstraction.PrimitiveType; +import de.uka.ilkd.key.java.ast.Annotation; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.reference.ExecutionContext; import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.rule.inst.SVInstantiations; +import org.key_project.util.collection.ImmutableArray; + public class TypeOf extends ProgramTransformer { /** @@ -23,7 +26,6 @@ public class TypeOf extends ProgramTransformer { */ public TypeOf(ProgramElement pe) { super("#typeof", pe); - } @Override @@ -36,21 +38,25 @@ public ProgramElement[] transform(ProgramElement pe, Services services, ec = insts.getContextInstantiation().activeStatementContext(); } KeYJavaType kjt = null; + ImmutableArray annotations = null; if (pe instanceof Expression) { kjt = services.getTypeConverter().getKeYJavaType((Expression) pe, ec); } else { kjt = ((TypeRef) pe).getKeYJavaType(); + annotations = ((TypeRef) pe).getAnnotations(); } + annotations = annotations == null ? new ImmutableArray<>() : annotations; + assert kjt != null; if (!(kjt.getJavaType() instanceof PrimitiveType)) { if (kjt.getJavaType() instanceof ArrayType) { return new ProgramElement[] { KeYJavaASTFactory.typeRef(kjt, - ((ArrayType) kjt.getJavaType()).getDimension()) }; + ((ArrayType) kjt.getJavaType()).getDimension(), annotations) }; } } - return new ProgramElement[] { KeYJavaASTFactory.typeRef(kjt) }; + return new ProgramElement[] { KeYJavaASTFactory.typeRef(kjt, 0, annotations) }; } } diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformation.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformation.java index 69e2d642d23..912d1e00a66 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformation.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformation.java @@ -10,6 +10,7 @@ import de.uka.ilkd.key.java.ast.*; import de.uka.ilkd.key.java.ast.expression.Expression; import de.uka.ilkd.key.java.ast.expression.literal.BooleanLiteral; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.statement.*; import de.uka.ilkd.key.logic.ProgramElementName; import de.uka.ilkd.key.logic.op.ProgramVariable; @@ -234,7 +235,8 @@ public void performActionOnWhile(While x) { Catch ctch = KeYJavaASTFactory.catchClause(KeYJavaASTFactory.parameterDeclaration(javaInfo, - javaInfo.getKeYJavaType("java.lang.Throwable"), excParam), catchStatements); + new TypeRef(javaInfo.getKeYJavaType("java.lang.Throwable")), excParam), + catchStatements); Branch[] branch = { ctch }; Statement res = KeYJavaASTFactory.tryBlock(newBody, branch); @@ -298,7 +300,8 @@ public void performActionOnEnhancedFor(EnhancedFor x) { Catch ctch = KeYJavaASTFactory.catchClause(KeYJavaASTFactory.parameterDeclaration(javaInfo, - javaInfo.getKeYJavaType("java.lang.Throwable"), excParam), catchStatements); + new TypeRef(javaInfo.getKeYJavaType("java.lang.Throwable")), excParam), + catchStatements); addChild(KeYJavaASTFactory.tryBlock(body, ctch)); changed(); diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformer.java b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformer.java index 3f0907a142d..a369d49b9f1 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformer.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/metaconstruct/WhileInvariantTransformer.java @@ -14,6 +14,7 @@ import de.uka.ilkd.key.java.ast.StatementBlock; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; import de.uka.ilkd.key.java.ast.expression.literal.BooleanLiteral; +import de.uka.ilkd.key.java.ast.reference.TypeRef; import de.uka.ilkd.key.java.ast.statement.If; import de.uka.ilkd.key.java.ast.statement.MethodFrame; import de.uka.ilkd.key.java.ast.statement.TransactionStatement; @@ -145,7 +146,7 @@ public JTerm transform(TermLabelState termLabelState, Rule rule, getNewLocalvariable("break_" + breakCounter++, "boolean", services); b.setProgramVariable(newVar); stmnt.add(KeYJavaASTFactory.declare(newVar, BooleanLiteral.FALSE, - javaInfo.getKeYJavaType("boolean"))); + new TypeRef(javaInfo.getKeYJavaType("boolean")))); numberOfBreaks++; Statement s; if (b.getBreak().getLabel() != null) { @@ -183,7 +184,7 @@ public JTerm transform(TermLabelState termLabelState, Rule rule, post, rule, ruleApp, goal, applicationPos, services)); if (returnType != null) { - stmnt.add(KeYJavaASTFactory.declare(returnExpression, returnType)); + stmnt.add(KeYJavaASTFactory.declare(returnExpression, new TypeRef(returnType))); } } @@ -197,10 +198,10 @@ public JTerm transform(TermLabelState termLabelState, Rule rule, // we catch all exceptions stmnt.add(KeYJavaASTFactory.declare(excFlag, BooleanLiteral.FALSE, - javaInfo.getKeYJavaType("boolean"))); + new TypeRef(javaInfo.getKeYJavaType("boolean")))); excFlagTerm = typeConv.convertToLogicElement(excFlag); stmnt.add(KeYJavaASTFactory.declare(thrownException, - javaInfo.getKeYJavaType("java.lang.Throwable"))); + new TypeRef(javaInfo.getKeYJavaType("java.lang.Throwable")))); resultSubterms.add(normalCaseAndContinue(termLabelState, services, applicationPos, rule, ruleApp, goal, applicationSequent, contFlagTerm, returnFlagTerm, breakFlagTerm, @@ -287,7 +288,8 @@ private ProgramVariable getNewLocalvariable(String varNameBase, String varType, private ProgramVariable getNewLocalvariable(String varNameBase, KeYJavaType varType, Services services) { return KeYJavaASTFactory.localVariable( - services.getVariableNamer().getTemporaryNameProposal(varNameBase), varType); + services.getVariableNamer().getTemporaryNameProposal(varNameBase), + new TypeRef(varType)); } @@ -331,7 +333,7 @@ private JTerm createLongJunctorTerm(Junctor junctor, ArrayList terms) { private Statement returnFlagDecl(ProgramVariable returnFlag, SVInstantiations svInst) { return KeYJavaASTFactory.declare(returnFlag, BooleanLiteral.FALSE, - javaInfo.getKeYJavaType("boolean")); + new TypeRef(javaInfo.getKeYJavaType("boolean"))); } private JTerm returnCase(TermLabelState termLabelState, ProgramVariable returnFlag, @@ -354,12 +356,12 @@ private JTerm returnCase(TermLabelState termLabelState, ProgramVariable returnFl private Statement breakFlagDecl(ProgramVariable breakFlag) { return KeYJavaASTFactory.declare(breakFlag, BooleanLiteral.FALSE, - javaInfo.getKeYJavaType("boolean")); + new TypeRef(javaInfo.getKeYJavaType("boolean"))); } private Statement contFlagDecl(ProgramVariable contFlag) { return KeYJavaASTFactory.declare(contFlag, BooleanLiteral.FALSE, - javaInfo.getKeYJavaType("boolean")); + new TypeRef(javaInfo.getKeYJavaType("boolean"))); } private JTerm breakCase(TermLabelState termLabelState, ProgramVariable breakFlag, JTerm post, diff --git a/key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletGenerator.java b/key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletGenerator.java index 077d8ec8aaa..8f6974e93f1 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletGenerator.java +++ b/key.core/src/main/java/de/uka/ilkd/key/rule/tacletbuilder/TacletGenerator.java @@ -247,6 +247,11 @@ public ImmutableSet generateFunctionalRepresentsTaclets(Name name, final Pair> limited = limitTerm(schemaRhs, toLimit, services); final JTerm limitedRhs = limited.first; result = result.union(limited.second); + final TermAndBoundVarPair schemaRepresentsLimited = + new TermAndBoundVarPair( + OpReplacer.replace(schemaRepresents.term.sub(1), limitedRhs, schemaRepresents.term, + services.getTermFactory()), + schemaRepresents.boundVars); // create if sequent final boolean finalClass = kjt.getJavaType() instanceof ClassDeclaration @@ -328,7 +333,7 @@ public ImmutableSet generateFunctionalRepresentsTaclets(Name name, if (satisfiability) { tacletBuilder.addRuleSet(new RuleSet(new Name("split"))); } - for (VariableSV boundSV : schemaRepresents.boundVars) { + for (VariableSV boundSV : schemaRepresentsLimited.boundVars) { for (SchemaVariable heapSV : heapSVs) { tacletBuilder.addVarsNotFreeIn(boundSV, heapSV); } @@ -345,7 +350,7 @@ public ImmutableSet generateFunctionalRepresentsTaclets(Name name, if (satisfiability) { functionalRepresentsAddSatisfiabilityBranch(target, services, heapSVs, selfSV, paramSVs, - schemaRepresents, tacletBuilder); + schemaRepresentsLimited, tacletBuilder); } tacletBuilder.setApplicationRestriction( new ApplicationRestriction(ApplicationRestriction.SAME_UPDATE_LEVEL)); diff --git a/key.core/src/main/java/de/uka/ilkd/key/speclang/AuxiliaryContract.java b/key.core/src/main/java/de/uka/ilkd/key/speclang/AuxiliaryContract.java index 53a30efff06..ad845423f4d 100644 --- a/key.core/src/main/java/de/uka/ilkd/key/speclang/AuxiliaryContract.java +++ b/key.core/src/main/java/de/uka/ilkd/key/speclang/AuxiliaryContract.java @@ -17,6 +17,8 @@ import de.uka.ilkd.key.java.ast.SourceElement; import de.uka.ilkd.key.java.ast.StatementBlock; import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType; +import de.uka.ilkd.key.java.ast.reference.TypeRef; +import de.uka.ilkd.key.java.ast.reference.TypeReference; import de.uka.ilkd.key.java.ast.statement.Break; import de.uka.ilkd.key.java.ast.statement.Continue; import de.uka.ilkd.key.java.ast.statement.For; @@ -1021,7 +1023,8 @@ public VariablesCreator(final JavaStatement statement, final List