Package hampi.parser

Source Code of hampi.parser.HContainsExpression

package hampi.parser;

import hampi.HampiException;
import hampi.parser.HProgram.HTypeEnvironment;
import hampi.utils.Utils;

public final class HContainsExpression extends HBooleanExpression{

  private final String  id;
  private final String  str;
  private final boolean contains;

  public HContainsExpression(String id, String str, boolean contains){
    super(HGrammarElementKind.BEXPR_CONTAINS);
    this.id = id;
    this.str = Utils.stripQuotes(str);
    this.contains = contains;
  }

  /**
   * Returns the v from: v contains "foo"
   */
  public String getVariableName(){
    return id;
  }

  /**
   * Returns the "foo" from: v contains "foo"
   */
  public String getString(){
    return str;
  }

  @Override
  public String unparse(){
    return id + (contains ? "" : " not") + " contains " + Utils.quotes(str);
  }

  @Override
  public void typeCheck(HTypeEnvironment tenv, HVarDeclStatement varDecl){
    if (tenv.getType(id) == null)
      throw new HampiException("undefined variable " + id + " in 'contains'");
  }

  @Override
  public void accept(HGrammarVisitor v){
    v.visitContainsExpression(this);
  }

  public boolean contains(){
    return contains;
  }
}
TOP

Related Classes of hampi.parser.HContainsExpression

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.