-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e8491c
commit 945e9d4
Showing
28 changed files
with
725 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/AnonymousFunctionCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.metapath.cst; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.DynamicContext; | ||
import gov.nist.secauto.metaschema.core.metapath.ISequence; | ||
import gov.nist.secauto.metaschema.core.metapath.function.IArgument; | ||
import gov.nist.secauto.metaschema.core.metapath.function.IFunction; | ||
import gov.nist.secauto.metaschema.core.metapath.function.impl.AbstractFunction; | ||
import gov.nist.secauto.metaschema.core.metapath.item.IItem; | ||
import gov.nist.secauto.metaschema.core.metapath.type.ISequenceType; | ||
import gov.nist.secauto.metaschema.core.util.ObjectUtils; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
|
||
/** | ||
* Executes a function call based on a specifier expression that is used to | ||
* dtermine the function and multiple argument expressions that are used to | ||
* determine the function arguments. | ||
*/ | ||
public class AnonymousFunctionCall | ||
extends AbstractFunction | ||
implements IExpression, IFunction { | ||
@NonNull | ||
private static final Set<FunctionProperty> PROPERTIES = ObjectUtils.notNull(EnumSet.of( | ||
// FunctionProperty.CONTEXT_DEPENDENT, | ||
// FunctionProperty.FOCUS_DEPENDENT, | ||
FunctionProperty.DETERMINISTIC)); | ||
@NonNull | ||
private final ISequenceType result; | ||
@NonNull | ||
private final IExpression body; | ||
|
||
/** | ||
* Construct a new function call expression. | ||
* | ||
* @param arguments | ||
*/ | ||
public AnonymousFunctionCall( | ||
@NonNull List<IArgument> arguments, | ||
@NonNull ISequenceType result, | ||
@NonNull IExpression body) { | ||
super("(anonymous)-" + UUID.randomUUID().toString(), "", arguments); | ||
this.result = result; | ||
this.body = body; | ||
} | ||
|
||
@Override | ||
public List<IExpression> getChildren() { | ||
return ObjectUtils.notNull(List.of(body)); | ||
} | ||
|
||
@Override | ||
public Class<? extends IItem> getBaseResultType() { | ||
return IFunction.class; | ||
} | ||
|
||
@Override | ||
public <RESULT, CONTEXT> RESULT accept(IExpressionVisitor<RESULT, CONTEXT> visitor, CONTEXT context) { | ||
return visitor.visitAnonymousFunctionCall(this, context); | ||
} | ||
|
||
@Override | ||
public ISequence<?> accept(DynamicContext dynamicContext, ISequence<?> focus) { | ||
return ISequence.of(this); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
@Override | ||
public String toASTString() { | ||
return String.format("%s[arguments=%s,return=%s]", | ||
getClass().getName(), getName(), | ||
getArguments(), | ||
result.toSignature()); | ||
} | ||
|
||
@Override | ||
public Set<FunctionProperty> getProperties() { | ||
return PROPERTIES; | ||
} | ||
|
||
@Override | ||
public ISequenceType getResult() { | ||
return result; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
protected ISequence<?> executeInternal( | ||
@NonNull List<ISequence<?>> arguments, | ||
@NonNull DynamicContext dynamicContext, | ||
@Nullable IItem focus) { | ||
|
||
DynamicContext subContext = dynamicContext.subContext(); | ||
Iterator<? extends ISequence<?>> args = arguments.iterator(); | ||
Iterator<IArgument> params = getArguments().iterator(); | ||
while (args.hasNext() && params.hasNext()) { | ||
ISequence<?> sequence = args.next(); | ||
IArgument param = params.next(); | ||
|
||
subContext.bindVariableValue(param.getName(), ObjectUtils.notNull(sequence)); | ||
} | ||
|
||
return body.accept(subContext, ISequence.of(focus)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.