Generate a type pattern representing the type and name of all quantifier
variables described by this quantifier.

@param expr
@return
978595
private WyalFile.VariableDeclaration[] generateQuantifierTypePattern(WyilFile.Expr.Quantifier expr,
			LocalEnvironment environment) {
		//
		Tuple<WyilFile.Decl.Variable> params = expr.getParameters();
		WyalFile.VariableDeclaration[] vardecls = new WyalFile.VariableDeclaration[params.size()];
		for (int i = 0; i != params.size(); ++i) {
			WyilFile.Decl.Variable var = params.get(i);
			vardecls[i] = environment.read(var);
		}
		return vardecls;
	}
1067339
public static ExprBoolean toExprBoolean(Expression expr) {
	if (expr instanceof ExprBoolean) return (ExprBoolean) expr;
	if (expr instanceof Literal) {
	    Boolean bool = ((Literal) expr).getBoolean(null);
	    if (bool != null) return expr.getFactory().createLitBoolean(bool.booleanValue(), expr.getStart(), expr.getEnd());
	    // TODO throw new TemplateException("can't cast value to a boolean value");
	}
	return new CastBoolean(expr);
    }
1324225
private boolean validConditionalExpression(Node expr) {
    // The expression must have four children:
    // - The cond keyword
    // - A boolean expression
    // - A type transformation expression with the 'if' branch
    // - A type transformation expression with the 'else' branch
    if (!checkParameterCount(expr, Keywords.COND)) {
      return false;
    }
    // Check for the validity of the boolean and the expressions
    if (!validBooleanExpression(getCallArgument(expr, 0))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    if (!validTypeTransformationExpression(getCallArgument(expr, 1))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    if (!validTypeTransformationExpression(getCallArgument(expr, 2))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    return true;
  }
556876
public Tuple<Decl.Variable> determineUsedVariables(Tuple<WyilFile.Expr> exprs) {
		HashSet<Decl.Variable> used = new HashSet<>();
		usedVariableExtractor.visitExpressions(exprs, used);
		return new Tuple<>(used);
	}
520242
public <T> JDOQuery<T> select(Expression<T> expr) {
        return query().select(expr);
    }
870798
public static <T> QBean<T> fields(Path<? extends T> type, Expression<?>... exprs) {
        return new QBean<T>(type.getType(), true, exprs);
    }
1209487
private boolean validRawTypeOfTypeExpression(Node expr) {
    // The expression must have two children. The rawTypeOf keyword and the
    // parameter
    if (!checkParameterCount(expr, Keywords.RAWTYPEOF)) {
      return false;
    }
    // The parameter must be a valid type expression
    if (!validTypeTransformationExpression(getCallArgument(expr, 0))) {
      warnInvalidInside(Keywords.RAWTYPEOF.name, expr);
      return false;
    }
    return true;
  }
1208683
public static Object execExpr(ExprResolver exprResolver, String expression) {

        try {
            // 返回输出的内容
            return exprResolver.executeExpr(expression);

        } catch (Exception e) {

            // 输出日志
            if (logger.isDebugEnabled()) {
                logger.debug("Can't resolving expression: " + expression, e);
            }
        }

        return null;
    }
1037525
public final DSLMapParser.variable_reference_expr_return variable_reference_expr() throws RecognitionException {
		DSLMapParser.variable_reference_expr_return retval = new DSLMapParser.variable_reference_expr_return();
		retval.start = input.LT(1);

		Object root_0 = null;

		Token set36=null;

		Object set36_tree=null;

		try {
			// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:248:5: ( ( LITERAL | EQUALS )+ )
			// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:248:8: ( LITERAL | EQUALS )+
			{
			root_0 = (Object)adaptor.nil();


			// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:248:8: ( LITERAL | EQUALS )+
			int cnt17=0;
			loop17:
			while (true) {
				int alt17=2;
				int LA17_0 = input.LA(1);
				if ( (LA17_0==EQUALS||LA17_0==LITERAL) ) {
					alt17=1;
				}

				switch (alt17) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/dsl/DSLMap.g:
					{
					set36=input.LT(1);
					if ( input.LA(1)==EQUALS||input.LA(1)==LITERAL ) {
						input.consume();
						if ( state.backtracking==0 ) adaptor.addChild(root_0, (Object)adaptor.create(set36));
						state.errorRecovery=false;
						state.failed=false;
					}
					else {
						if (state.backtracking>0) {state.failed=true; return retval;}
						MismatchedSetException mse = new MismatchedSetException(null,input);
						throw mse;
					}
					}
					break;

				default :
					if ( cnt17 >= 1 ) break loop17;
					if (state.backtracking>0) {state.failed=true; return retval;}
					EarlyExitException eee = new EarlyExitException(17, input);
					throw eee;
				}
				cnt17++;
			}

			}

			retval.stop = input.LT(-1);

			if ( state.backtracking==0 ) {
			retval.tree = (Object)adaptor.rulePostProcessing(root_0);
			adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
			}
		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
			retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);
		}
		finally {
			// do for sure before leaving
		}
		return retval;
	}
1001151
public String conditionalExpression() throws RecognitionException {
        int first = input.index();
        exprParser.conditionalExpression();
        if ( state.failed ) return null;

        if ( state.backtracking == 0 && input.index() > first ) {
            // expression consumed something
            String expr = input.toString( first,
                                          input.LT( -1 ).getTokenIndex() );
            return expr;
        }
        return null;
    }
115075
public static <T> Expression<T> list(Class<T> clazz, Expression<?>... exprs) {
        return list(clazz, ImmutableList.copyOf(exprs));
    }
1081635
public static List<String> parse(String expr) {
        
        List<String> expressions = new ArrayList<>();
        
        int parenthesis = 0; // '(' and ')'
        int brackets = 0; // '{' and '}'
        int brackets2 = 0; // '[' and ']'

        String[] lines = expr.split("\n");
        StringBuilder sb = new StringBuilder();
        for(String line : lines) {
            line = line.trim();
            if(line.startsWith("#")) {
                // Ignore commented lines
            } else {
                char currentChar=0;
                for (int i = 0; i < line.length(); i++) {
                    currentChar = line.charAt(i);
                    if (currentChar == '#') {// Ignore rest of line
                        line = line.substring(0,i);
                        break; 
                    } else if (currentChar == '(') {
                        parenthesis++;
                    } else if (currentChar == ')') {
                        parenthesis--;
                    } else if (currentChar == '{') {
                        brackets++;
                    } else if (currentChar == '}') {
                        brackets--;
                    } else if (currentChar == '[') {
                        brackets2++;
                    } else if (currentChar == ']') {
                        brackets2--;
                    } else if (parenthesis == 0 && brackets == 0 && brackets2 == 0) {
                        if(currentChar == ';') {
                            String firstLine = line.substring(0, i+1);
                            sb.append(firstLine);                            
                            expressions.add(sb.toString());
                            sb = new StringBuilder();
                                                        
                            String remainder = line.substring(i+1);
                            line = remainder.trim()+"\n";
                            i=0;
                        }
                    }
                }
                if(line.trim().length()>0) {
                    sb.append(line);
                    if(parenthesis == 0 && brackets == 0 && brackets2 == 0) {
                        expressions.add(sb.toString());
                        sb = new StringBuilder();
                    } else {
                        if (currentChar!=',' && currentChar!='+' && currentChar!='-' && currentChar!='*' &&currentChar!='/' &&currentChar!='=')
                        sb.append(";\n");
                    }
                }
            }
        }
        
        return expressions;
    }
293186
public static Object calculateGuess(JCExpression expr) {
		if (expr instanceof JCLiteral) {
			JCLiteral lit = (JCLiteral) expr;
			if (lit.getKind() == com.sun.source.tree.Tree.Kind.BOOLEAN_LITERAL) {
				return ((Number) lit.value).intValue() == 0 ? false : true;
			}
			return lit.value;
		}
		
		if (expr instanceof JCIdent || expr instanceof JCFieldAccess) {
			String x = expr.toString();
			if (x.endsWith(".class")) return new ClassLiteral(x.substring(0, x.length() - 6));
			int idx = x.lastIndexOf('.');
			if (idx > -1) x = x.substring(idx + 1);
			return new FieldSelect(x);
		}
		
		return null;
	}
95065
public static boolean containsAggregateExpression(AbstractExpression expr) {
        AbstractExpression.SubexprFinderPredicate pred =
                new AbstractExpression.SubexprFinderPredicate() {
            @Override
            public boolean matches(AbstractExpression expr) {
                return expr.getExpressionType().isAggregateExpression();
            }
        };
        return expr.hasAnySubexpressionWithPredicate(pred);
    }
289205
public static AbstractExpression evaluateExpression(AbstractExpression expr) {
        if (expr == null) {
            return null;
        }

        // Evaluate children first
        expr.setLeft(evaluateExpression(expr.getLeft()));
        expr.setRight(evaluateExpression(expr.getRight()));

        // Evaluate self
        if (ExpressionType.CONJUNCTION_AND == expr.getExpressionType()) {
            if (ExpressionType.VALUE_CONSTANT == expr.getLeft().getExpressionType()) {
                if (ConstantValueExpression.isBooleanTrue(expr.getLeft())) {
                    return expr.getRight();
                } else {
                    return expr.getLeft();
                }
            }
            if (ExpressionType.VALUE_CONSTANT == expr.getRight().getExpressionType()) {
                if (ConstantValueExpression.isBooleanTrue(expr.getRight())) {
                    return expr.getLeft();
                } else {
                    return expr.getRight();
                }
            }
        } else if (ExpressionType.CONJUNCTION_OR == expr.getExpressionType()) {
            if (ExpressionType.VALUE_CONSTANT == expr.getLeft().getExpressionType()) {
                if (ConstantValueExpression.isBooleanTrue(expr.getLeft())) {
                    return expr.getLeft();
                } else {
                    return expr.getRight();
                }
            }
            if (ExpressionType.VALUE_CONSTANT == expr.getRight().getExpressionType()) {
                if (ConstantValueExpression.isBooleanTrue(expr.getRight())) {
                    return expr.getRight();
                } else {
                    return expr.getLeft();
                }
            }
        } else if (ExpressionType.OPERATOR_NOT == expr.getExpressionType()) {
            AbstractExpression leftExpr = expr.getLeft();
            // function expressions can also return boolean. So the left child expression
            // can be expression which are not constant value expressions, so don't
            // evaluate every left child expr as constant value expression
            if ((VoltType.BOOLEAN == leftExpr.getValueType()) &&
                    (leftExpr instanceof ConstantValueExpression)) {
                if (ConstantValueExpression.isBooleanTrue(leftExpr)) {
                    return ConstantValueExpression.getFalse();
                } else {
                    return ConstantValueExpression.getTrue();
                }
            } else if (ExpressionType.OPERATOR_NOT == leftExpr.getExpressionType()) {
                return leftExpr.getLeft();
            } else if (ExpressionType.CONJUNCTION_OR == leftExpr.getExpressionType()) {
                // NOT (.. OR .. OR ..) => NOT(..) AND NOT(..) AND NOT(..)
                AbstractExpression l = new OperatorExpression(ExpressionType.OPERATOR_NOT, leftExpr.getLeft(), null);
                AbstractExpression r = new OperatorExpression(ExpressionType.OPERATOR_NOT, leftExpr.getRight(), null);
                leftExpr = new OperatorExpression(ExpressionType.CONJUNCTION_AND, l, r);
                return evaluateExpression(leftExpr);
            }
            // NOT (expr1 AND expr2) => (NOT expr1) || (NOT expr2)
            // The above case is probably not interesting to do for short circuit purpose
        }
        return expr;
    }
48155
public static <T extends Number & Comparable<?>> NumberExpression<T> asNumber(Expression<T> expr) {
        Expression<T> underlyingMixin = ExpressionUtils.extract(expr);
        if (underlyingMixin instanceof PathImpl) {
            return new NumberPath<T>((PathImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof OperationImpl) {
            return new NumberOperation<T>((OperationImpl<T>) underlyingMixin);
        } else if (underlyingMixin instanceof TemplateExpressionImpl) {
            return new NumberTemplate<T>((TemplateExpressionImpl<T>) underlyingMixin);
        } else {
            return new NumberExpression<T>(underlyingMixin) {

                private static final long serialVersionUID = -8712299418891960222L;

                @Override
                public <R, C> R accept(Visitor<R, C> v, C context) {
                    return this.mixin.accept(v, context);
                }

            };
        }
    }
633349
function makeSimpleExpr(expr) {
    var a, b, c;
    if (expr.charAt(0) === '$') {
        return new VariableExpr(expr.substr(1));
    } else if (expr.charAt(0) === '@') {
        a = new NodeTestName(expr.substr(1));
        b = new StepExpr('attribute', a);
        c = new LocationExpr();
        c.appendStep(b);
        return c;
    } else if (expr.match(/^[0-9]+$/)) {
        return new NumberExpr(expr);
    } else {
        a = new NodeTestName(expr);
        b = new StepExpr('child', a);
        c = new LocationExpr();
        c.appendStep(b);
        return c;
    }
}