Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott-Guest committed Feb 23, 2024
1 parent 5af0a82 commit 2b75913
Show file tree
Hide file tree
Showing 3 changed files with 913 additions and 0 deletions.
45 changes: 45 additions & 0 deletions kore/src/main/java/org/kframework/attributes/Attribute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Runtime Verification, Inc. All Rights Reserved.
package org.kframework.attributes;

import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.EnumSet;

public abstract class Attribute {

public enum Syntax {
CELL,
CLAIM,
CONTEXT,
CONTEXT_ALIAS,
MODULE,
PRODUCTION,
RULE,
SENTENCE,
SYNTAX_SORT,
UNCHECKED
}

public sealed interface Visibility {
record User(EnumSet<Syntax> allowedSyntax) implements Visibility {
User(Syntax... allowed) {
this(Sets.newEnumSet(Arrays.asList(allowed), Syntax.class));
}
}

record Internal() implements Visibility {}
}

public enum EmitToKORE {
YES,
NO
}

public final Visibility visibility;
public final EmitToKORE emit;

protected Attribute(Visibility visibility, EmitToKORE emit) {
this.visibility = visibility;
this.emit = emit;
}
}
34 changes: 34 additions & 0 deletions kore/src/main/java/org/kframework/attributes/ClassSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Runtime Verification, Inc. All Rights Reserved.
package org.kframework.attributes;

import java.util.Objects;
import java.util.Optional;
import org.pcollections.HashPMap;

public class ClassSet<U> {

public final HashPMap<Class<? extends U>, Object> data;

private ClassSet(HashPMap<Class<? extends U>, Object> data) {
this.data = data;
}

public <T extends U> ClassSet<U> add(Class<T> elemClass, T elem) {
return new ClassSet<>(data.plus(elemClass, elem));
}

public <T extends U> Optional<T> get(Class<T> elemClass) {
if (!data.containsKey(elemClass)) {
return Optional.empty();
}
return Optional.of(Objects.requireNonNull(elemClass.cast(data.get(elemClass))));
}

public <T extends U> boolean contains(Class<T> elemClass) {
return data.containsKey(elemClass);
}

public <T extends U> ClassSet<U> remove(Class<T> elemClass) {
return new ClassSet<>(data.minus(elemClass));
}
}
Loading

0 comments on commit 2b75913

Please sign in to comment.