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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText : © 2025 TU Wien <vadl@tuwien.ac.at>
// SPDX-FileCopyrightText : © 2025-2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -19,33 +19,36 @@
import com.google.auto.service.AutoService;
import com.google.errorprone.BugPattern;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.VariableTree;
import java.util.ArrayList;
import java.util.List;
import vadl.javaannotations.AbstractAnnotationChecker;

/**
* The CollectInputsChecker class is a bug checker that checks for classes with fields
* annotated with @Input and ensures that they override the collectInputs method.
* annotated with @Input and ensures that they override the forEachInput method.
* It will fail if its implementation is not as expected.
*/
@AutoService(BugChecker.class)
@BugPattern(
name = "CollectInputs",
summary = "Classes with @Input annotated fields must override the collectInputs method",
summary = "Classes with @Input annotated fields must override the forEachInput method",
severity = BugPattern.SeverityLevel.ERROR
)
@SuppressWarnings("BugPatternNaming")
public class CollectInputsChecker extends AbstractAnnotationChecker implements DefaultCollectMixin {
public class CollectInputsChecker extends AbstractAnnotationChecker {

private static final String PARAM_TYPE = "java.util.List" + "<" + CheckerUtils.NODE + ">";
private static final String PARAM_TYPE =
"java.util.function.Consumer" + "<" + CheckerUtils.NODE + ">";

/**
* Constructs the bug checker.
*/
public CollectInputsChecker() {
super(
Input.class,
"collectInputs",
"forEachInput",
"void",
List.of(PARAM_TYPE)
);
Expand All @@ -54,6 +57,27 @@ public CollectInputsChecker() {
@Override
protected List<String> expectedMethodStatements(List<String> paramNames,
List<VariableTree> fields) {
return defaultCollectStatements(methodName, paramNames, fields, true);
var stmts = new ArrayList<String>();
var consumerName = paramNames.get(0);

stmts.add("super.%s(%s);".formatted(methodName, consumerName));
for (var field : fields) {
var type = ASTHelpers.getType(field);
assert type != null;

var hasAnnotation = ASTHelpers
.hasDirectAnnotationWithSimpleName(field, "Nullable");

var stmt = type.toString().startsWith(CheckerUtils.NODELIST)
? "%s.forEach(%s);".formatted(field.getName(), consumerName)
: "%s.accept(%s);".formatted(consumerName, field.getName());

if (hasAnnotation) {
stmt = "if (this.%s != null) { %s }".formatted(field.getName(), stmt);
}

stmts.add(stmt);
}
return stmts;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText : © 2025 TU Wien <vadl@tuwien.ac.at>
// SPDX-FileCopyrightText : © 2025-2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -19,34 +19,36 @@
import com.google.auto.service.AutoService;
import com.google.errorprone.BugPattern;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.VariableTree;
import java.util.ArrayList;
import java.util.List;
import vadl.javaannotations.AbstractAnnotationChecker;

/**
* The CollectSuccessorsChecker class is a bug checker that checks for classes with @Successor
* annotated fields that must override the collectSuccessors method.
* annotated fields that must override the forEachSuccessor method.
* It will fail if the method implementation is not as expected.
*/
@AutoService(BugChecker.class)
@BugPattern(
name = "CollectSuccessors",
summary = "Classes with @Successor annotated fields must override the collectSuccessors method",
summary = "Classes with @Successor annotated fields must override the forEachSuccessor method",
severity = BugPattern.SeverityLevel.ERROR
)
@SuppressWarnings("BugPatternNaming")
public class CollectSuccessorsChecker extends AbstractAnnotationChecker
implements DefaultCollectMixin {
public class CollectSuccessorsChecker extends AbstractAnnotationChecker {

private static final String PARAM_TYPE = "java.util.List<" + CheckerUtils.NODE + ">";
private static final String PARAM_TYPE =
"java.util.function.Consumer" + "<" + CheckerUtils.NODE + ">";

/**
* Constructs the bug checker.
*/
public CollectSuccessorsChecker() {
super(
Successor.class,
"collectSuccessors",
"forEachSuccessor",
"void",
List.of(PARAM_TYPE)
);
Expand All @@ -55,6 +57,27 @@ public CollectSuccessorsChecker() {
@Override
protected List<String> expectedMethodStatements(List<String> paramNames,
List<VariableTree> fields) {
return defaultCollectStatements(methodName, paramNames, fields, true);
var stmts = new ArrayList<String>();
var consumerName = paramNames.get(0);

stmts.add("super.%s(%s);".formatted(methodName, consumerName));
for (var field : fields) {
var type = ASTHelpers.getType(field);
assert type != null;

var hasAnnotation = ASTHelpers
.hasDirectAnnotationWithSimpleName(field, "Nullable");

var stmt = type.toString().startsWith(CheckerUtils.NODELIST)
? "%s.forEach(%s);".formatted(field.getName(), consumerName)
: "%s.accept(%s);".formatted(consumerName, field.getName());

if (hasAnnotation) {
stmt = "if (this.%s != null) { %s }".formatted(field.getName(), stmt);
}

stmts.add(stmt);
}
return stmts;
}
}
11 changes: 6 additions & 5 deletions vadl/main/vadl/cppCodeGen/model/nodes/CppUpdateBitRangeNode.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText : © 2025 TU Wien <vadl@tuwien.ac.at>
// SPDX-FileCopyrightText : © 2025-2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -18,6 +18,7 @@


import java.util.List;
import java.util.function.Consumer;
import vadl.cppCodeGen.CppCodeGenGraphNodeVisitor;
import vadl.javaannotations.viam.DataValue;
import vadl.javaannotations.viam.Input;
Expand Down Expand Up @@ -76,10 +77,10 @@ public <T extends GraphNodeVisitor> void accept(T visitor) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.add(value);
collection.add(patch);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
consumer.accept(value);
consumer.accept(patch);
}

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

package vadl.iss.passes.common.opDecomposition.nodes;

import java.util.List;
import java.util.function.Consumer;
import vadl.javaannotations.viam.Input;
import vadl.types.Type;
import vadl.viam.graph.GraphVisitor;
Expand Down Expand Up @@ -64,9 +64,9 @@ protected void applyOnInputsUnsafe(GraphVisitor.Applier<Node> visitor) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.add(arg1);
collection.add(arg2);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
consumer.accept(arg1);
consumer.accept(arg2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package vadl.iss.passes.common.safeResourceRead.nodes;

import java.util.List;
import java.util.function.Consumer;
import vadl.javaannotations.viam.Input;
import vadl.viam.graph.GraphNodeVisitor;
import vadl.viam.graph.GraphVisitor;
Expand Down Expand Up @@ -70,9 +70,9 @@ public <T extends GraphNodeVisitor> void accept(T visitor) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.add(value);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
consumer.accept(value);
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions vadl/main/vadl/iss/passes/nodes/IssConstExtractNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package vadl.iss.passes.nodes;

import java.util.List;
import java.util.function.Consumer;
import vadl.iss.passes.common.opDecomposition.nodes.IssExprNode;
import vadl.iss.passes.tcg.lowering.TcgExtend;
import vadl.javaannotations.viam.DataValue;
Expand Down Expand Up @@ -153,9 +154,9 @@ protected void collectData(List<Object> collection) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.add(value);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
consumer.accept(value);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions vadl/main/vadl/iss/passes/nodes/IssGhostCastNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package vadl.iss.passes.nodes;

import java.util.List;
import java.util.function.Consumer;
import vadl.iss.passes.common.opDecomposition.nodes.IssExprNode;
import vadl.javaannotations.viam.Input;
import vadl.types.DataType;
Expand Down Expand Up @@ -77,9 +77,9 @@ public <T extends GraphNodeVisitor> void accept(T visitor) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.add(value);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
consumer.accept(value);
}

@Override
Expand Down
15 changes: 8 additions & 7 deletions vadl/main/vadl/iss/passes/nodes/IssGvecOpNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package vadl.iss.passes.nodes;

import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import vadl.iss.passes.extensions.VectorTensorPlan;
import vadl.iss.passes.extensions.VectorTensorPlan.OperandForm;
Expand Down Expand Up @@ -231,16 +232,16 @@ public <T extends GraphNodeVisitor> void accept(T visitor) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.addAll(destinationAccessorIndices);
collection.addAll(lhsAccessorIndices);
collection.addAll(rhsAccessorIndices);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
destinationAccessorIndices.forEach(consumer);
lhsAccessorIndices.forEach(consumer);
rhsAccessorIndices.forEach(consumer);
if (this.scalarOperand != null) {
collection.add(scalarOperand);
consumer.accept(scalarOperand);
}
if (this.immediateOperand != null) {
collection.add(immediateOperand);
consumer.accept(immediateOperand);
}
}

Expand Down
12 changes: 6 additions & 6 deletions vadl/main/vadl/iss/passes/nodes/IssMoveNode.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText : © 2025 TU Wien <vadl@tuwien.ac.at>
// SPDX-FileCopyrightText : © 2025-2026 TU Wien <vadl@tuwien.ac.at>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
Expand All @@ -16,7 +16,7 @@

package vadl.iss.passes.nodes;

import java.util.List;
import java.util.function.Consumer;
import vadl.javaannotations.viam.Input;
import vadl.viam.graph.GraphNodeVisitor;
import vadl.viam.graph.GraphVisitor;
Expand Down Expand Up @@ -66,10 +66,10 @@ public <T extends GraphNodeVisitor> void accept(T visitor) {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.add(dest);
collection.add(expr);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
consumer.accept(dest);
consumer.accept(expr);
}

@Override
Expand Down
12 changes: 7 additions & 5 deletions vadl/main/vadl/iss/passes/nodes/IssReadRegNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.Streams;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import vadl.javaannotations.viam.DataValue;
import vadl.javaannotations.viam.Input;
Expand All @@ -28,6 +29,7 @@
import vadl.viam.Constant;
import vadl.viam.Counter;
import vadl.viam.RegisterTensor;
import vadl.viam.graph.Node;
import vadl.viam.graph.NodeList;
import vadl.viam.graph.dependency.ConstantNode;
import vadl.viam.graph.dependency.ExpressionNode;
Expand Down Expand Up @@ -290,11 +292,11 @@ public IssReadRegNode shallowCopy() {
}

@Override
protected void collectInputs(List<vadl.viam.graph.Node> collection) {
super.collectInputs(collection);
collection.addAll(accessorIndices);
collection.add(bitOffset);
collection.add(bitWidth);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
accessorIndices.forEach(consumer);
consumer.accept(bitOffset);
consumer.accept(bitWidth);
}

@Override
Expand Down
13 changes: 7 additions & 6 deletions vadl/main/vadl/iss/passes/nodes/IssRegBitfieldWriteNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package vadl.iss.passes.nodes;

import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import vadl.javaannotations.viam.DataValue;
import vadl.javaannotations.viam.Input;
Expand Down Expand Up @@ -118,12 +119,12 @@ public void verifyState() {
}

@Override
protected void collectInputs(List<Node> collection) {
super.collectInputs(collection);
collection.addAll(indices);
collection.add(value);
collection.add(bitOffset);
collection.add(bitWidth);
protected void forEachInput(Consumer<Node> consumer) {
super.forEachInput(consumer);
indices.forEach(consumer);
consumer.accept(value);
consumer.accept(bitOffset);
consumer.accept(bitWidth);
}

@Override
Expand Down
Loading
Loading