Lower Expressions involving non-existent ContextFields to TrueLiteral and simplify result.
197457
def _update_context_field_expression(present_locations, expression):
    """"""
    no_op_blocks = (ContextField, Literal, LocalField, UnaryTransformation, Variable)
    if isinstance(expression, BinaryComposition):
        if isinstance(expression.left, ContextField) or isinstance(expression.right, ContextField):
            return _update_context_field_binary_composition(present_locations, expression)
        else:
            return _simplify_non_context_field_binary_composition(expression)
    elif isinstance(expression, TernaryConditional):
        return _simplify_ternary_conditional(expression)
    elif isinstance(expression, BetweenClause):
        lower_bound = expression.lower_bound
        upper_bound = expression.upper_bound
        if isinstance(lower_bound, ContextField) or isinstance(upper_bound, ContextField):
            raise AssertionError(u'Found BetweenClause with ContextFields as lower/upper bounds. '
                                 u'This should never happen: {}'.format(expression))
        return expression
    elif isinstance(expression, (OutputContextField, FoldedContextField)):
        raise AssertionError(u'Found unexpected expression of type {}. This should never happen: '
                             u'{}'.format(type(expression).__name__, expression))
    elif isinstance(expression, no_op_blocks):
        return expression

    raise AssertionError(u'Found unhandled expression of type {}. This should never happen: '
                         u'{}'.format(type(expression).__name__, expression))
997307
def from_like_context(ctx, param, value):
    """"""
    if ctx.obj and ctx.obj.get("like") and (value == "like" or ctx.obj.get("all_like")):
        return ctx.obj["like"][param.name]
    else:
        return None
1039996
private static List<String> _evaluateValueExpressions(FacesContext context, List<String> values)
    {
        // note that we have to create a new List here, because if we
        // change any value on the given List, it will be changed in the
        // NavigationCase too and the EL expression won't be evaluated again
        List<String> target = new ArrayList<String>(values.size());
        for (String value : values)
        {
            if (_isExpression(value))
            {
                // evaluate the ValueExpression
                value = context.getApplication().evaluateExpressionGet(context, value, String.class);
            }
            target.add(value);
        }
        return target;
    }
649430
def _Pluralize(value, unused_context, args):
    """"""
    
    if len(args) == 0:
        s, p = '', 's'
    elif len(args) == 1:
        s, p = '', args[0]
    elif len(args) == 2:
        s, p = args
    else:
        # Should have been checked at compile time
        raise AssertionError
    
    if value > 1:
        return p
    else:
        return s
219922
function evalIteration(result, context, node, vars) {
    var iter = new Ruleset(scopeSelector, vars),
        push = true;

    if (node.condition) {
        var frames = context.frames;
        iter.functionRegistry = frames[0].functionRegistry;
        // ^ fixme: dirty kludge, not sure if it's related 
        // to #3054 - maybe there's more mistery (needs research)
        frames.unshift(iter);
        push = node.condition.eval(context);
        frames.shift();
    }

    if (push) {
        pushArray.apply(iter.rules, node.rules);
        result.push(iter);
    }
}
1050434
@Override
  public void exitNotExpression(GDLParser.NotExpressionContext ctx) {
    if (!ctx.NOT().isEmpty()) {
      Predicate not = new Not(currentPredicates.pop());
      currentPredicates.add(not);
    }
  }
72688
function lowercaseContains(arr, elem) {
    return arr.map(function (arrElem) {
        return arrElem.toLowerCase();
    }).indexOf(elem) !== -1;
}
888739
private FieldPosition[] getNegativePrefixFieldPositions() {
        if (negativePrefixFieldPositions == null) {
            if (negPrefixPattern != null) {
                negativePrefixFieldPositions = expandAffix(negPrefixPattern);
            } else {
                negativePrefixFieldPositions = EmptyFieldPositionArray;
            }
        }
        return negativePrefixFieldPositions;
    }
122449
private String inClause(String field, Set<String> values) {
        String separator = "";
        StringBuffer sb = new StringBuffer(" and (");
        for (String v : values) {
            sb.append(separator);
            sb.append(String.format("%s = '%s'", field, v));
            separator = " or ";
        }
        sb.append(")");
        return sb.toString();
    }
652706
def truthtable2expr(tt, conj=False):
    """"""
    if conj:
        outer, inner = (And, Or)
        nums = tt.pcdata.iter_zeros()
    else:
        outer, inner = (Or, And)
        nums = tt.pcdata.iter_ones()
    inputs = [exprvar(v.names, v.indices) for v in tt.inputs]
    terms = [boolfunc.num2term(num, inputs, conj) for num in nums]
    return outer(*[inner(*term) for term in terms])
