org.aya.concrete.resolve.context.BindContext Maven / Gradle / Ivy
// Copyright (c) 2020-2021 Yinsen (Tesla) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.context;
import kala.collection.immutable.ImmutableSeq;
import kala.collection.mutable.DynamicSeq;
import kala.collection.mutable.MutableMap;
import org.aya.api.error.Reporter;
import org.aya.api.ref.LocalVar;
import org.aya.api.ref.Var;
import org.aya.util.error.SourcePos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
import java.util.Objects;
/**
* Introduces a locally bound variable to the context.
*
* @author re-xyr
*/
public record BindContext(
@NotNull Context parent,
@NotNull String name,
@NotNull LocalVar ref
) implements Context {
@Override public @NotNull Context parent() {
return parent;
}
@Override public @NotNull Reporter reporter() {
return parent.reporter();
}
@Override public @NotNull Path underlyingFile() {
return parent.underlyingFile();
}
@Override public DynamicSeq collect(@NotNull DynamicSeq container) {
if (container.noneMatch(v -> Objects.equals(v.name(), ref.name()))) container.append(ref);
return parent.collect(container);
}
@Override public @Nullable Var getUnqualifiedLocalMaybe(@NotNull String name, @NotNull SourcePos sourcePos) {
if (name.equals(this.name)) return ref;
else return null;
}
@Override
public @Nullable Var getQualifiedLocalMaybe(@NotNull ImmutableSeq<@NotNull String> modName, @NotNull String name, @NotNull SourcePos sourcePos) {
return null;
}
@Override
public @Nullable MutableMap getModuleLocalMaybe(@NotNull ImmutableSeq modName) {
return null;
}
}