
org.snapscript.tree.function.ParameterListCompiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
The newest version!
package org.snapscript.tree.function;
import static org.snapscript.core.constraint.Constraint.NONE;
import static org.snapscript.core.function.Origin.DEFAULT;
import java.util.ArrayList;
import java.util.List;
import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.function.FunctionSignature;
import org.snapscript.core.function.Parameter;
import org.snapscript.core.function.ParameterBuilder;
import org.snapscript.core.function.Signature;
import org.snapscript.core.module.Module;
import org.snapscript.core.scope.Scope;
public class ParameterListCompiler {
private final ParameterMatchChecker checker;
private final ParameterDeclaration[] list;
private final ParameterBuilder builder;
public ParameterListCompiler(ParameterDeclaration... list) {
this.checker = new ParameterMatchChecker(list);
this.builder = new ParameterBuilder();
this.list = list;
}
public Signature compile(Scope scope, List generics) throws Exception{
return compile(scope, generics, null);
}
public Signature compile(Scope scope, List generics, String prefix) throws Exception{
List parameters = new ArrayList();
if(prefix != null) {
Parameter parameter = builder.create(NONE, prefix, 0); // this is constrained by type
parameters.add(parameter);
}
Module module = scope.getModule();
boolean variable = checker.isVariable(scope);
boolean absolute = checker.isAbsolute(scope);
int start = parameters.size();
for(int i = 0; i < list.length; i++) {
ParameterDeclaration declaration = list[i];
if(declaration != null) {
Parameter parameter = declaration.get(scope, start + i);
Constraint constraint = parameter.getConstraint();
constraint.getType(scope);
parameters.add(parameter);
}
}
return new FunctionSignature(parameters, generics, module, null, DEFAULT, absolute, variable);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy