Package org.rascalmpl.interpreter.result

Examples of org.rascalmpl.interpreter.result.ConstructorFunction


  }
 
  @Override
  public ConstructorFunction constructorFromTuple(AbstractAST ast, Evaluator eval, Type adt, String name, Type tupleType, Type keywordParams, List<KeywordFormal> initializers) {
    Type cons = makeTupleType(adt, name, tupleType, keywordParams);
    ConstructorFunction function = new ConstructorFunction(ast, eval, this, cons, initializers);
    storeFunction(name, function);
    markNameFinal(name);
    markNameOverloadable(name);
    return function;
  }
View Full Code Here


        }
       
        Type children = tf.tupleType(fields, labels);
       
        try {
          ConstructorFunction cons = env.constructorFromTuple(var, eval, adt, altName, children, kwType, kws);
          cons.setPublic(true); // TODO: implement declared visibility
        } catch (org.eclipse.imp.pdb.facts.exceptions.RedeclaredConstructorException e) {
          throw new RedeclaredType(altName, var);
        } catch (RedeclaredFieldNameException e) {
          throw new RedeclaredField(e.getMessage(), var);
        }
View Full Code Here

      }
    }

    if (type.hasKeywordParameters()) {
      // this fills in the defaults for pattern matching against them:
      ConstructorFunction func = ctx.getCurrentEnvt().getConstructorFunction(type);
      Map<String, IValue> kwArgs = func.computeKeywordArgs(subjectChildren, subject.getValue().asWithKeywordParameters().getParameters());

     
      for (String kwLabel : type.getKeywordParameterTypes().getFieldNames()) {
        IValue subjectParam = kwArgs.get(kwLabel);
       
        if (keywordParameters.containsKey(kwLabel)) {
          IMatchingResult matcher = keywordParameters.get(kwLabel);
          matcher.initMatch(ResultFactory.makeResult(type.getKeywordParameterType(kwLabel), subjectParam, ctx));
         
          if (!matcher.hasNext()) {
            // the matcher can never work, so we can skip initializing the rest
            hasNext = false;
            break;
          }
        }
       
        // note if there is no matcher for the current parameter, still we have initialized it because the next
        // keyword parameter that who do match on may depend on its dynamic value.
      }
    }
    else if (this.subject.mayHaveKeywordParameters()) {
      Map<String, IValue> kwArgs;
     
      // the matching side has no declared keyword parameters (an untyped node), so we do not have default values to take care of
      if (this.subject.getType().isAbstractData()) {
        ConstructorFunction func = ctx.getCurrentEnvt().getConstructorFunction(((IConstructor) this.subject).getConstructorType());
     
        if (func != null) {
          kwArgs = func.computeKeywordArgs(subjectChildren, subject.getValue().asWithKeywordParameters().getParameters());
        }
        else {
          // the definition of the constructor could not be found, so we don't have defaults
          kwArgs = this.subject.asWithKeywordParameters().getParameters();
        }
View Full Code Here

    List<AbstractFunction> list = new LinkedList<>();
    getAllFunctions(constructorType.getAbstractDataType(), constructorType.getName(), list);
   
    for (AbstractFunction candidate : list) {
      if (candidate instanceof ConstructorFunction) {
        ConstructorFunction func = (ConstructorFunction) candidate;
       
        if (func.getName().equals(constructorType.getName())
            && func.getFunctionType() == functionType) {
          return func;
        }
      }
    }
   
View Full Code Here

TOP

Related Classes of org.rascalmpl.interpreter.result.ConstructorFunction

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.