Package org.rascalmpl.ast

Examples of org.rascalmpl.ast.AbstractAST


    if (result !=  null) {
      return result;
    }
 
    Environment old = ctx.getCurrentEnvt();
    AbstractAST currentAST = ctx.getCurrentAST();
    AbstractAST oldAST = currentAST;
    Stack<Accumulator> oldAccus = ctx.getAccumulators();

    try {
      String label = isAnonymous() ? "Anonymous Function" : name;
      Environment environment = new Environment(declarationEnvironment, ctx.getCurrentEnvt(), currentAST != null ? currentAST.getLocation() : null, ast.getLocation(), label);
View Full Code Here


      if (hasJavaModifier(this)) {
        throw new NonAbstractJavaFunction(this);
      }

      ISourceLocation src = this.getLocation();
      AbstractAST ret = ASTBuilder.makeStat("Return", src, ASTBuilder.makeStat("Expression", src, getExpression()));
      AbstractAST fail = ASTBuilder.makeStat("Fail", src, ASTBuilder.make("Target", "Labeled", src, getSignature().getName()));
      AbstractAST ite = ASTBuilder.makeStat("IfThenElse", src, ASTBuilder.make("Label", "Empty", src), getConditions(), ret, fail);
      List<AbstractAST> sl = Arrays.<AbstractAST>asList(ite);
      AbstractAST body = ASTBuilder.make("FunctionBody", "Default", src, sl);
      FunctionDeclaration.Default func = ASTBuilder.make("FunctionDeclaration", "Default", src, getTags(), getVisibility(), getSignature(), body);
     
      lambda = new RascalFunction(__eval, func, varArgs, __eval
          .getCurrentEnvt(), __eval.__getAccumulators());
View Full Code Here

  }

  private IValue applyCases(IValue subject, CaseBlockList casesOrRules, TraverseResult tr) {
    for (CaseBlock cs : casesOrRules.getCases()) {
      Environment old = eval.getCurrentEnvt();
      AbstractAST prevAst = eval.getCurrentAST();
     
      try {
        eval.pushEnv();
       
        tr.matched = cs.matchAndEval(eval, makeResult(subject.getType(), subject, eval));
View Full Code Here

    }
    return result;
  }

  private AbstractAST buildContextFreeNode(IConstructor tree)  {
    AbstractAST cached = sortCache.get(tree);
   
    if (cached != null) {
      return cached;
    }
   
    String constructorName = TreeAdapter.getConstructorName(tree);
    if (constructorName == null) {
      throw new ImplementationError("All Rascal productions should have a constructor name: " + TreeAdapter.getProduction(tree));
    }
   
    String cons = capitalize(constructorName);
    String sort = sortName(tree);
   
    if (sort.length() == 0) {
      throw new ImplementationError("Could not retrieve sort name for " + tree);
    }
    sort = sort.equalsIgnoreCase("pattern") ? "Expression" : capitalize(sort);
   
    switch(sort){
    case "Mapping":
      sort = "Mapping_Expression"; break;
    case "KeywordArgument":
      sort = "KeywordArgument_Expression"; break;
    case "KeywordArguments":
      sort = "KeywordArguments_Expression"; break;
    }

    IList args = getASTArgs(tree);
    int arity = args.length();
    Object actuals[] = new Object[arity+1];
    actuals[0] = tree;

    int i = 1;
    for (IValue arg : args) {
      IConstructor argTree = (IConstructor) arg;

      if (TreeAdapter.isList(argTree)) {
        actuals[i] = buildList((IConstructor) arg);
      }
      else {
        actuals[i] = buildValue(arg);
      }
      i++;
    }

    AbstractAST ast = callMakerMethod(sort, cons, tree.asAnnotatable().getAnnotations(), actuals, null);
   
    sortCache.putUnsafe(tree, ast);
    return ast;
  }
View Full Code Here

    sortCache.putUnsafe(tree, ast);
    return ast;
  }
 
  private AbstractAST buildLexicalNode(IConstructor tree) {
    AbstractAST cached = lexCache.get(tree);
    if (cached != null) {
      return cached;
    }
    String sort = capitalize(sortName(tree));

    if (sort.length() == 0) {
      throw new ImplementationError("could not retrieve sort name for " + tree);
    }
    Object actuals[] = new Object[] { tree, new String(TreeAdapter.yield(tree)) };

    AbstractAST result = callMakerMethod(sort, "Lexical", tree.asAnnotatable().getAnnotations(), actuals, null);
    lexCache.putUnsafe(tree, result);
    return result;
  }
View Full Code Here

    }
    return false;
  }

  private AbstractAST newLift(IConstructor tree, boolean match) {
      AbstractAST cached = constructorCache.get(tree);
      if (cached != null) {
        return cached;
      }
     
      IConstructor concrete = (IConstructor) TreeAdapter.getArgs(tree).get(0);
View Full Code Here

        constructor = clazz.getConstructors()[0];
        constructor.setAccessible(true);
        astConstructors.put(name, constructor);
      }

      AbstractAST result = (AbstractAST) constructor.newInstance(actuals);
      if (src != null) {
        result.setSourceLocation(src);
      }
      if (annotations != null && !annotations.isEmpty()) {
        result.setAnnotations(annotations);
      }
      return result;
    } catch (SecurityException e) {
      throw unexpectedError(e);
    } catch (IllegalArgumentException e) {
View Full Code Here

TOP

Related Classes of org.rascalmpl.ast.AbstractAST

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.