Skip to content

Commit

Permalink
Add JDoc comments to new classes
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Jul 22, 2024
1 parent 40ae8ce commit ed44599
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Represent the BDD atom.
*
* @since 2201.10.0
*/
public interface Atom {

int index();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Marker type representing AtomicType.
*
* @since 2201.10.0
*/
public interface AtomicType {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@

import static io.ballerina.runtime.api.types.semtype.Conjunction.and;

/**
* Represent BDD node. Subtypes that uses BDDs to represent subtypes such as list, mapping and cell should implement
* their own {@code SubType} implementation that wraps an implementation of this class.
*
* @since 2201.10.0
*/
public abstract sealed class Bdd extends SubType permits BddAllOrNothing, BddNode {

protected Bdd(boolean all, boolean nothing) {
Bdd(boolean all, boolean nothing) {
super(all, nothing);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Represent the leaf node of a Bdd.
*
* @since 2201.10.0
*/
public final class BddAllOrNothing extends Bdd {

public static BddAllOrNothing ALL = new BddAllOrNothing(true);
public static BddAllOrNothing NOTHING = new BddAllOrNothing(false);
public static final BddAllOrNothing ALL = new BddAllOrNothing(true);
public static final BddAllOrNothing NOTHING = new BddAllOrNothing(false);

private BddAllOrNothing(boolean all) {
super(all, !all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Internal node of a BDD, which represents a disjunction of conjunctions of atoms.
*
* @since 2201.10.0
*/
public final class BddNode extends Bdd {

private final Atom atom;
private final Bdd left;
private final Bdd middle;
private final Bdd right;

public BddNode(Atom atom, Bdd left, Bdd middle, Bdd right) {
BddNode(Atom atom, Bdd left, Bdd middle, Bdd right) {
super(false, false);
this.atom = atom;
this.left = left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Represents a predicate that can be applied to a BDD conjunction.
*
* @since 2201.10.0
*/
@FunctionalInterface
public interface BddPredicate {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,26 @@

package io.ballerina.runtime.api.types.semtype;

import static io.ballerina.runtime.api.types.semtype.TypeAtom.createTypeAtom;

/**
* CellAtomicType node.
*
* @param ty Type "wrapped" by this cell
* @param mut Mutability of the cell
* @since 2201.10.0
*/
public record CellAtomicType(SemType ty, CellMutability mut) implements AtomicType {

private static final AtomicType CELL_ATOMIC_VAL = new CellAtomicType(
Builder.val(), CellAtomicType.CellMutability.CELL_MUT_LIMITED
);
public static final TypeAtom ATOM_CELL_VAL = createTypeAtom(0, CELL_ATOMIC_VAL);

public static final CellAtomicType CELL_ATOMIC_NEVER = new CellAtomicType(
Builder.neverType(), CellAtomicType.CellMutability.CELL_MUT_LIMITED
);

public enum CellMutability {
CELL_MUT_NONE,
CELL_MUT_LIMITED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Represents the Conjunction in the BDD.
*
* @param atom Atom of this node
* @param next Next node in the conjunction, will be {@code null} if this is the last node
* @since 2201.10.0
*/
public record Conjunction(Atom atom, Conjunction next) {

public static Conjunction and(Atom atom, Conjunction next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
* Represent the environment in which {@code SemTypes} are defined in. Type checking types defined in different
* environments with each other in undefined.
*
* @since 2201.10.0
*/
public final class Env {

private final static Env INSTANCE = new Env();
private static final Env INSTANCE = new Env();

private final Map<AtomicType, TypeAtom> atomTable;
private final ReadWriteLock atomTableLock = new ReentrantReadWriteLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

package io.ballerina.runtime.api.types.semtype;

/**
* Represent a recursive type atom.
*
* @since 2201.10.0
*/
public class RecAtom implements Atom {

Check warning on line 27 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/semtype/RecAtom.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/semtype/RecAtom.java#L27

Added line #L27 was not covered by tests

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
// TODO: would making this a child class of say BddNode be faster than making this a delegate
// -- Problem with this is modeling type operations (union, intersect, complement) since parent must return a Cell
// as well

/**
* Runtime representation of CellSubType.
*
* @since 2201.10.0
*/
public class BCellSubType extends SubType {

private final Bdd inner;
Expand All @@ -47,16 +53,13 @@ private BCellSubType(Bdd inner) {
public static BCellSubType createDelegate(SubType inner) {
if (inner instanceof Bdd bdd) {
return new BCellSubType(bdd);
} else if (inner.isAll() || inner.isNothing()) {
// FIXME: if all or nothing do the same thing as cellSubtypeDataEnsureProper
throw new IllegalStateException("unimplemented");
} else if (inner instanceof BCellSubType bCell) {
return new BCellSubType(bCell.inner);

Check warning on line 57 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/semtype/BCellSubType.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/semtype/BCellSubType.java#L57

Added line #L57 was not covered by tests
}
throw new IllegalArgumentException("Unexpected inner type");

Check warning on line 59 in bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/semtype/BCellSubType.java

View check run for this annotation

Codecov / codecov/patch

bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/semtype/BCellSubType.java#L59

Added line #L59 was not covered by tests
}

public static CellAtomicType cellAtomType(Atom atom) {
private static CellAtomicType cellAtomType(Atom atom) {
return (CellAtomicType) ((TypeAtom) atom).atomicType();
}

Expand Down

0 comments on commit ed44599

Please sign in to comment.