Package org.rascalmpl.interpreter.result

Examples of org.rascalmpl.interpreter.result.OverloadedFunction


     
      if (result.isEmpty()) {
        return null;
      }
     
      return new OverloadedFunction(cons, result);
    }
   
    if (modulename != null) {
      if (modulename.equals(getName())) {
        return getVariable(cons);
View Full Code Here


    try {
      ModuleEnvironment modEnv = getHeap().getModule(module);
      setCurrentEnvt(modEnv);
     
      Name name = Names.toName(function, modEnv.getLocation());
      OverloadedFunction func = (OverloadedFunction) getCurrentEnvt().getVariable(name);
     
      if (func == null) {
        throw new UndeclaredVariable(function, name);
      }
     
      AbstractFunction main = func.getFunctions().get(0);
     
      if (func.getFunctions().size() > 1) {
        throw new CommandlineError("should only have one main function", main);
      }
     
      if (main.getArity() == 1) {
        return func.call(getMonitor(), new Type[] { tf.listType(tf.stringType()) },new IValue[] { parsePlainCommandLineArgs(commandline)}, null).getValue();
      }
      else if (main.hasKeywordArgs() && main.getArity() == 0) {
        Map<String, IValue> args = parseKeywordCommandLineArgs(monitor, commandline, main);
        return func.call(getMonitor(), new Type[] { },new IValue[] {}, args).getValue();
      }
      else {
        throw new CommandlineError("main function should either have one argument of type list[str], or keyword parameters", main);
      }
    }
View Full Code Here

    setCurrentAST(qualifiedName);
    return call(qualifiedName, kwArgs, args);
  }
 
  public IValue call(QualifiedName qualifiedName, Map<String,IValue> kwArgs, IValue... args) {
    OverloadedFunction func = (OverloadedFunction) getCurrentEnvt().getVariable(qualifiedName);
    RascalTypeFactory rtf = RascalTypeFactory.getInstance();
   
    Type[] types = new Type[args.length];

    int i = 0;
    for (IValue v : args) {
      Type type = v.getType();
      types[i++] = type.isSubtypeOf(Factory.Tree) ? rtf.nonTerminalType((IConstructor) v) : type;
    }
   
    if (func == null) {
      throw new UndeclaredFunction(Names.fullName(qualifiedName), types, this, getCurrentAST());
    }

    return func.call(getMonitor(), types, args, kwArgs).getValue();
  }
View Full Code Here

    super(computeMessage(function, argTypes), caller);
  }

  private static String computeMessage(Result<IValue> function, Type[] argTypes) {
    if (function instanceof OverloadedFunction) {
      OverloadedFunction of = (OverloadedFunction) function;
      return computeMessage(of.getName(), of.getFunctions(), argTypes);
    }
    else {
      AbstractFunction func = (AbstractFunction) function;
      return computeMessage(func.getName(), Arrays.<AbstractFunction>asList(func), argTypes);
    }
View Full Code Here

    getAllFunctions(name, funcs);
   
    if (funcs.isEmpty()) {
      return null;
    }
    return new OverloadedFunction(name, funcs);
  }
View Full Code Here

TOP

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

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.