All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aya.syntax.ref.LocalVar Maven / Gradle / Ivy

There is a newer version: 0.34.0
Show newest version
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.syntax.ref;

import org.aya.util.error.SourceNode;
import org.aya.util.error.SourcePos;
import org.aya.util.error.WithPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public record LocalVar(
  @NotNull String name,
  @NotNull SourcePos definition,
  @NotNull GenerateKind generateKind
) implements AnyVar, SourceNode {
  public LocalVar(@NotNull String name) {
    this(name, SourcePos.NONE);
  }

  public LocalVar(@NotNull String name, @NotNull SourcePos definition) {
    this(name, definition, GenerateKind.Basic.None);
  }

  public static @NotNull LocalVar generate(@NotNull String name, @NotNull SourcePos sourcePos) {
    return new LocalVar(name, sourcePos, GenerateKind.Basic.Tyck);
  }

  public static @NotNull LocalVar generate(@NotNull String name) {
    return generate(name, SourcePos.NONE);
  }

  public static @NotNull LocalVar from(@NotNull WithPos id) {
    if (id.data() == null) return new LocalVar("_", id.sourcePos());
    return new LocalVar(id.data(), id.sourcePos());
  }

  public static final @NotNull LocalVar IGNORED = new LocalVar("_", SourcePos.NONE);
  @Override public @NotNull SourcePos sourcePos() { return definition; }
  @Override public boolean equals(@Nullable Object o) { return this == o; }
  @Override public int hashCode() { return System.identityHashCode(this); }

  public boolean isGenerated() {
    return generateKind != GenerateKind.Basic.None;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy