Determine the set of used variables in a given set of expressions. A used
variable is one referred to by a VariableAccess expression.

@param expression
@return
556876
public Tuple<Decl.Variable> determineUsedVariables(Tuple<WyilFile.Expr> exprs) {
		HashSet<Decl.Variable> used = new HashSet<>();
		usedVariableExtractor.visitExpressions(exprs, used);
		return new Tuple<>(used);
	}
856152
public void visitVariableExpression(VariableExpression expression) {
        String variableName = expression.getName();

        //-----------------------------------------------------------------------
        // SPECIAL CASES

        // "this" for static methods is the Class instance
        ClassNode classNode = controller.getClassNode();
        //if (controller.isInClosure()) classNode = controller.getOutermostClass();

        if (variableName.equals("this")) {
            if (controller.isStaticMethod() || (!controller.getCompileStack().isImplicitThis() && controller.isStaticContext())) {
                if (controller.isInClosure()) classNode = controller.getOutermostClass();
                visitClassExpression(new ClassExpression(classNode));
            } else {
                loadThis(expression);
            }
            return;
        }

        // "super" also requires special handling
        if (variableName.equals("super")) {
            if (controller.isStaticMethod()) {
                visitClassExpression(new ClassExpression(classNode.getSuperClass()));
            } else {
                loadThis(expression);
            }
            return;
        }

        BytecodeVariable variable = controller.getCompileStack().getVariable(variableName, false);
        if (variable == null) {
            processClassVariable(variableName);
        } else {
            controller.getOperandStack().loadOrStoreVariable(variable, expression.isUseReferenceDirectly());
        }
        if (!controller.getCompileStack().isLHS()) controller.getAssertionWriter().record(expression);
    }
505225
public List<Variable> getUsedVariables() {
        ArrayList<Variable> vars = new ArrayList<Variable>();

        for (Operand o : getOperands()) {
            o.addUsedVariables(vars);
        }

        return vars;
    }
509783
public static Expression createExpression(String expression) {
        try {
            return INSTANCE.ctorExpression.newInstance(expression);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
760609
private void checkForFinal(final Expression expression, VariableExpression ve) {
        Variable v = ve.getAccessedVariable();
        boolean isFinal = isFinal(v.getModifiers());
        boolean isParameter = v instanceof Parameter;
        if (isFinal && isParameter) {
            addError("Cannot assign a value to final variable '" + v.getName() + "'", expression);
        }
    }
1176416
def get_variables(expression, variables=None):
    """"""
    if variables is None:
        variables = set()
    if hasattr(expression, 'variable_name') and expression.variable_name is not None:
        variables.add(expression.variable_name)
    if isinstance(expression, Operation):
        for operand in op_iter(expression):
            get_variables(operand, variables)
    return variables
404586
protected Object getParsedExpression(final String expression) {
		try {
			return Ognl.parseExpression(expression);
		} catch (OgnlException ex) {
			throw new OgnlRuntimeException("Failed to parse the expression.[" + expression + "]", ex);
		}
	}
252022
def get_vars_in_expression(source):
    ''''''

    import compiler
    from compiler.ast import Node

    ##
    # @brief Internal recursive function.
    # @param node An AST parse Node.
    # @param var_list Input list of variables.
    # @return An updated list of variables.
    def get_vars_body(node, var_list=[]):
        if isinstance(node, Node):
            if node.__class__.__name__ == 'Name':
                for child in node.getChildren():
                    if child not in var_list:
                        var_list.append(child)
            for child in node.getChildren():
                if isinstance(child, Node):
                    for child in node.getChildren():
                        var_list = get_vars_body(child, var_list)
                    break

        return var_list

    return get_vars_body(compiler.parse(source))
115867
public String getExpressionString() {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < mElements.length; i++) {
            Object elem = mElements[i];
            if (elem instanceof String) {
                buf.append((String) elem);
            } else if (elem instanceof Expression) {
                buf.append("${");
                buf.append(((Expression) elem).getExpressionString());
                buf.append("}");
            }
        }
        return buf.toString();
    }
90585
public static Variable lookup(String varName, BindingSet bindingSet) {
        if (bindingSet == null) {
            return null;
        }
        Binding binding = bindingSet.lookup(varName);
        return (binding != null) ? binding.getVariable() : null;
    }
1200215
public static List<Expression> getVariableExpressions(DeclarationExpression declarationExpression) {
        Expression leftExpression = declarationExpression.getLeftExpression();

        // !important: performance enhancement
        if (leftExpression instanceof ArrayExpression) {
            List<Expression> expressions = ((ArrayExpression) leftExpression).getExpressions();
            return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
        } else if (leftExpression instanceof ListExpression) {
            List<Expression> expressions = ((ListExpression) leftExpression).getExpressions();
            return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
        } else if (leftExpression instanceof TupleExpression) {
            List<Expression> expressions = ((TupleExpression) leftExpression).getExpressions();
            return expressions.isEmpty() ? Arrays.asList(leftExpression) : expressions;
        } else if (leftExpression instanceof VariableExpression) {
            return Arrays.asList(leftExpression);
        }
        // todo: write warning
        return Collections.emptyList();
    }
1353219
private String chooseAlternations(final String expression) {
		StrBuilder sb = new StrBuilder(expression);

		int i = 0;
		// Loop until an unescaped pipe symbol appears.
		while (UNESCAPED_PIPE_PATTERN.matcher(sb.toString()).find()) {
			for (; i < sb.length(); ++i) {
				if (sb.charAt(i) == '|') {
					if (sb.charAt(i - 1) == '\\') {
						// escapet
						continue;
					}

					int start = i;
					// Backtrack until an opening bracket is found
					// to limit the context of alternatives.
					for (int closingCount = 0; start >= 0; --start) {
						char c = sb.charAt(start);
						if (c == '(') {
							if (closingCount == 0) {
								break;
							}
							--closingCount;
						} else if (c == ')') {
							++closingCount;
						}
					}

					if (start >= 0) {
						// If an opening brace was found
						// search for a closing bracket.
						int end = i;
						for (int openingCount = 0; end < sb.length(); ++end) {
							char c = sb.charAt(end);
							if (c == '(') {
								++openingCount;
							} else if (c == ')') {
								if (openingCount == 0) {
									break;
								}
								--openingCount;
							}
						}
						String alternative = random.getBoolean() ? sb.substring(start + 1, i) : sb.substring(i + 1, end);
						sb.replace(start, end + 1, alternative);
						i = start + alternative.length();
						break;
					}
					String alternative = random.getBoolean() ? sb.substring(0, i) : sb.substring(i + 1);
					sb.replace(0, sb.length() + 1, alternative);
					break;
				}
			}
		}
		return sb.toString();
	}
867951
public boolean assertExpression(String variableNameExpression, String expectedValue)
    {
    	Expression expression = new Expression(variableNameExpression);
    	return expectedValue.equals(this.variables.get(expression.parseVariableName()));
    }
1211788
public static Set<Symbol> extractUnique(RowExpression expression)
    {
        return ImmutableSet.copyOf(extractAll(expression).stream().map(variable -> new Symbol(variable.getName())).collect(toSet()));
    }
1105798
private static boolean isPredefinedConstant(Expression expression) {
        if (expression instanceof PropertyExpression) {
            Expression object = ((PropertyExpression) expression).getObjectExpression();
            Expression property = ((PropertyExpression) expression).getProperty();

            if (object instanceof VariableExpression) {
                List<String> predefinedConstantNames = PREDEFINED_CONSTANTS.get(((VariableExpression) object).getName());
                if (predefinedConstantNames != null && predefinedConstantNames.contains(property.getText())) {
                    return true;
                }
            }
        }
        return false;
    }
1169273
@Check
	public void checkAssertKeywordUse(SarlAssertExpression expression) {
		final XExpression condition = expression.getCondition();
		if (condition != null) {
			final LightweightTypeReference fromType = getActualType(condition);
			if (!fromType.isAssignableFrom(Boolean.TYPE)) {
				error(MessageFormat.format(
						Messages.SARLValidator_38,
						getNameOfTypes(fromType), boolean.class.getName()),
						condition,
						null,
						ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
						INCOMPATIBLE_TYPES);
				return;
			}
			if (getExpressionHelper() instanceof SARLExpressionHelper) {
				final SARLExpressionHelper helper = (SARLExpressionHelper) getExpressionHelper();
				final Boolean constant = helper.toBooleanPrimitiveWrapperConstant(condition);
				if (constant == Boolean.TRUE && !isIgnored(DISCOURAGED_BOOLEAN_EXPRESSION)) {
					addIssue(Messages.SARLValidator_51,
							condition,
							null,
							ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
							DISCOURAGED_BOOLEAN_EXPRESSION);
					return;
				}
			}
		}
	}
1181660
@Pure
	protected XExpression fromString(String expression) {
		if (!Strings.isEmpty(expression)) {
			ResourceSet resourceSet = this.context.eResource().getResourceSet();
			URI uri = computeUnusedUri(resourceSet);
			Resource resource = getResourceFactory().createResource(uri);
			resourceSet.getResources().add(resource);
			try (StringInputStream is = new StringInputStream(generateExpressionCode(expression))) {
				resource.load(is, null);
				SarlScript script = resource.getContents().isEmpty() ? null : (SarlScript) resource.getContents().get(0);
				SarlEvent topElement = (SarlEvent) script.getXtendTypes().get(0);
				SarlField member = (SarlField) topElement.getMembers().get(0);
				return member.getInitialValue();
			} catch (Throwable exception) {
				throw new RuntimeException(exception);
			} finally {
				resourceSet.getResources().remove(resource);
			}
		}
		throw new IllegalArgumentException("not a valid expression");
	}