Package org.eclipse.imp.pdb.facts

Examples of org.eclipse.imp.pdb.facts.ISourceLocation


  }
 
  @Override
  public void run(){
    while(running){
      ISourceLocation stat = eval.getCurrentAST().getLocation();
      if(stat != null){
        Count currentCount = data.get(stat);
        if(currentCount == null)
          data.put(stat, new Count());
        else
View Full Code Here


      return arg;
    }
  }

  public static IConstructor locateLexical(IConstructor tree, int offset) {
    ISourceLocation l = TreeAdapter.getLocation(tree);

    if (l == null) {
      throw new IllegalArgumentException(
          "locate assumes position information on the tree");
    }

    if (TreeAdapter.isLexical(tree)) {
      if (l.getOffset() <= offset
          && offset < l.getOffset() + l.getLength()) {
        return tree;
      }

      return null;
    }

    if (TreeAdapter.isAmb(tree)) {
      return null;
    }

    if (TreeAdapter.isAppl(tree)) {
      IList children = TreeAdapter.getASTArgs(tree);

      for (IValue child : children) {
        ISourceLocation childLoc = TreeAdapter
            .getLocation((IConstructor) child);

        if (childLoc == null) {
          continue;
        }

        if (childLoc.getOffset() <= offset
            && offset < childLoc.getOffset() + childLoc.getLength()) {
          IConstructor result = locateLexical((IConstructor) child,
              offset);

          if (result != null) {
            return result;
View Full Code Here

  /**
   * This finds the most specific (smallest) annotated tree which has its yield around the given offset.
   */
  public static IConstructor locateAnnotatedTree(IConstructor tree, String label, int offset) {
    ISourceLocation l = TreeAdapter.getLocation(tree);

    if (l == null) {
      throw new IllegalArgumentException(
          "locate assumes position information on the tree");
    }

    if (TreeAdapter.isAmb(tree)) {
      if (tree.asAnnotatable().hasAnnotation(label)) {
        return tree;
      }
     
      return null;
    }

    if (TreeAdapter.isAppl(tree) && !TreeAdapter.isLexical(tree)) {
      IList children = TreeAdapter.getArgs(tree); //TreeAdapter.getASTArgs(tree);

      for (IValue child : children) {
        ISourceLocation childLoc = TreeAdapter
            .getLocation((IConstructor) child);

        if (childLoc == null) {
          continue;
        }

        if (childLoc.getOffset() <= offset
            && offset < childLoc.getOffset() + childLoc.getLength()) {
          IConstructor result = locateAnnotatedTree((IConstructor) child, label, offset);

          if (result != null) {
            return result;
          }
View Full Code Here

   
      setSuspendRequested(false);
     
    } else {

      ISourceLocation location = currentAST.getLocation();
      switch (getStepMode()) {
     
      case STEP_INTO:
        updateSuspensionState(evaluator, currentAST);
        getEventTrigger().fireSuspendByStepEndEvent();
        break;
       
      case STEP_OVER:
        // TODO: remove cast to {@link Evaluator} and rework {@link IEvaluator}.
        // TODO: optimize {@link Evaluator.getCallStack()}; currently it is expensive because of environment traversal
        Integer currentEnvironmentStackSize = ((Evaluator) evaluator).getCallStack().size();

        /*
         * Stepping over implies:
         * * either there is a next statement in the same environment stack frame (which might
         *   equal the reference statement in case of recursion or single statement loops)
         * * or there is no next statement in the same stack frame and thus the stack frame
         *   eventually gets popped from the stack. As long the calls in deeper nesting levels
         *   are executed, no action needs to be taken.
         */
        switch (currentEnvironmentStackSize.compareTo(getReferenceEnvironmentStackSize())) {
        case 0:
          /*
           * For the case that we are still within the same stack
           * frame, positions are compared to ensure that the
           * statement was finished executing.
           */
          int referenceStart = getReferenceAST().getLocation().getOffset();
          int referenceAfter = getReferenceAST().getLocation().getOffset() + getReferenceAST().getLocation().getLength();
          int currentStart = location.getOffset();
          int currentAfter = location.getOffset() + location.getLength();

          if (currentStart < referenceStart
              || currentStart >= referenceAfter
              || currentStart == referenceStart
              && currentAfter == referenceAfter) {
View Full Code Here

  @Override
  public void processMessage(IDebugMessage message) {
    switch (message.getSubject()) {

    case BREAKPOINT:
      ISourceLocation breakpointLocation = (ISourceLocation) message.getPayload();

      switch (message.getAction()) {
      case SET:
        addBreakpoint(breakpointLocation);
        break;
View Full Code Here

    private Statement makeMidAppend(ISourceLocation tree, String str) {
      return new MidAppend(tree, ASTBuilder.<DataTarget>make("DataTarget","Labeled", tree, label), str);
    }

    private Statement makeIndentingAppend(Expression exp) {
      ISourceLocation loc = exp.getLocation();
      return new IndentingAppend(exp.getLocation(), ASTBuilder.<DataTarget>make("DataTarget","Labeled", loc, label),
          ASTBuilder.<Statement>make("Statement","Expression", loc, exp));
    }
View Full Code Here

        }
      }
      return pt;
    }
    catch (ParseError pe) {
      ISourceLocation errorLoc = values.sourceLocation(pe.getLocation(), pe.getOffset(), pe.getLength(), pe.getBeginLine() + 1, pe.getEndLine() + 1, pe.getBeginColumn(), pe.getEndColumn());
      throw RuntimeExceptionFactory.parseError(errorLoc, ctx.getCurrentAST(), ctx.getStackTrace());
    }
    catch (UndeclaredNonTerminalException e){
      throw new UndeclaredNonTerminal(e.getName(), e.getClassName(), ctx.getCurrentAST());
    }
View Full Code Here

      }

      return pt;
    }
    catch (ParseError pe) {
      ISourceLocation errorLoc = values.sourceLocation(pe.getLocation(), pe.getOffset(), pe.getLength(), pe.getBeginLine() + 1, pe.getEndLine() + 1, pe.getBeginColumn(), pe.getEndColumn());
      throw RuntimeExceptionFactory.parseError(errorLoc, null, null);
    }
    catch (UndeclaredNonTerminalException e){
      throw new UndeclaredNonTerminal(e.getName(), e.getClassName(), ctx.getCurrentAST());
    }
View Full Code Here

      }

      return pt;
    }
    catch (ParseError pe) {
      ISourceLocation errorLoc = values.sourceLocation(pe.getLocation(), pe.getOffset(), pe.getLength(), pe.getBeginLine(), pe.getEndLine(), pe.getBeginColumn(), pe.getEndColumn());
      throw RuntimeExceptionFactory.parseError(errorLoc, null, null);
    }
    catch (UndeclaredNonTerminalException e){
      throw new UndeclaredNonTerminal(e.getName(), e.getClassName(), ctx.getCurrentAST());
    }
View Full Code Here

        Iterator<Type> iter = conses.iterator();
        while (iter.hasNext()) {
          try {
            @SuppressWarnings("unused")
            Type cons = iter.next();
            ISourceLocation loc = TreeAdapter.getLocation(tree);
            IConstructor ast = makeConstructor(type, constructorName, ctx, values.string(yield));
            return ast.asAnnotatable().setAnnotation("location", loc);
          }
          catch (Backtrack b) {
            continue;
          }
        }
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Cannot find a constructor " + type));
      }
      if (type.isInteger()) {
        return values.integer(yield);
      }
      if (type.isReal()) {
        return values.real(yield);
      }
      if (type.isBool()) {
        if (yield.equals("true")) {
          return values.bool(true);
        }
        if (yield.equals("false")) {
          return values.bool(false);
        }
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Bool type does not match with " + yield));
      }
      if (type.isString() || isUntypedNodeType(type)) {
        // NB: in "node space" all lexicals become strings
        return values.string(yield);
      }
     
      throw RuntimeExceptionFactory.illegalArgument(tree, null, null, "Missing lexical constructor");
    }
   
    //Set implementation added here by Jurgen at 19/07/12 16:45
    if (TreeAdapter.isList(tree)) {
      if (type.isList() || splicing || isUntypedNodeType(type)) {
        // if in node space, we also make a list;
        // NB: this breaks type safety if the top-level tree
        // is itself a list.
       
        Type elementType = type;
        if (!splicing && !isUntypedNodeType(type)) {
          elementType = type.getElementType();
        }
        IListWriter w = values.listWriter();
        for (IValue arg: TreeAdapter.getListASTArgs(tree)) {
          w.append(implode(store, elementType, (IConstructor) arg, false, ctx));
        }
        return w.done();
      }
      else if (type.isSet()) {
        Type elementType = splicing ? type : type.getElementType();
        ISetWriter w = values.setWriter();
        for (IValue arg: TreeAdapter.getListASTArgs(tree)) {
          w.insert(implode(store, elementType, (IConstructor) arg, false, ctx));
        }
        return w.done();
      }
      else {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Cannot match list with " + type));
      }
    }
    //Changes end here
   
    if (TreeAdapter.isOpt(tree) && type.isBool()) {
      IList args = TreeAdapter.getArgs(tree);
      if (args.isEmpty()) {
        return values.bool(false);
      }
      return values.bool(true);
    }
   
    if (TreeAdapter.isOpt(tree)) {
      if (!type.isList() && !isUntypedNodeType(type)) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Optional should match with a list and not " + type));
      }
      Type elementType = isUntypedNodeType(type) ? type : type.getElementType();
      IListWriter w = values.listWriter();
      for (IValue arg: TreeAdapter.getASTArgs(tree)) {
        IValue implodedArg = implode(store, elementType, (IConstructor) arg, true, ctx);
        if (implodedArg instanceof IList) {
          // splicing
          for (IValue nextArg: (IList)implodedArg) {
            w.append(nextArg);
          }
        }
        else {
          w.append(implodedArg);
        }
        // opts should have one argument (if any at all)
        break;
      }
      return w.done();
    }
   
    if (TreeAdapter.isAmb(tree)) {
      if (!type.isSet()) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Ambiguous node should match with set and not " + type));
      }
      Type elementType = type.getElementType();
      ISetWriter w = values.setWriter();
      for (IValue arg: TreeAdapter.getAlternatives(tree)) {
        w.insert(implode(store, elementType, (IConstructor) arg, false, ctx));
      }
      return w.done();
    }
   
    if (ProductionAdapter.hasAttribute(TreeAdapter.getProduction(tree), Factory.Attribute_Bracket)) {
      return implode(store, type, (IConstructor) TreeAdapter.getASTArgs(tree).get(0), false, ctx);
    }
   
    if (TreeAdapter.isAppl(tree)) {
      IList args = TreeAdapter.getASTArgs(tree);
     
      int j = 0;
      IMapWriter cw = values.mapWriter();
      IListWriter aw = values.listWriter();
      for (IValue kid : TreeAdapter.getArgs(tree)) {
        if (TreeAdapter.isLayout((IConstructor) kid)) {
          IList cts = extractComments((IConstructor) kid);
          if (!cts.isEmpty()) {
            cw.put(values.integer(j), cts);
          }
          j++;
        }
        else if (!TreeAdapter.isLiteral((IConstructor) kid) &&
            !TreeAdapter.isCILiteral((IConstructor) kid) &&
            !TreeAdapter.isEmpty((IConstructor) kid)) {
          aw.append(kid);
        }
      }
      args = aw.done();
      int length = args.length();
      IMap comments = cw.done();
     
//      // this could be optimized.
//      i = 0;
//      int length = args.length();
//      while (i < length) {
//        if (TreeAdapter.isEmpty((IConstructor) args.get(i))) {
//          length--;
//          args = args.delete(i);
//        }
//        else {
//          i++;
//        }
//      }
     
     
      java.lang.String constructorName = unescapedConsName(tree);     
     
      if (constructorName == null) {
        if (length == 1) {
          // jump over injection
          return implode(store, type, (IConstructor) args.get(0), splicing, ctx);
        }
       
       
        // make a tuple if we're in node space
        if (isUntypedNodeType(type)) {
          return values.tuple(implodeArgs(store, type, args, ctx));
        }

        if (!type.isTuple()) {
          throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Constructor does not match with " + type));
        }
       
        if (length != type.getArity()) {
          throw new Backtrack(RuntimeExceptionFactory.arityMismatch(type.getArity(), length, null, null));
        }

        return values.tuple(implodeArgs(store, type, args, ctx));
      }
     
      // if in node space, make untyped nodes
      if (isUntypedNodeType(type)) {
        INode ast = values.node(constructorName, implodeArgs(store, type, args, ctx));
        return ast.asAnnotatable().setAnnotation("location", TreeAdapter.getLocation(tree)).asAnnotatable().setAnnotation("comments", comments);
      }
     
      // make a typed constructor
      if (!type.isAbstractData()) {
        throw new Backtrack(RuntimeExceptionFactory.illegalArgument(tree, null, null, "Constructor (" + constructorName + ") should match with abstract data type and not with " + type));
      }

      Set<Type> conses = findConstructors(type, constructorName, length, store);
      Iterator<Type> iter = conses.iterator();
      while (iter.hasNext()) {
        try {
          Type cons = iter.next();
          ISourceLocation loc = TreeAdapter.getLocation(tree);
          IValue[] implodedArgs = implodeArgs(store, cons, args, ctx);
          IConstructor ast = makeConstructor(type, constructorName, ctx, implodedArgs);
          return ast.asAnnotatable().setAnnotation("location", loc).asAnnotatable().setAnnotation("comments", comments);
        }
        catch (Backtrack b) {
View Full Code Here

TOP

Related Classes of org.eclipse.imp.pdb.facts.ISourceLocation

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.