Skip to content

Commit

Permalink
Deal with type definition contexts for counterexample/witnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Nov 13, 2023
1 parent c4c7257 commit d6f7f21
Showing 1 changed file with 50 additions and 35 deletions.
85 changes: 50 additions & 35 deletions lsp/src/main/java/workspace/plugins/POPluginSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fujitsu.vdmj.po.definitions.PODefinition;
import com.fujitsu.vdmj.po.definitions.POExplicitFunctionDefinition;
import com.fujitsu.vdmj.po.definitions.POImplicitFunctionDefinition;
import com.fujitsu.vdmj.po.definitions.POTypeDefinition;
import com.fujitsu.vdmj.po.modules.POModuleList;
import com.fujitsu.vdmj.po.patterns.POPattern;
import com.fujitsu.vdmj.po.patterns.POPatternList;
Expand Down Expand Up @@ -99,49 +100,17 @@ protected JSONObject getLaunch(ProofObligation po, Context ctxt)
if (def instanceof POExplicitFunctionDefinition)
{
POExplicitFunctionDefinition efd = (POExplicitFunctionDefinition)def;
StringBuilder callString = new StringBuilder();
PORemoveIgnoresVisitor.init();

for (POPatternList pl: efd.paramPatternList)
{
callString.append("(");
String sep = "";

for (POPattern p: pl)
{
String match = paramMatch(p.removeIgnorePatterns(), ctxt);

if (match == null)
{
return null; // Can't match some params
}

callString.append(sep);
callString.append(match);
sep = ", ";
}

callString.append(")");
}

result = new JSONObject(
"name", "PO #" + po.number + " counterexample",
"type", "vdm",
"request", "launch",
"noDebug", false,
"defaultName", def.name.getModule(),
"command", "print " + def.name.getName() + callString
);
result = launchExplicitFunction(po, efd, ctxt);
}
else if (def instanceof POImplicitFunctionDefinition)
{
POImplicitFunctionDefinition efd = (POImplicitFunctionDefinition)def;
POImplicitFunctionDefinition ifd = (POImplicitFunctionDefinition)def;
StringBuilder callString = new StringBuilder();
callString.append("(");
String sep = "";
PORemoveIgnoresVisitor.init();

for (POPatternListTypePair pl: efd.parameterPatterns)
for (POPatternListTypePair pl: ifd.parameterPatterns)
{
for (POPattern p: pl.patterns)
{
Expand Down Expand Up @@ -169,9 +138,55 @@ else if (def instanceof POImplicitFunctionDefinition)
"command", "print " + def.name.getName() + callString
);
}
else if (def instanceof POTypeDefinition)
{
POTypeDefinition td = (POTypeDefinition)def;

if (td.invdef != null)
{
result = launchExplicitFunction(po, td.invdef, ctxt);
}
}

return result;
}

private JSONObject launchExplicitFunction(ProofObligation po, POExplicitFunctionDefinition efd, Context ctxt)
{
StringBuilder callString = new StringBuilder();
PORemoveIgnoresVisitor.init();

for (POPatternList pl: efd.paramPatternList)
{
callString.append("(");
String sep = "";

for (POPattern p: pl)
{
String match = paramMatch(p.removeIgnorePatterns(), ctxt);

if (match == null)
{
return null; // Can't match some params
}

callString.append(sep);
callString.append(match);
sep = ", ";
}

callString.append(")");
}

return new JSONObject(
"name", "PO #" + po.number + " counterexample",
"type", "vdm",
"request", "launch",
"noDebug", false,
"defaultName", efd.name.getModule(),
"command", "print " + efd.name.getName() + callString
);
}

private String paramMatch(POPattern p, Context ctxt)
{
Expand Down

0 comments on commit d6f7f21

Please sign in to comment.