001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.golo.compiler.ir;
011
012public class ReferenceLookup extends ExpressionStatement {
013
014  private final String name;
015
016  ReferenceLookup(String name) {
017    super();
018    this.name = name;
019  }
020
021  public String getName() {
022    return name;
023  }
024
025  public LocalReference resolveIn(ReferenceTable referenceTable) {
026    return referenceTable.get(name);
027  }
028
029  public LocalReference varRef() {
030    return Builders.localRef(name).variable();
031  }
032
033  public LocalReference letRef() {
034    return Builders.localRef(name);
035  }
036
037  @Override
038  public String toString() {
039    return String.format("Ref{name=%s}", getName());
040  }
041
042  @Override
043  public void accept(GoloIrVisitor visitor) {
044    visitor.visitReferenceLookup(this);
045  }
046
047  @Override
048  public void walk(GoloIrVisitor visitor) {
049    // nothing to do, not a composite
050  }
051
052  @Override
053  protected void replaceElement(GoloElement original, GoloElement newElement) {
054    throw cantReplace();
055  }
056
057}