Package org.eclipse.imp.pdb.facts

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


  }

  private IList computeTypes(ITypeBinding[] bindings, boolean isDeclaration) {
    IListWriter parameters = values.listWriter();
    for (ITypeBinding parameterType: bindings) {
      IConstructor arg = resolveType(parameterType, isDeclaration);
        parameters.append(arg);
    }
    return parameters.done();
  }
View Full Code Here


    org.eclipse.imp.pdb.facts.type.Type cons = store.lookupConstructor(getTypeSymbol(), "constructor", tf.tupleType(decl.getType(), parameters.getType()));
    return values.constructor(cons, decl, parameters);
  }

  private IConstructor parameterNode(ISourceLocation decl, ITypeBinding[] bound, boolean isDeclaration, boolean isUpperbound) {
  IConstructor boundSym = unboundedSym();
    if (isDeclaration) {
      if (bound.length > 0) {
        boundSym = boundSymbol(bound, isDeclaration, isUpperbound);
      }
      org.eclipse.imp.pdb.facts.type.Type cons = store.lookupConstructor(getTypeSymbol(), "typeParameter", tf.tupleType(decl.getType(), boundSym.getType()));
      return values.constructor(cons, decl, boundSym);
    }
    org.eclipse.imp.pdb.facts.type.Type cons = store.lookupConstructor(getTypeSymbol(), "typeArgument", tf.tupleType(decl.getType()));
    return values.constructor(cons, decl);
  }
View Full Code Here

  }

  public IValue fromJSON(IValue type, IString src, RascalExecutionContext rex) {
    TypeStore store = new TypeStore();
   
    IConstructor type_cons = ((IConstructor) type);
    IMap definitions = rex.getSymbolDefinitions();

    tr.declareAbstractDataTypes(definitions, store);
    Type start = tr.valueToType(type_cons, store);
   
View Full Code Here

    return variable;
  }
 
  @Override
  public IMatchingResult buildMatcher(IEvaluatorContext ctx) {
    IConstructor symbol = ((NonTerminalType) type).getSymbol();
    if (SymbolAdapter.isStarList(symbol) || SymbolAdapter.isPlusList(symbol)) {
      return new ConcreteListVariablePattern(ctx, this, type, name);
    }
    else {
      return new TypedVariablePattern(ctx, this, type, name);
View Full Code Here

            org.rascalmpl.interpreter.AssignableEvaluator.__getTf()
                .nodeType(), __eval.__getValue().getType(),
            this);
      }

      IConstructor node = (IConstructor) __eval.__getValue().getValue();
      Type nodeType = node.getType();

      if (nodeType.isAbstractData()) {
        nodeType = ((IConstructor) __eval.__getValue().getValue())
            .getConstructorType();
      }

      if (!node.getName().equals(
          org.rascalmpl.interpreter.utils.Names.name(this.getName()))) {
        throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
            .nameMismatch(node.getName(),
                org.rascalmpl.interpreter.utils.Names.name(this
                    .getName()), this.getName(), __eval
                    .__getEval().getStackTrace());
      }

      List<org.rascalmpl.ast.Assignable> arguments = this.getArguments();

      if (node.arity() != arguments.size()) {
        throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
            .arityMismatch(node.arity(), arguments.size(), this,
                __eval.__getEval().getStackTrace());
      }

      IValue[] results = new IValue[arguments.size()];
      Type[] resultTypes = new Type[arguments.size()];

      for (int i = 0; i < arguments.size(); i++) {
        Type argType = !nodeType.isConstructor() ? org.rascalmpl.interpreter.AssignableEvaluator
            .__getTf().valueType()
            : nodeType.getFieldType(i);
        IValue arg = node.get(i);
        Result<IValue> result = org.rascalmpl.interpreter.result.ResultFactory
            .makeResult(argType, arg, __eval.__getEval());
        AssignableEvaluator ae = new AssignableEvaluator(__eval
            .__getEnv(), null, result, __eval.__getEval());
        Result<IValue> argResult = arguments.get(i).assignment(ae);
        results[i] = argResult.getValue();
        resultTypes[i] = argType;
      }
     
      if (!nodeType.isAbstractData() && !nodeType.isConstructor()) {
        // TODO: can this be the case?
        return org.rascalmpl.interpreter.result.ResultFactory
            .makeResult(nodeType, __eval.__getEval()
                .getValueFactory().node(node.getName(), results),
                __eval.__getEval());
      }

      Type constructor = __eval.__getEval().getCurrentEnvt()
          .getConstructor(
              node.getName(),
              org.rascalmpl.interpreter.AssignableEvaluator
                  .__getTf().tupleType(resultTypes));

      if (constructor == null) {
        throw new ImplementationError("could not find constructor for "
            + node.getName()
            + " : "
            + org.rascalmpl.interpreter.AssignableEvaluator
                .__getTf().tupleType(resultTypes));
      }
