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

NewValidator Changes #733

Merged
merged 29 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1fb79eb
Refactored NewValidator.java to work with Sootup.
akshitad11 Oct 30, 2023
dc0277b
Changes in NewValidator.java
akshitad11 Oct 30, 2023
be5face
Formatting changes after executing fmt maven plugin.
akshitad11 Nov 2, 2023
bbf8513
add Validator Interceptor draft
swissiety Nov 10, 2023
81034eb
add licenseheader
swissiety Nov 11, 2023
32d3e8d
Changes to increase test coverage.
akshitad11 Nov 15, 2023
242492f
Merge branch 'develop' of https://github.com/soot-oss/SootUp into val…
akshitad11 Nov 15, 2023
4961fe2
Formatting changes
akshitad11 Nov 16, 2023
4d3022c
minor
kadirayk Nov 22, 2023
9722c61
Merge branch 'develop' of https://github.com/soot-oss/SootUp into val…
akshitad11 Nov 30, 2023
6868bb4
validate method signature change
akshitad11 Dec 6, 2023
2368035
Merge branch 'develop' of https://github.com/soot-oss/SootUp into val…
akshitad11 Dec 6, 2023
30bde64
Deleting files, jimple file used for testing
akshitad11 Dec 6, 2023
e7eae50
Renaming to handle ambiguity
akshitad11 Dec 11, 2023
3e99c3a
Merge branch 'develop' of https://github.com/soot-oss/SootUp into val…
akshitad11 Dec 11, 2023
d8e357a
use equals instead of contains
kadirayk Dec 19, 2023
8085ac9
move test to integration
kadirayk Dec 19, 2023
7d21bf9
Merge remote-tracking branch 'origin/develop' into validator_changes
kadirayk Dec 19, 2023
732bcd3
remove JimpleProject
kadirayk Dec 19, 2023
8bde134
remove hardcoded version
kadirayk Dec 19, 2023
331d059
Fixing Tests
akshitad11 Dec 19, 2023
dba836e
Merge remote-tracking branch 'origin/validator_changes' into validato…
akshitad11 Dec 19, 2023
397dcef
Merge branch 'develop' into validator_changes
akshitad11 Dec 19, 2023
3bcdb99
Refactoring NewValidator tests
akshitad11 Dec 19, 2023
64f5d8d
Commenting FieldRefValidator changes.
akshitad11 Dec 20, 2023
57209fb
Rollback changes for FieldRefValidator
akshitad11 Dec 21, 2023
e2a0747
Rollback changes for FieldRefValidator
akshitad11 Dec 21, 2023
ae8ede5
Rollback LocalsValidator changes
akshitad11 Dec 21, 2023
3dd6d09
Formatting changes
akshitad11 Dec 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import sootup.core.model.Body;
import sootup.core.model.Position;
import sootup.core.types.Type;
import sootup.core.types.VoidType;
import sootup.core.util.Copyable;
import sootup.core.util.printer.StmtPrinter;

Expand All @@ -57,7 +58,11 @@
/** Constructs a JimpleLocal of the given name and type. */
public Local(@Nonnull String name, @Nonnull Type type, @Nonnull Position position) {
this.name = name;
this.type = type;
if (type instanceof VoidType) {
throw new RuntimeException("Type should not be VoidType");

Check warning on line 62 in sootup.core/src/main/java/sootup/core/jimple/basic/Local.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/jimple/basic/Local.java#L62

Added line #L62 was not covered by tests
} else {
this.type = type;
}
this.position = position;
}

Expand Down
25 changes: 8 additions & 17 deletions sootup.core/src/main/java/sootup/core/model/Body.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public class Body implements Copyable {
new ValuesValidator(),
new CheckInitValidator(),
new CheckTypesValidator(),
new CheckVoidLocalesValidator(),
new CheckEscapingValidator());
new CheckVoidLocalesValidator());

/**
* Creates an body which is not associated to any method.
Expand All @@ -89,7 +88,7 @@ private Body(
this.graph = /* FIXME: [ms] make immutable when availabe */
new MutableBlockStmtGraph(stmtGraph).unmodifiableStmtGraph();
this.position = position;
checkInit();
// checkInit();
}

