Skip to content

Commit

Permalink
[lang] Fixing the invalid detection of pure status for operations and…
Browse files Browse the repository at this point in the history
… provides an API for retreiving the side-effect expressions.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 13, 2021
1 parent 385e6b2 commit a0c2dc8
Show file tree
Hide file tree
Showing 3 changed files with 448 additions and 162 deletions.
Expand Up @@ -80,9 +80,23 @@ public interface IOperationHelper {
* @param calledOperation the called operation. It is used for detecting recursive calls.
* @param expr the expression to test, usually, the body of the expression.
* @return <code>true</code> if a side effect was detected into the expression.
* @see #getSideEffectCalls(InferredPrototype, XExpression)
*/
boolean hasSideEffects(InferredPrototype calledOperation, XExpression expr);

/** Replies the list of calls that have side effects into the given expression.
*
* <p>This function differs from {@link XExpressionHelper#hasSideEffects(XExpression)} because it explore the
* syntax tree for determining if one action has a side effect.
*
* @param calledOperation the called operation. It is used for detecting recursive calls.
* @param expr the expression to test, usually, the body of the expression.
* @return the list of side-effect calls.
* @since 0.12
* @see #hasSideEffects(InferredPrototype, XExpression)
*/
Iterable<XExpression> getSideEffectExpressions(InferredPrototype calledOperation, XExpression expr);

/** Replies if the given operation could be annotated with {@code @Pure} according
* to its associated adapters.
*
Expand Down
Expand Up @@ -26,6 +26,7 @@

import org.eclipse.xtext.xbase.XExpression;
import org.eclipse.xtext.xbase.lib.Inline;
import org.eclipse.xtext.xbase.lib.Pure;

import io.sarl.lang.sarl.actionprototype.InferredPrototype;

Expand Down Expand Up @@ -110,4 +111,27 @@ default ISideEffectContext branch() {
*/
List<? extends XExpression> getVariableValues(String name);

/** Replies if the side-effect exploration should stop at the first discovered side effect.
*
* @return {@code true} if the algorithm stops at first side-effect occurrence.
* @since 0.12
*/
@Pure
boolean isStoppingAtFirstSideEffect();

/** Register the given call to have a side effect.
*
* @param expression the side-effect expression.
* @since 0.12
*/
void registerSideEffect(XExpression expression);

/** Replies the detected side effect expressions.
*
* @return the side-effect expressions.
* @since 0.12
*/
@Pure
Iterable<XExpression> getSideEffectExpressions();

}

0 comments on commit a0c2dc8

Please sign in to comment.