View Full Code Here

        }
        return __eval.recur(this, result);
      }
      else if (receiver.getType().isConstructor()
          || receiver.getType().isAbstractData()) {
        IConstructor cons = (IConstructor) receiver.getValue();
        Type node = cons.getConstructorType();

        if (node.hasField(label)) {
          int index = node.getFieldIndex(label);

          if (!__eval.__getValue().getType().isSubtypeOf(
              node.getFieldType(index))) {
            throw new UnexpectedType(node.getFieldType(index),
                __eval.__getValue().getType(), this);
          }
          __eval.__setValue(__eval.newResult(cons.get(index), __eval
              .__getValue()));

          IValue result = cons.set(index, __eval.__getValue().getValue());
          return __eval.recur(this,
              org.rascalmpl.interpreter.result.ResultFactory
              .makeResult(receiver.getType(), result, __eval
                  .__getEval()));
        }
        else if (node.hasKeywordParameter(label)) {
          if (!__eval.__getValue().getType().isSubtypeOf(
              node.getKeywordParameterType(label))) {
            throw new UnexpectedType(node.getKeywordParameterType(label),
                __eval.__getValue().getType(), this);
          }

          __eval.__setValue(__eval.newResult(cons.asWithKeywordParameters().getParameter(label), __eval.__getValue()));

          IValue result = cons.asWithKeywordParameters().setParameter(label,  __eval.__getValue().getValue());
          return __eval.recur(this,
              org.rascalmpl.interpreter.result.ResultFactory
              .makeResult(receiver.getType(), result, __eval
                  .__getEval()));
        }
View Full Code Here

      }
      else if (receiverType.isExternalType() && receiverType instanceof NonTerminalType) {
        return receiver.fieldAccess(label, __eval.getCurrentEnvt().getStore());
      }
      else if (receiverType.isConstructor() || receiverType.isAbstractData()) {
        IConstructor cons = (IConstructor) receiver.getValue();
        Type node = cons.getConstructorType();

        if (!receiverType.hasField(label, __eval.getCurrentEnvt()
            .getStore())
            && !receiverType.hasKeywordParameter(label, __eval.getCurrentEnvt().getStore())) {
          throw new UndeclaredField(label, receiverType, this);
        }

        if (!node.hasField(label) && ! node.hasKeywordParameter(label)) {
          throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
              .noSuchField(label, this, __eval.getStackTrace());
        }

        if (node.hasKeywordParameter(label)) {
          return ResultFactory
              .makeResult(node.getKeywordParameterType(label), cons.asWithKeywordParameters().getParameter(label)
                  ,__eval);
        }
        else {
          int index = node.getFieldIndex(label);
          return ResultFactory
              .makeResult(node.getFieldType(index), cons.get(index),
                  __eval);
        }
      } else if (receiverType.isSourceLocation()) {
        return receiver.fieldAccess(label, new TypeStore());
      } else {
View Full Code Here

        }

      } else if (rec.getType().isNode()
          && subscript.getType().isInteger()) {
        int index = ((IInteger) subscript.getValue()).intValue();
        IConstructor node = (IConstructor) rec.getValue();

        if (index >= node.arity()) {
          throw org.rascalmpl.interpreter.utils.RuntimeExceptionFactory
              .indexOutOfBounds((IInteger) subscript.getValue(),
                  __eval.__getEval().getCurrentAST(), __eval
                      .__getEval().getStackTrace());
        }
        __eval.__setValue(__eval.newResult(node.get(index), __eval
            .__getValue()));
        node = node.set(index, __eval.__getValue().getValue());
        result = org.rascalmpl.interpreter.result.ResultFactory
            .makeResult(rec.getType(), node, __eval.__getEval());
      } else if (rec.getType().isTuple()
          && subscript.getType().isInteger()) {
        int index = ((IInteger) subscript.getValue()).intValue();
View Full Code Here

    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }
 
  public static void main(String[] args){
    Optional2 o2 = new Optional2();
    IConstructor result = o2.executeParser();
    System.out.println(result);
   
    System.out.println("S(a,O?()) <- good");
  }
View Full Code Here

  private IList flatten(IList args) {
    IListWriter result = VF.listWriter(Factory.Args.getElementType());
    boolean previousWasEmpty = false;
   
    for (int i = 0; i < args.length(); i+=(delta+1)) {
      IConstructor tree = (IConstructor) args.get(i);
     
      if (TreeAdapter.isList(tree) && ProductionAdapter.shouldFlatten(production, TreeAdapter.getProduction(tree))) {
        IList nestedArgs = TreeAdapter.getArgs(tree);
        if (nestedArgs.length() > 0) {
          appendPreviousSeparators(args, result, delta, i, previousWasEmpty);
View Full Code Here

TOP

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

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.