Package org.rascalmpl.interpreter.asserts

Examples of org.rascalmpl.interpreter.asserts.ImplementationError


  public static ISet getAlternatives(IConstructor tree) {
    if (isAmb(tree)) {
      return (ISet) tree.get("alternatives");
    }
   
    throw new ImplementationError("Node has no alternatives");
  }
View Full Code Here


  public static void unparse(IConstructor tree, Writer stream)
      throws IOException, FactTypeUseException {
    if (tree.getType().isSubtypeOf(Factory.Tree)) { // == Factory.Tree) {
      tree.accept(new Unparser(stream));
    } else {
      throw new ImplementationError("Can not unparse this " + tree + " (type = "
          + tree.getType() + ")") ;
    }
  }
View Full Code Here

    }
    catch (IOLimitReachedException e) {
      return stream.toString();     
    }
    catch (IOException e) {
      throw new ImplementationError("Method yield failed", e);
    }
  }
View Full Code Here

    try {
      Writer stream = new CharArrayWriter();
      unparse(tree, stream);
      return stream.toString();
    } catch (IOException e) {
      throw new ImplementationError("Method yield failed", e);
    }
  }
View Full Code Here

        return new TypedMultiVariablePattern(eval, this, type, arg.getName());
      }
      if(arg.hasQualifiedName()){
        return new MultiVariablePattern(eval, this, arg.getQualifiedName());
      }
      throw new ImplementationError(null);
    }
View Full Code Here

        return arg.getType().typeOf(env, instantiateTypeParameters, eval);
      }
      if(arg.hasQualifiedName()){
        return arg.getQualifiedName().typeOf(env, instantiateTypeParameters, eval);
      }
      throw new ImplementationError(null);
    }
View Full Code Here

  public void convertToListType() {
    if (!this.alreadyStored) {
      this.declaredType = TypeFactory.getInstance().listType(/*this.declaredType.isListType() ? this.declaredType.getElementType() : */this.declaredType);
    } else {
      if(!declaredType.isList())
        throw new ImplementationError("Cannot convert a typed multi variable to a list after it has already been stored at its current type");
    }
  }
View Full Code Here

  public void covertToSetType() {
    if (!this.alreadyStored) {
      this.declaredType = TypeFactory.getInstance().setType(/*this.declaredType.isSetType() ? this.declaredType.getElementType() : */this.declaredType);
    } else {
      if(!declaredType.isSet())
        throw new ImplementationError("Cannot convert a typed multi variable to a set after it has already been stored at its current type");
    }
  }
