All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.tree.function.ParameterList Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.tree.function;

import java.util.ArrayList;
import java.util.List;

import org.snapscript.core.Module;
import org.snapscript.core.Scope;
import org.snapscript.core.function.FunctionSignature;
import org.snapscript.core.function.Parameter;
import org.snapscript.core.function.ParameterBuilder;
import org.snapscript.core.function.Signature;

public class ParameterList {
   
   private ParameterMatchChecker checker;
   private ParameterDeclaration[] list;
   private ParameterBuilder builder;
   private Signature signature;
   
   public ParameterList(ParameterDeclaration... list) {
      this.checker = new ParameterMatchChecker(list);
      this.builder = new ParameterBuilder();
      this.list = list;
   }
   
   public Signature create(Scope scope) throws Exception{
      return create(scope, null);
   }
   
   public Signature create(Scope scope, String prefix) throws Exception{
      Module module = scope.getModule();
      
      if(signature == null) {
         List parameters = new ArrayList();
         
         if(prefix != null) {
            Parameter parameter = builder.create(null, prefix); // this is constrained by type
            parameters.add(parameter);
         }
         boolean variable = checker.isVariable(scope);
         boolean absolute = checker.isAbsolute(scope);
         
         for(int i = 0; i < list.length; i++) {
            ParameterDeclaration declaration = list[i];
            
            if(declaration != null) {
               Parameter parameter = declaration.get(scope);
               parameters.add(parameter);
            }
         }
         signature = new FunctionSignature(parameters, module, null, absolute, variable);
      }
      return signature;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy