Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native calls removal #158

Merged
merged 6 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lisa/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,13 @@ buildscript {
classpath 'org.ajoberstar.grgit:grgit-core:4.0.2'
classpath 'org.ajoberstar.grgit:grgit-gradle:4.0.2'

classpath 'com.github.roroche:plantuml-gradle-plugin:1.0.2'
classpath 'gradle.plugin.org.fmiw:plantuml-gradle-plugin:0.1'

classpath 'com.diffplug.spotless:spotless-plugin-gradle:5.15.0'
}
}

subprojects {
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'com.github.roroche.plantuml' // generation of plantuml from source code (visualization: https://www.planttext.com/)
apply plugin: 'org.fmiw.plantuml' // plantuml to png
apply plugin: 'org.ajoberstar.grgit' // parse git information during the build
apply plugin: 'com.diffplug.spotless' // code formatting task
apply plugin: 'checkstyle' // javadoc checking - coding conventions
Expand All @@ -78,7 +73,6 @@ subprojects {
apply plugin: 'jacoco' // coverage reports

apply from: "${project.rootDir}/code-style.gradle"
apply from: "${project.rootDir}/doc-extra.gradle"
apply from: "${project.rootDir}/java.gradle"
apply from: "${project.rootDir}/publishing.gradle"
}
50 changes: 0 additions & 50 deletions lisa/doc-extra.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Collection<CFGWithAnalysisResults<A, H, V>> getAnalysisResultsOf(CFG cfg)
@Override
public AnalysisState<A, H, V> getAbstractResultOf(CFGCall call, AnalysisState<A, H, V> entryState,
ExpressionSet<SymbolicExpression>[] parameters) throws SemanticException {
OpenCall open = new OpenCall(call.getCFG(), call.getLocation(), call.getQualifiedName(),
OpenCall open = new OpenCall(call.getCFG(), call.getLocation(), call.getTargetName(),
call.getStaticType(), call.getParameters());
return getAbstractResultOf(open, entryState, parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import it.unive.lisa.program.cfg.controlFlow.ControlFlowStructure;
import it.unive.lisa.program.cfg.edge.Edge;
import it.unive.lisa.program.cfg.statement.Expression;
import it.unive.lisa.program.cfg.statement.NaryExpression;
import it.unive.lisa.program.cfg.statement.PluggableStatement;
import it.unive.lisa.program.cfg.statement.Ret;
import it.unive.lisa.program.cfg.statement.Statement;
Expand Down Expand Up @@ -272,6 +273,8 @@ public void testStatements() {
extra.add("originating");
if (Call.class.isAssignableFrom(st))
extra.add("source");
if (NaryExpression.class.isAssignableFrom(st))
extra.add("order");
verify(st,
verifier -> verifier
.withIgnoredFields(ListUtils.union(expressionFields, extra).toArray(String[]::new)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import it.unive.lisa.program.SourceCodeLocation;
import it.unive.lisa.program.cfg.CFG;
import it.unive.lisa.program.cfg.statement.Expression;
import it.unive.lisa.program.cfg.statement.call.BinaryNativeCall;
import it.unive.lisa.symbolic.SymbolicExpression;
import it.unive.lisa.symbolic.value.BinaryExpression;
import it.unive.lisa.symbolic.value.operator.binary.BinaryOperator;
Expand All @@ -35,7 +34,7 @@
*
* @author <a href="mailto:[email protected]">Luca Negrini</a>
*/
public class IMPAddOrConcat extends BinaryNativeCall {
public class IMPAddOrConcat extends it.unive.lisa.program.cfg.statement.BinaryExpression {

/**
* Builds the addition.
Expand All @@ -55,14 +54,12 @@ public IMPAddOrConcat(CFG cfg, String sourceFile, int line, int col, Expression
protected <A extends AbstractState<A, H, V>,
H extends HeapDomain<H>,
V extends ValueDomain<V>> AnalysisState<A, H, V> binarySemantics(
AnalysisState<A, H, V> entryState,
InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V> leftState,
AnalysisState<A, H, V> state,
SymbolicExpression left,
AnalysisState<A, H, V> rightState,
SymbolicExpression right)
throws SemanticException {
AnalysisState<A, H, V> result = entryState.bottom();
AnalysisState<A, H, V> result = state.bottom();
BinaryOperator op;

for (Type tleft : left.getTypes())
Expand Down Expand Up @@ -92,7 +89,7 @@ else if (tright.isNumericType() || tright.isUntyped())
if (op == null)
continue;

result = result.lub(rightState.smallStepSemantics(
result = result.lub(state.smallStepSemantics(
new BinaryExpression(
op == StringConcat.INSTANCE
? Caches.types().mkSingletonSet(StringType.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import it.unive.lisa.interprocedural.InterproceduralAnalysis;
import it.unive.lisa.program.SourceCodeLocation;
import it.unive.lisa.program.cfg.CFG;
import it.unive.lisa.program.cfg.statement.BinaryExpression;
import it.unive.lisa.program.cfg.statement.Expression;
import it.unive.lisa.program.cfg.statement.call.BinaryNativeCall;
import it.unive.lisa.symbolic.SymbolicExpression;
import it.unive.lisa.symbolic.heap.AccessChild;
import it.unive.lisa.symbolic.heap.HeapDereference;
Expand All @@ -21,7 +21,7 @@
*
* @author <a href="mailto:[email protected]">Luca Negrini</a>
*/
public class IMPArrayAccess extends BinaryNativeCall {
public class IMPArrayAccess extends BinaryExpression {

/**
* Builds the array access.
Expand All @@ -42,20 +42,19 @@ public IMPArrayAccess(CFG cfg, String sourceFile, int line, int col, Expression
protected <A extends AbstractState<A, H, V>,
H extends HeapDomain<H>,
V extends ValueDomain<V>> AnalysisState<A, H, V> binarySemantics(
AnalysisState<A, H, V> entryState, InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V> leftState,
InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V> state,
SymbolicExpression left,
AnalysisState<A, H, V> rightState,
SymbolicExpression right)

throws SemanticException {

if (!left.getDynamicType().isArrayType() && !left.getDynamicType().isUntyped())
return entryState.bottom();
return state.bottom();
// it is not possible to detect the correct type of the field without
// resolving it. we rely on the rewriting that will happen inside heap
// domain to translate this into a variable that will have its correct
// type
HeapDereference deref = new HeapDereference(getRuntimeTypes(), left, getLocation());
return rightState.smallStepSemantics(new AccessChild(getRuntimeTypes(), deref, right, getLocation()), this);
return state.smallStepSemantics(new AccessChild(getRuntimeTypes(), deref, right, getLocation()), this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import it.unive.lisa.program.SourceCodeLocation;
import it.unive.lisa.program.cfg.CFG;
import it.unive.lisa.program.cfg.statement.Expression;
import it.unive.lisa.program.cfg.statement.call.NativeCall;
import it.unive.lisa.program.cfg.statement.NaryExpression;
import it.unive.lisa.symbolic.SymbolicExpression;
import it.unive.lisa.symbolic.heap.HeapAllocation;
import it.unive.lisa.symbolic.heap.HeapReference;
Expand All @@ -25,7 +25,7 @@
*
* @author <a href="mailto:[email protected]">Luca Negrini</a>
*/
public class IMPNewArray extends NativeCall {
public class IMPNewArray extends NaryExpression {

/**
* Builds the array allocation.
Expand All @@ -39,31 +39,24 @@ public class IMPNewArray extends NativeCall {
*/
public IMPNewArray(CFG cfg, String sourceFile, int line, int col, Type type, Expression[] dimensions) {
super(cfg, new SourceCodeLocation(sourceFile, line, col), "new " + type + "[]",
ArrayType.lookup(type, dimensions.length),
dimensions);
ArrayType.lookup(type, dimensions.length), dimensions);
}

@Override
public <A extends AbstractState<A, H, V>,
H extends HeapDomain<H>,
V extends ValueDomain<V>> AnalysisState<A, H, V> callSemantics(
AnalysisState<A, H, V> entryState, InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V>[] computedStates,
V extends ValueDomain<V>> AnalysisState<A, H, V> expressionSemantics(
InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V> state,
ExpressionSet<SymbolicExpression>[] params)
throws SemanticException {
// it corresponds to the analysis state after the evaluation of all the
// parameters of this call
// (the semantics of this call does not need information about the
// intermediate analysis states)
AnalysisState<A, H,
V> lastPostState = computedStates.length == 0 ? entryState : computedStates[computedStates.length - 1];
AnalysisState<A, H,
V> sem = lastPostState.smallStepSemantics(new HeapAllocation(getRuntimeTypes(), getLocation()), this);
HeapAllocation alloc = new HeapAllocation(getRuntimeTypes(), getLocation());
AnalysisState<A, H, V> sem = state.smallStepSemantics(alloc, this);

AnalysisState<A, H, V> result = entryState.bottom();
AnalysisState<A, H, V> result = state.bottom();
for (SymbolicExpression loc : sem.getComputedExpressions()) {
AnalysisState<A, H,
V> refSem = sem.smallStepSemantics(new HeapReference(loc.getTypes(), loc, getLocation()), this);
HeapReference ref = new HeapReference(loc.getTypes(), loc, getLocation());
AnalysisState<A, H, V> refSem = sem.smallStepSemantics(ref, this);
result = result.lub(refSem);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import it.unive.lisa.program.SourceCodeLocation;
import it.unive.lisa.program.cfg.CFG;
import it.unive.lisa.program.cfg.statement.Expression;
import it.unive.lisa.program.cfg.statement.NaryExpression;
import it.unive.lisa.program.cfg.statement.VariableRef;
import it.unive.lisa.program.cfg.statement.call.NativeCall;
import it.unive.lisa.program.cfg.statement.call.UnresolvedCall;
import it.unive.lisa.symbolic.SymbolicExpression;
import it.unive.lisa.symbolic.heap.HeapAllocation;
Expand All @@ -32,7 +32,7 @@
*
* @author <a href="mailto:[email protected]">Luca Negrini</a>
*/
public class IMPNewObj extends NativeCall {
public class IMPNewObj extends NaryExpression {

/**
* Builds the object allocation and initialization.
Expand All @@ -51,30 +51,29 @@ public IMPNewObj(CFG cfg, String sourceFile, int line, int col, Type type, Expre
@Override
public <A extends AbstractState<A, H, V>,
H extends HeapDomain<H>,
V extends ValueDomain<V>> AnalysisState<A, H, V> callSemantics(
AnalysisState<A, H, V> entryState, InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V>[] computedStates,
V extends ValueDomain<V>> AnalysisState<A, H, V> expressionSemantics(
InterproceduralAnalysis<A, H, V> interprocedural,
AnalysisState<A, H, V> state,
ExpressionSet<SymbolicExpression>[] params)
throws SemanticException {
HeapAllocation created = new HeapAllocation(getRuntimeTypes(), getLocation());

// we need to add the receiver to the parameters
VariableRef paramThis = new VariableRef(getCFG(), getLocation(), "this",
getStaticType());
Expression[] fullExpressions = ArrayUtils.insert(0, getParameters(), paramThis);
VariableRef paramThis = new VariableRef(getCFG(), getLocation(), "this", getStaticType());
Expression[] fullExpressions = ArrayUtils.insert(0, getSubExpressions(), paramThis);
ExpressionSet<SymbolicExpression>[] fullParams = ArrayUtils.insert(0, params, new ExpressionSet<>(created));

UnresolvedCall call = new UnresolvedCall(getCFG(), getLocation(),
IMPFrontend.CALL_STRATEGY, true, getStaticType().toString(), fullExpressions);
call.inheritRuntimeTypesFrom(this);
AnalysisState<A, H, V> sem = call.callSemantics(entryState, interprocedural, computedStates, fullParams);
call.setRuntimeTypes(getRuntimeTypes());
AnalysisState<A, H, V> sem = call.expressionSemantics(interprocedural, state, fullParams);

if (!call.getMetaVariables().isEmpty())
sem = sem.forgetIdentifiers(call.getMetaVariables());

sem = sem.smallStepSemantics(created, this);

AnalysisState<A, H, V> result = entryState.bottom();
AnalysisState<A, H, V> result = state.bottom();
for (SymbolicExpression loc : sem.getComputedExpressions())
result = result.lub(sem.smallStepSemantics(new HeapReference(loc.getTypes(), loc, getLocation()), call));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.unive.lisa.checks.warnings;

import it.unive.lisa.program.cfg.CodeLocation;
import java.util.Objects;

/**
* A warning reported by LiSA on the program under analysis. This warning is
Expand All @@ -17,12 +18,12 @@ public abstract class WarningWithLocation extends Warning {
/**
* Builds the warning.
*
* @param location the location in the source file where this warning is
* located. If unknown, use {@code, null}
* @param location the location in the program where this warning is located
* @param message the message of this warning
*/
protected WarningWithLocation(CodeLocation location, String message) {
super(message);
Objects.requireNonNull(location, "The location of a warning with location cannot be null");
this.location = location;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
public interface CodeElement {

/**
* Yields the location where this code element appears in the source file.
* Yields the location where this code element appears in the program.
*
* @return the location where this code element apperars in the source file
* @return the location where this code element apperars in the program
*/
CodeLocation getLocation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class CompilationUnit extends Unit implements CodeElement {

/**
* The location in the source file of this unit
* The location in the program of this unit
*/
private final CodeLocation location;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Global implements CodeElement {

/**
* Builds an untyped global variable, identified by its name. The location
* where this global happens is unknown (i.e. no source file/line/column is
* where this global happens is unknown (e.g. no source file/line/column is
* available) as well as its type (i.e. it is {#link Untyped#INSTANCE}).
*
* @param location the location of this global variable
Expand All @@ -46,7 +46,7 @@ public Global(CodeLocation location, String name) {
* happening at the given location in the program.
*
* @param location the location where this global is defined within the
* source file. If unknown, use {@code null}
* program
* @param name the name of this global
* @param staticType the type of this global. If unknown, use
* {@link Untyped#INSTANCE}
Expand All @@ -60,7 +60,7 @@ public Global(CodeLocation location, String name, Type staticType) {
* happening at the given location in the program.
*
* @param location the location where this global is defined within the
* source file. If unknown, use {@code null}
* program
* @param name the name of this global
* @param staticType the type of this global. If unknown, use
* {@link Untyped#INSTANCE}
Expand Down
Loading