View Full Code Here

    return null;
  }
 
  public static IList getASTSymbols(IConstructor tree) {
    if (isLexical(tree)) {
      throw new ImplementationError("This is not a context-free production: " + tree);
    }

    IList children = getSymbols(tree);
    IListWriter writer = ValueFactoryFactory.getValueFactory().listWriter(Factory.Args.getElementType());
View Full Code Here

 
  @Override
  public IConstructor visitExpressionCallOrTree(CallOrTree x) {
    Expression namePart = x.getExpression();
    if (!namePart.isQualifiedName()) {
      throw new ImplementationError("weird AST");
    }
    String name = ((org.rascalmpl.semantics.dynamic.QualifiedName.Default) namePart.getQualifiedName()).lastName();
   
    if (name.equals("lit")) {
      StringConstant.Lexical arg =
        (org.rascalmpl.ast.StringConstant.Lexical) x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
      // TODO: escaping etc.
      String str = arg.getString();
      str = str.substring(1, str.length() - 1);
      return vf.constructor(Factory.Symbol_Lit, vf.string(str));
    }
   
    if (name.equals("cilit")) {
      StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical) x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
      // TODO: escaping etc.
      String str = arg.getString();
      str = str.substring(1, str.length() - 1);
      return vf.constructor(Factory.Symbol_CiLit, vf.string(str));
    }
   
    if (name.equals("empty")) {
      return vf.constructor(Factory.Symbol_Empty)
    }
   
    if (name.equals("seq")) {
      IList list = vf.list(Factory.Symbol);
      Expression.List arg = (List) x.getArguments().get(0);
      for (Expression y: arg.getElements()) {
        list = list.append(y.accept(this));
      }
      return vf.constructor(Factory.Symbol_Seq, list);
     
    }
   
    if (name.equals("opt")) {
      IConstructor arg = x.getArguments().get(0).accept(this);
      return vf.constructor(Factory.Symbol_Opt, arg);
    }
   
    if (name.equals("alt")) {
      ISet set = vf.set(Factory.Symbol);
      Expression.Set arg = (Set) x.getArguments().get(0);
      for(Expression y: arg.getElements()){
        set = set.insert(y.accept(this));
      }
      return vf.constructor(Factory.Symbol_Alt, set);
    }
   
    if (name.equals("tuple")) {
      java.util.List<Expression> args = x.getArguments();
      IConstructor head = args.get(0).accept(this);
      IList rest = vf.list(Factory.Symbol);
      for (Expression arg: ((Expression.List)args.get(1)).getElements()) {
        rest = rest.append(arg.accept(this));
      }
      return vf.constructor(Factory.Symbol_Tuple, head, rest);
    }
   
    if (name.equals("sort")) {
      StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical)
        x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
      String str = arg.getString();
      str = str.substring(1, str.length() - 1);
      return vf.constructor(Factory.Symbol_Sort, vf.string(str));
    }
   
    if (name.equals("layouts")) {
      StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical)
        x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
      String str = arg.getString();
      str = str.substring(1, str.length() - 1);
      return vf.constructor(Factory.Symbol_LayoutX, vf.string(str));
    }
   

    if (name.equals("iter")) {
      IConstructor arg = x.getArguments().get(0).accept(this);
      return vf.constructor(Factory.Symbol_IterPlus, arg);
    }
   
    if (name.equals("iter-star")) {
      IConstructor arg = x.getArguments().get(0).accept(this);
      return vf.constructor(Factory.Symbol_IterStar, arg);
    }
   
    if (name.equals("iter-star-seps")) {
      IConstructor arg = x.getArguments().get(0).accept(this);
      Expression.List args = (Expression.List) x.getArguments().get(1);
      IList seps = vf.list(Factory.Args);
      for (Expression elem: args.getElements()) {
        seps = seps.append(elem.accept(this));
      }
      return vf.constructor(Factory.Symbol_IterStarSepX, arg, seps);
    }
   
    if (name.equals("iter-seps")) {
      IConstructor arg = x.getArguments().get(0).accept(this);
      Expression.List args = (Expression.List) x.getArguments().get(1);
      IList seps = vf.list(Factory.Args);
      for (Expression elem: args.getElements()) {
        seps = seps.append(elem.accept(this));
      }
      return vf.constructor(Factory.Symbol_IterSepX, arg, seps);
    }

    if (name.equals("parameterized-sort")) {
      java.util.List<Expression> args = x.getArguments();
      StringConstant.Lexical sort = (org.rascalmpl.ast.StringConstant.Lexical)
        x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
      IList rest = vf.list(Factory.Symbol);
      for (Expression arg: ((Expression.List)args.get(1)).getElements()) {
        rest = rest.append(arg.accept(this));
      }
      return vf.constructor(Factory.Symbol_ParameterizedSort, vf.string(sort.getString()), rest);
     
    }
   
    if (name.equals("lit")) {
      StringConstant.Lexical arg = (org.rascalmpl.ast.StringConstant.Lexical)
        x.getArguments().get(0).getLiteral().getStringLiteral().getConstant();
      // TODO: escaping etc.
      return vf.constructor(Factory.Symbol_Lit, vf.string(arg.getString()));
    }
   
    if (name.equals("char-class")) {
      java.util.List<Expression> args = x.getArguments();
      IList ranges = vf.list(Factory.CharRange);
      for (Expression arg: ((Expression.List)args.get(0)).getElements()) {
        ranges = ranges.append(arg.accept(this));
      }
      return vf.constructor(Factory.Symbol_CharClass, ranges);
    }
   
    if (name.equals("single")) {
      org.rascalmpl.ast.DecimalIntegerLiteral.Lexical arg1 = (org.rascalmpl.ast.DecimalIntegerLiteral.Lexical) x.getArguments().get(0).getLiteral().getIntegerLiteral().getDecimal();
      IInteger num = vf.integer(java.lang.Integer.parseInt(arg1.getString()));
      return vf.constructor(Factory.CharRange_Single, num);
    }
   
    if (name.equals("range")) {
      org.rascalmpl.ast.DecimalIntegerLiteral.Lexical arg1 = (org.rascalmpl.ast.DecimalIntegerLiteral.Lexical) x.getArguments().get(0).getLiteral().getIntegerLiteral().getDecimal();
      IInteger num1 = vf.integer(java.lang.Integer.parseInt(arg1.getString()));
      org.rascalmpl.ast.DecimalIntegerLiteral.Lexical arg2 = (org.rascalmpl.ast.DecimalIntegerLiteral.Lexical) x.getArguments().get(1).getLiteral().getIntegerLiteral().getDecimal();
      IInteger num2 = vf.integer(java.lang.Integer.parseInt(arg2.getString()));
      return vf.constructor(Factory.CharRange_Range, num1, num2);
    }

    throw new ImplementationError("Non-IUPTR AST expression: " + name + ", " + x);
  }
View Full Code Here

TOP

Related Classes of org.rascalmpl.interpreter.asserts.ImplementationError

Copyright © 2018 www.massapicom. 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.