Example #1
0
 internal bool Eval(ASTQueries.NodePred pred, ChildContextKind context, int absPos, int relPos)
 {
     if (pred.PredicateKind == NodePredicateKind.Star)
     {
         return(true);
     }
     else if (pred.PredicateKind == NodePredicateKind.False)
     {
         return(false);
     }
     else if (pred.PredicateKind == NodePredicateKind.Atom)
     {
         return(EvalAtom((ASTQueries.NodePredAtom)pred, context, absPos, relPos));
     }
     else if (pred.PredicateKind == NodePredicateKind.Or)
     {
         var or = (ASTQueries.NodePredOr)pred;
         if (or.Arg1.PredicateKind == NodePredicateKind.Or)
         {
             return(Eval(or.Arg2, context, absPos, relPos) ||
                    Eval(or.Arg1, context, absPos, relPos));
         }
         else
         {
             return(Eval(or.Arg1, context, absPos, relPos) ||
                    Eval(or.Arg2, context, absPos, relPos));
         }
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Example #2
0
        /// <summary>
        /// Returns true if this node satisfies the atomic predicate.
        /// </summary>
        protected virtual bool EvalAtom(ASTQueries.NodePredAtom pred, ChildContextKind context, int absPos, int relPos)
        {
            if (pred.PredicateKind == NodePredicateKind.False ||
                (pred.TargetKind != NodeKind.AnyNodeKind && pred.TargetKind != NodeKind))
            {
                return(false);
            }

            if (pred.ChildContext != ChildContextKind.AnyChildContext && pred.ChildContext != context)
            {
                return(false);
            }

            if (pred.ChildContext == ChildContextKind.AnyChildContext &&
                (absPos < pred.ChildIndexLower || absPos > pred.ChildIndexUpper))
            {
                return(false);
            }

            if (pred.ChildContext != ChildContextKind.AnyChildContext &&
                (relPos < pred.ChildIndexLower || relPos > pred.ChildIndexUpper))
            {
                return(false);
            }

            return(true);
        }
Example #3
0
 internal ChildInfo(Node node, ChildContextKind context, int absPos, int relPos)
 {
     this.node    = node;
     this.context = context;
     this.absPos  = absPos;
     this.relPos  = relPos;
 }
Example #4
0
        protected override bool EvalAtom(ASTQueries.NodePredAtom pred, ChildContextKind context, int absPos, int relPos)
        {
            if (!base.EvalAtom(pred, context, absPos, relPos))
            {
                return(false);
            }

            return(pred.AttributePredicate == null ? true : pred.AttributePredicate(AttributeKind.Name, Name));
        }
Example #5
0
 public NodePredAtom MkPredicate(
     NodeKind targetKind,
     ChildContextKind childContext,
     int childIndexLower,
     int childIndexUpper,
     Func <AttributeKind, object, bool> attributePredicate)
 {
     Contract.Requires(childIndexLower <= childIndexUpper);
     return(new NodePredAtom(targetKind, childContext, childIndexLower, childIndexUpper, attributePredicate));
 }
Example #6
0
 internal NodePredAtom(
     NodeKind targetKind,
     ChildContextKind childContext,
     int childIndexLower,
     int childIndexUpper,
     Func <AttributeKind, object, bool> attributePredicate
     )
 {
     TargetKind         = targetKind;
     ChildContext       = childContext;
     ChildIndexLower    = childIndexLower;
     ChildIndexUpper    = childIndexUpper;
     AttributePredicate = attributePredicate;
 }
Example #7
0
        protected override bool EvalAtom(ASTQueries.NodePredAtom pred, ChildContextKind context, int absPos, int relPos)
        {
            if (!base.EvalAtom(pred, context, absPos, relPos))
            {
                return(false);
            }

            if (pred.AttributePredicate == null)
            {
                return(true);
            }

            return(pred.AttributePredicate(AttributeKind.Raw, Raw) &&
                   pred.AttributePredicate(AttributeKind.CnstKind, CnstKind));
        }
Example #8
0
 public NodePredAtom MkPredicate(ChildContextKind context)
 {
     return(new NodePredAtom(NodeKind.AnyNodeKind, context, -1, int.MaxValue, null));
 }