Skip to content

Commit

Permalink
Add "meta" referable kind
Browse files Browse the repository at this point in the history
Fixes #349
  • Loading branch information
valis committed Nov 20, 2024
1 parent b499994 commit 900528c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ private static GlobalReferable.Kind getDefinitionKind(DefinitionProtos.Definitio
case CONSTRUCTOR -> {
return GlobalReferable.Kind.DEFINED_CONSTRUCTOR;
}
case META -> {
return GlobalReferable.Kind.META;
}
default -> {
return GlobalReferable.Kind.OTHER;
}
Expand All @@ -269,7 +272,9 @@ private StaticGroup readGroup(ModuleProtos.Group groupProto, ChildGroup parent,
referable = new FullModuleReferable(modulePath);
} else {
String name = referableProto.getName();
if (myPrelude && kind == GlobalReferable.Kind.FUNCTION && Prelude.ARRAY_NAME.equals(name)) {
if (kind == GlobalReferable.Kind.META) {
referable = new MetaReferable(AccessModifier.PUBLIC, readPrecedence(referableProto.getPrecedence()), name, "", null, null, parent.getReferable());
} else if (myPrelude && kind == GlobalReferable.Kind.FUNCTION && Prelude.ARRAY_NAME.equals(name)) {
referable = new TypedLocatedReferable(AccessModifier.PUBLIC, readPrecedence(referableProto.getPrecedence()), name, parent.getReferable(), kind, null, null);
} else {
referable = new LocatedReferableImpl(AccessModifier.PUBLIC, readPrecedence(referableProto.getPrecedence()), name, parent.getReferable(), kind);
Expand All @@ -290,9 +295,7 @@ private StaticGroup readGroup(ModuleProtos.Group groupProto, ChildGroup parent,
List<Statement> statements = new ArrayList<>(groupProto.getSubgroupCount());

StaticGroup group;
if (def == null || def instanceof FunctionDefinition) {
group = new StaticGroup(referable, statements, Collections.emptyList(), parent);
} else if (def instanceof DataDefinition) {
if (def instanceof DataDefinition) {
Set<Definition> invisibleRefs = new HashSet<>();
for (Integer index : groupProto.getInvisibleInternalReferableList()) {
invisibleRefs.add(myCallTargetProvider.getCallTarget(index));
Expand Down Expand Up @@ -326,7 +329,7 @@ private StaticGroup readGroup(ModuleProtos.Group groupProto, ChildGroup parent,
dynamicReferables.add(subgroup.getReferable());
}
} else {
throw new IllegalStateException();
group = new StaticGroup(referable, statements, Collections.emptyList(), parent);
}

for (ModuleProtos.Group subgroup : groupProto.getSubgroupList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private ModuleProtos.Group writeGroup(Group group, ReferableConverter referableC
refBuilder.setIndex(index);
myCurrentDefinitions.add(index);
}
if (tcReferable != null && (typechecked == null || !typechecked.status().noErrors()) && tcReferable.getKind() != GlobalReferable.Kind.OTHER) {
if (tcReferable != null && (typechecked == null || !typechecked.status().noErrors()) && tcReferable.getKind().isTypecheckable()) {
myComplete = false;
}
builder.setReferable(refBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum Kind {
},
FIELD { @Override public boolean isTypecheckable() { return false; } },
LEVEL { @Override public boolean isTypecheckable() { return false; } },
META { @Override public boolean isTypecheckable() { return false; } },
OTHER { @Override public boolean isTypecheckable() { return false; } };

public boolean isTypecheckable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Precedence getPrecedence() {
@NotNull
@Override
public Kind getKind() {
return Kind.OTHER;
return Kind.META;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void print(@NotNull CommonCliRepl api, Node node, String prefix,
if (scope != null) {
for (Referable referable : scope.getElements()) {
if (referable instanceof TCDefReferable referable1) {
if (referable1.getTypechecked() == null && referable1.getKind() != GlobalReferable.Kind.OTHER)
if (referable1.getTypechecked() == null && referable1.getKind().isTypecheckable())
failedDefs.add(referable);
else successful++;
}
Expand Down

0 comments on commit 900528c

Please sign in to comment.