703782
function maybeAddEmptyStringAtEnd(elements, items) {
  let length = elements.length;
  if (!length || elements[length - 1].type !== TEMPLATE_LITERAL_PORTION) {
    items.push(createStringLiteralExpression(null, '""'));
  }
}
792056
private static Selector simplifyNOT(Selector tree) {
    if (tree instanceof Literal)
      return new LiteralImpl( EvaluatorImpl.not((Boolean) ((Literal) tree).getValue())); // was BooleanValue
    if (!(tree instanceof Operator))
      return new OperatorImpl(Selector.NOT, tree);
    Operator oper = (Operator) tree;
    switch(oper.getOp()) {
    case Selector.NOT:
      return simplifyTree(oper.getOperands()[0]);
    case Selector.AND:
      return makeOR(simplifyNOT(oper.getOperands()[0]),
                    simplifyNOT(oper.getOperands()[1]));
    case Selector.OR:
      return makeAND(simplifyNOT(oper.getOperands()[0]),
                     simplifyNOT(oper.getOperands()[1]));
    case Selector.EQ:
      return simplifyNE(oper.getOperands()[0], oper.getOperands()[1]);
    case Selector.NE:
      return simplifyEQ(oper.getOperands()[0], oper.getOperands()[1]);
    case Selector.GT:
      return new OperatorImpl(Selector.LE, oper.getOperands()[0], oper.getOperands()[1]);
    case Selector.LT:
      return new OperatorImpl(Selector.GE, oper.getOperands()[0], oper.getOperands()[1]);
    case Selector.GE:
      return new OperatorImpl(Selector.LT, oper.getOperands()[0], oper.getOperands()[1]);
    case Selector.LE:
      return new OperatorImpl(Selector.GT, oper.getOperands()[0], oper.getOperands()[1]);
    default:
      return new OperatorImpl(Selector.NOT, tree);
    }
  }
862953
function isContextSensitive(node) {
            ts.Debug.assert(node.kind !== 147 /* MethodDeclaration */ || ts.isObjectLiteralMethod(node));
            switch (node.kind) {
                case 179 /* FunctionExpression */:
                case 180 /* ArrowFunction */:
                    return isContextSensitiveFunctionLikeDeclaration(node);
                case 171 /* ObjectLiteralExpression */:
                    return ts.forEach(node.properties, isContextSensitive);
                case 170 /* ArrayLiteralExpression */:
                    return ts.forEach(node.elements, isContextSensitive);
                case 188 /* ConditionalExpression */:
                    return isContextSensitive(node.whenTrue) ||
                        isContextSensitive(node.whenFalse);
                case 187 /* BinaryExpression */:
                    return node.operatorToken.kind === 52 /* BarBarToken */ &&
                        (isContextSensitive(node.left) || isContextSensitive(node.right));
                case 253 /* PropertyAssignment */:
                    return isContextSensitive(node.initializer);
                case 147 /* MethodDeclaration */:
                case 146 /* MethodSignature */:
                    return isContextSensitiveFunctionLikeDeclaration(node);
                case 178 /* ParenthesizedExpression */:
                    return isContextSensitive(node.expression);
            }
            return false;
        }
713057
def p_expression_lessthan(self, p):
        ''
        p[0] = LessThan(p[1], p[3], lineno=p.lineno(1))
        p.set_lineno(0, p.lineno(1))
245983
def _wrap_value_with_context(self, tokens: List[Token], start: int, end: int) -> Extraction:
        """"""
        return Extraction(' '.join([x.orth_ if isinstance(x, Token) else x for x in tokens[start:end]]),
                          self.name,
                          start_token=start,
                          end_token=end,
                          start_char=tokens[start].idx if isinstance(tokens[start], Token) else -1,
                          end_char=tokens[end - 1].idx + len(tokens[end - 1].orth_) if isinstance(tokens[end - 1],
                                                                                                  Token) else -1
                          )
350273
def simplify(self):
        
        if self.iscanonical:
            return self

        expr = self.cancel()
        if not isinstance(expr, self.__class__):
            return expr.simplify()

        if expr.args[0] in (self.TRUE, self.FALSE,):
            return expr.args[0].dual

        expr = self.__class__(expr.args[0].simplify())
        expr.iscanonical = True
        return expr
121066
def lower_unsupported_metafield_expressions(ir_blocks):
    """"""
    def visitor_fn(expression):
        """Visitor function raising exception for any unsupported metafield."""
        if not isinstance(expression, expressions.LocalField):
            return expression
        if expression.field_name not in constants.UNSUPPORTED_META_FIELDS:
            return expression
        raise NotImplementedError(
            u'Encountered unsupported metafield {} in LocalField {} during construction of '
            u'SQL query tree for IR blocks {}.'.format(
                constants.UNSUPPORTED_META_FIELDS[expression.field_name], expression, ir_blocks))

    new_ir_blocks = [
        block.visit_and_update_expressions(visitor_fn)
        for block in ir_blocks
    ]
    return new_ir_blocks