/**
Expand Down Expand Up @@ -122,14 +121,6 @@ public int getLocalCount() {
return locals.size();
}

private void runValidation(BodyValidator validator) {
final List<ValidationException> exceptionList = new ArrayList<>();
validator.validate(this, exceptionList);
if (!exceptionList.isEmpty()) {
throw exceptionList.get(0);
}
}

/** Verifies that a Value is not used in more than one place. */
// TODO: #535 implement validator public void validateValues() { runValidation(new
// ValuesValidator());}
Expand All @@ -141,9 +132,9 @@ private void runValidation(BodyValidator validator) {
/** Verifies that each use in this Body has a def. */
// TODO: #535 implement validator public void validateUses() { runValidation(new
// UsesValidator()); }
private void checkInit() {
runValidation(new CheckInitValidator());
}
// private void checkInit() {
// runValidation(new CheckInitValidator(),);
// }
akshitad11 marked this conversation as resolved.
Show resolved Hide resolved

/** Returns a backed chain of the locals declared in this Body. */
public Set<Local> getLocals() {
Expand Down Expand Up @@ -279,9 +270,9 @@ public boolean isStmtBranchTarget(@Nonnull Stmt targetStmt) {
return getStmtGraph().isStmtBranchTarget(targetStmt);
}

public void validateIdentityStatements() {
runValidation(new IdentityStatementsValidator());
}
// public void validateIdentityStatements() {
// runValidation(new IdentityStatementsValidator());
// }

/** Returns the first non-identity stmt in this body. */
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

/** Implement this interface if you want to provide your own body Validator */
public interface BodyValidator {
/**
* Validates the given body and saves all validation errors in the given list.
*
* @param body the body to check
* @param exceptions the list of exceptions
* @param view the view
*/
void validate(Body body, List<ValidationException> exceptions);
List<ValidationException> validate(Body body, View<?> view);

/**
* Basic validators run essential checks and are run always if validate is called.<br>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

public class CheckInitValidator implements BodyValidator {

@Override
public void validate(Body body, List<ValidationException> exception) {
public List<ValidationException> validate(Body body, View<?> view) {

// TODO: #535 implement validator
// check code copied from old soot
Expand All @@ -41,6 +42,7 @@
* "Local variable $1 is not definitively defined at this point".replace("$1", l.getName()), "Warning: Local variable " +
* l + " not definitely defined at " + s + " in " + body.getMethod(), false); } } } }
*/
return null;

Check warning on line 45 in sootup.core/src/main/java/sootup/core/validation/CheckInitValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/CheckInitValidator.java#L45

Added line #L45 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

public class CheckTypesValidator implements BodyValidator {

@Override
public void validate(Body body, List<ValidationException> exception) {
public List<ValidationException> validate(Body body, View<?> view) {
// TODO: check code from old soot in the comment below
/*
* for (Unit u : body.getUnits()) { String errorSuffix = " at " + u + " in " + body.getMethod();
Expand Down Expand Up @@ -88,6 +89,7 @@
* body.getMethod())); } } } return; } exception.add(new ValidationException(stmt, "Warning: Bad types" + errorSuffix +
* " in " + body.getMethod()));
*/
return null;

Check warning on line 92 in sootup.core/src/main/java/sootup/core/validation/CheckTypesValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/CheckTypesValidator.java#L92

Added line #L92 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

public class CheckVoidLocalesValidator implements BodyValidator {

@Override
public void validate(Body body, List<ValidationException> exception) {
public List<ValidationException> validate(Body body, View<?> view) {
// TODO: check copied code from old soot
/*
* for (Local l : body.getLocals()) { if (l.getType() instanceof VoidType) { exception.add(new ValidationException(l,
* "Local " + l + " in " + body.getMethod() + " defined with void type")); } }
*/
return null;

Check warning on line 38 in sootup.core/src/main/java/sootup/core/validation/CheckVoidLocalesValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/CheckVoidLocalesValidator.java#L38

Added line #L38 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997-2020 Raja Vallée-Rai, Linghui Luo, Markus Schmidt and others
* Copyright (C) 1997-2020 Raja Vallée-Rai, Christian Brüggemann, Markus Schmidt and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
Expand All @@ -22,14 +22,19 @@
* #L%
*/

import java.util.ArrayList;
import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

public class FieldRefValidator implements BodyValidator {

/** Checks the consistency of field references. */
// Checks the consistency of field references.
@Override
public void validate(Body body, List<ValidationException> exceptions) {
public List<ValidationException> validate(Body body, View<?> view) {

List<ValidationException> validationException = new ArrayList<>();

Check warning on line 36 in sootup.core/src/main/java/sootup/core/validation/FieldRefValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/FieldRefValidator.java#L36

Added line #L36 was not covered by tests

// TODO: check copied code from old soot
/*
* SootMethod methodRef = body.getMethod(); if (methodRef.isAbstract()) { return; }
Expand All @@ -54,6 +59,8 @@
* "Trying to get an instance field which is static: " + v)); } } else { throw new RuntimeException("unknown field ref");
* } }
*/

return validationException;

Check warning on line 63 in sootup.core/src/main/java/sootup/core/validation/FieldRefValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/FieldRefValidator.java#L63

Added line #L63 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

public class IdentityStatementsValidator implements BodyValidator {

Expand All @@ -36,9 +37,11 @@
* <li>param-references must precede all statements that are not themselves param-references or
* this-references, if they occur at all
* </ol>
*
* @return
*/
@Override
public void validate(Body body, List<ValidationException> exceptions) {
public List<ValidationException> validate(Body body, View<?> view) {
// TODO: check copied code from old soot
/*
* SootMethod methodRef = body.getMethod(); if (methodRef.isAbstract()) { return; }
Expand All @@ -57,6 +60,7 @@
* // @caughtexception statement foundNonThisOrParamIdentityStatement = true; } } else { // non-identity statement
* foundNonThisOrParamIdentityStatement = true; } firstStatement = false; }
*/
return null;

Check warning on line 63 in sootup.core/src/main/java/sootup/core/validation/IdentityStatementsValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/IdentityStatementsValidator.java#L63

Added line #L63 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

/**
* This validator checks whether each ParameterRef and ThisRef is used exactly once.
Expand All @@ -32,9 +33,13 @@
*/
public class IdentityValidator implements BodyValidator {

/** Checks whether each ParameterRef and ThisRef is used exactly once. */
/**
* Checks whether each ParameterRef and ThisRef is used exactly once.
*
* @return
*/
@Override
public void validate(Body body, List<ValidationException> exceptions) {
public List<ValidationException> validate(Body body, View<?> view) {
// TODO: check copied code from old soot
/*
* boolean hasThisLocal = false; int paramCount = body.getMethod().getParameterCount(); boolean[] parameterRefs = new
Expand All @@ -57,6 +62,7 @@
* String.format("There is no parameter local for parameter number %d", i))); } }
*
*/
return null;

Check warning on line 65 in sootup.core/src/main/java/sootup/core/validation/IdentityValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/IdentityValidator.java#L65

Added line #L65 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

/**
* A basic validator that checks whether the length of the invoke statement's argument list matches
Expand All @@ -34,13 +35,14 @@
public class InvokeArgumentValidator implements BodyValidator {

@Override
public void validate(Body body, List<ValidationException> exceptions) {
public List<ValidationException> validate(Body body, View<?> view) {
// TODO: check copied code from old soot
/*
* for (Unit u : body.getUnits()) { Stmt s = (Stmt) u; if (s.containsInvokeExpr()) { InvokeExpr iinvExpr =
* s.getInvokeExpr(); SootMethod callee = iinvExpr.getMethod(); if (callee != null && iinvExpr.getArgCount() !=
* callee.getParameterCount()) { exceptions.add(new ValidationException(s, "Invalid number of arguments")); } } }
*/
return null;

Check warning on line 45 in sootup.core/src/main/java/sootup/core/validation/InvokeArgumentValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/InvokeArgumentValidator.java#L45

Added line #L45 was not covered by tests
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,24 @@

import java.util.List;
import sootup.core.model.Body;
import sootup.core.views.View;

/**
* This validator checks whether the jimple traps are correct. It does not perform the same checks
* as {link sootup.validation.TrapsValidator}
*
* @see JimpleTrapValidator#validate(Body, List)
* @see BodyValidator#validate(Body, View)
* @author Marc Miltenberger
*/
public class JimpleTrapValidator implements BodyValidator {

/** Checks whether all Caught-Exception-References are associated to traps. */
/**
* Checks whether all Caught-Exception-References are associated to traps.
*
* @return
*/
@Override
public void validate(Body body, List<ValidationException> exceptions) {
public List<ValidationException> validate(Body body, View<?> view) {
// TODO: check copied code from old soot
/*
* Set<Unit> caughtUnits = new HashSet<Unit>(); for (Trap trap : body.getTraps()) {
Expand All @@ -52,6 +57,7 @@
* body.getMethod().getSignature() + " contains a caught exception reference," +
* "but not a corresponding trap using this statement as handler")); } } } }
*/
return null;

Check warning on line 60 in sootup.core/src/main/java/sootup/core/validation/JimpleTrapValidator.java

View check run for this annotation

Codecov / codecov/patch

sootup.core/src/main/java/sootup/core/validation/JimpleTrapValidator.java#L60

Added line #L60 was not covered by tests
}

@Override
Expand Down
Loading