Ejemplo n.º 1
0
 public override void CalcFollowpos(BitSet[] followpos) {
   LeftChild.CalcFollowpos(followpos);
   int length = followpos.Length;        
   for (int i = length - 1; i >= 0; i--) {
     if (Lastpos.Get(i)) {
       followpos[i].Or(Firstpos);
     }
   }
 }
Ejemplo n.º 2
0
 public override bool CheckDeterministic(ValidationState context, NamedNode[] namedTerminals, out BitSet bitset, out SchemaNamespaceList wildcard) {
   BitSet lset = null, rset = null; bitset = null; wildcard = null; 
   SchemaNamespaceList lany = null, rany = null;
   if (!LeftChild.CheckDeterministic(context, namedTerminals, out lset, out lany))
     return false;
   if (!RightChild.CheckDeterministic(context, namedTerminals, out rset, out rany))
     return false;
   return Join(context, namedTerminals, lset, lany, rset, rany, out bitset, out wildcard);
 }
Ejemplo n.º 3
0
 public override void CalcFollowpos(BitSet[] followpos) {
   LeftChild.CalcFollowpos(followpos);
 }
Ejemplo n.º 4
0
    public override bool CheckDeterministic(ValidationState context, NamedNode[] namedTerminals, out BitSet bitset, out SchemaNamespaceList wildcard) {
      bitset = null; BitSet lset = null, rset = null; wildcard = null;
      SchemaNamespaceList lany = null, rany = null;
      if (!LeftChild.CheckDeterministic(context, namedTerminals, out lset, out lany))
        return false;
      if (!RightChild.CheckDeterministic(context, namedTerminals, out rset, out rany))
        return false;

      if (LeftChild.HasRange || LeftChild.IsNullable) {
        return Join(context, namedTerminals, lset, lany, rset, rany, out bitset, out wildcard);                            
      }
      else {
        bitset = lset;
        wildcard = lany;
      }
      return true;
    }
Ejemplo n.º 5
0
    public override void CalcFollowpos(BitSet[] followpos) {
      LeftChild.CalcFollowpos(followpos);
      RightChild.CalcFollowpos(followpos);

      int length = followpos.Length;        
      BitSet Lastpos = LeftChild.Lastpos;
      BitSet Firstpos = RightChild.Firstpos;        
      for (int i = length - 1; i >= 0; i--) {
        if (Lastpos[i]) {
          followpos[i].Or(Firstpos);
        }
      }
    }
Ejemplo n.º 6
0
 public void Or(BitSet other) {
   if (this == other) {
     return;
   }
   int setLength = other.bits.Length;
   EnsureLength(setLength);
   for (int i = setLength; i-- > 0 ;) {
     bits[i] |= other.bits[i];
   }
 }
Ejemplo n.º 7
0
 private bool CheckDeterministic(BitSet bitset, NamedNode[] namedTerminals, ValidationState context) {
   TrivialHashtable nodeTable = new TrivialHashtable();
   for (int i = 0; i < namedTerminals.Length; i++) {
     if (bitset[i]) {
       NamedNode node = namedTerminals[i];
       Identifier n = node.Name;
       if (n != Identifier.Empty) {
         if (nodeTable[n.UniqueKey] == null) {
           nodeTable[n.UniqueKey] = n;
         }
         else {
           Node offendingNode = (node.Member is Method) ? node.Name : node.Member.Name;
           context.HandleError(this.RootNode, offendingNode, Error.NonDeterministic, context.Name.ToString(), n.Name.ToString());
           return false;
         }
       }
     }
   }
   return true;
 }
Ejemplo n.º 8
0
 public override void ConstructPos(int terminalsCount) {
   Firstpos = new BitSet(terminalsCount);
   Lastpos = new BitSet(terminalsCount);
 }
Ejemplo n.º 9
0
 public override bool CheckDeterministic(ValidationState context, NamedNode[] namedTerminals, out BitSet bitset, out SchemaNamespaceList wildcard) {
   bitset = null;
   wildcard = this.wildcard;
   wildcard.AddType(this.TypeNode);
   return true;
 }
Ejemplo n.º 10
0
 public override void CalcFollowpos(BitSet[] followpos) {
 }
Ejemplo n.º 11
0
 public override bool CheckDeterministic(ValidationState context, NamedNode[] namedTerminals, out BitSet bitset, out SchemaNamespaceList wildcard) {
   bitset = Firstpos;
   wildcard = null;
   return true;
 }
Ejemplo n.º 12
0
 public abstract bool CheckDeterministic(ValidationState context, NamedNode[] namedTerminals, out BitSet bitset, out SchemaNamespaceList wildcard);
Ejemplo n.º 13
0
 public abstract void CalcFollowpos(BitSet[] followpos);
Ejemplo n.º 14
0
 public AllElementsContentValidator(Member mixed, int size, bool isEmptiable) : base(mixed == null ? XmlSchemaContentType.ElementOnly : XmlSchemaContentType.Mixed, mixed) {
   elements = new TrivialHashtable(size);
   isRequired = new BitSet(size);
   namedNodes = new ArrayList();
   this.isEmptiable = isEmptiable;
 }
Ejemplo n.º 15
0
 public override void CalcFollowpos(BitSet[] followpos) {
   // todo: error handling
   throw new Exception("Res.Xml_InternalError, string.Empty");
 }
Ejemplo n.º 16
0
 public override bool CheckDeterministic(ValidationState context, NamedNode[] namedTerminals, out BitSet bitset, out SchemaNamespaceList wildcard) {
   return LeftChild.CheckDeterministic(context, namedTerminals, out bitset, out wildcard);                            
 }
Ejemplo n.º 17
0
 public void And(BitSet other) {
   /*
          * Need to synchronize  both this and other->
          * This might lead to deadlock if one thread grabs them in one order
          * while another thread grabs them the other order.
          * Use a trick from Doug Lea's book on concurrency,
          * somewhat complicated because BitSet overrides hashCode().
          */
   if (this == other) {
     return;
   }
   int bitsLength = bits.Length;
   int setLength = other.bits.Length;
   int n = (bitsLength > setLength) ? setLength : bitsLength;
   for (int i = n ; i-- > 0 ;) {
     bits[i] &= other.bits[i];
   }
   for (; n < bitsLength ; n++) {
     bits[n] = 0;
   }
 }
Ejemplo n.º 18
0
    protected bool Join(ValidationState context, NamedNode[] namedTerminals, BitSet lset, SchemaNamespaceList lany, BitSet rset, SchemaNamespaceList rany, out BitSet bitset, out SchemaNamespaceList wildcard) {
      wildcard = null;
      if (lset != null) {
        if (rset != null) {
          bitset = lset.Clone();
          bitset.And(rset);
          if (!bitset.IsEmpty) {
            Identifier id = (context.Name == null) ? Identifier.Empty : context.Name;
            context.HandleError(this, id, Error.NonDeterministicAny, id.ToString());
            return false;
          }
          bitset.Or(lset);
          bitset.Or(rset);
        }
        else {
          bitset = lset;
        }
      }
      else {
        bitset = rset;                
      }

      if (lany != null) {
        if (rany != null) {
          SchemaNamespaceList list = SchemaNamespaceList.Intersection(rany, lany);
          if (list == null ||  list.IsEmpty()) { 
            wildcard = SchemaNamespaceList.Union(rany, lany);
          }                
          else {
            Identifier id = (context.Name == null) ? Identifier.Empty : context.Name;
            context.HandleError(this, id, Error.NonDeterministicAny, id.ToString());
            return false;
          }
        }
        else {
          wildcard = lany;
        }                        
      }
      else {
        wildcard = rany;     
      } 

      if (wildcard != null && bitset != null) {
        for (int i = 0; i < bitset.Count; i++) {
          NamedNode node = namedTerminals[i];
          if (bitset.Get(i) && wildcard.Allows(node)) {
            Identifier id = (context.Name == null ? node.Name : context.Name);
            context.HandleError(this, id, Error.NonDeterministicAny, id.ToString());
            return false;
          }
        }
      }
      return true;
    }
Ejemplo n.º 19
0
 public BitSet Clone() {
   BitSet newset = new BitSet();
   newset.count = count;
   newset.bits = (int[])bits.Clone();
   return newset;
 }
Ejemplo n.º 20
0
    internal CompiledParticleContentValidator(ValidationState context, InternalNode contentRoot, NamedNode[] namedTerminals, Hashtable symbols, int symCount, bool isOpen, XmlSchemaContentType contentType, Member mixed, NamedNode endMarker)  
      : base(contentType, namedTerminals, symbols, contentRoot, endMarker, symCount, mixed) {
      // keep these
      this.isOpen = isOpen;
      this.isEmptiable = contentRoot.LeftChild.IsNullable;

      int terminalsCount = namedTerminals.Length;
      int endMarkerPos = terminalsCount - 1; 

      // calculate followpos
      BitSet[] followpos = new BitSet[terminalsCount];
      for (int i = 0; i < terminalsCount; i++) {
        followpos[i] = new BitSet(terminalsCount);
      }
      contentRoot.CalcFollowpos(followpos);

      // transition table
      ArrayList transitionTable = new ArrayList();
            
      // state lookup table
      Hashtable stateTable = new Hashtable();

      // lists unmarked states
      ArrayList unmarked = new ArrayList();

      stateTable.Add(new BitSet(terminalsCount), -1); // add empty

      // start with firstpos at the root
      BitSet firstpos = contentRoot.Firstpos;
      stateTable.Add(firstpos, 0);
      unmarked.Add(firstpos);

      int[] a = new int[symbolCount + 1];
      transitionTable.Add(a);
      if (firstpos[endMarkerPos]) {
        a[symbolCount] = 1;   // accepting
      }

      // current state processed
      int state = 0;

      // check all unmarked states
      while (unmarked.Count > 0) {
        int[] t = (int[])transitionTable[state];

        firstpos = (BitSet)unmarked[0];
        if (!isNonDeterministic && !CheckDeterministic(firstpos, namedTerminals, context)) {
          isNonDeterministic = true;
        }
        unmarked.RemoveAt(0);

        // check all input symbols
        foreach (NamedNodeList list in symbols.Values){
          foreach (NamedNode node in list) {
            BitSet newset = new BitSet(terminalsCount);

            // if symbol is in the set add followpos to new set
            for (int i = 0; i < terminalsCount; i++) {
              if (firstpos[i] && node == namedTerminals[i]) {
                newset.Or(followpos[i]);
              }
            }

            object lookup = stateTable[newset];
            // this state will transition to
            int transitionTo;
            // if new set is not in states add it
            if (lookup == null) {
              transitionTo = stateTable.Count - 1;
              stateTable.Add(newset, transitionTo);
              unmarked.Add(newset);
              a = new int[symbolCount + 1];
              transitionTable.Add(a);
              if (newset[endMarkerPos]) {
                a[symbolCount] = 1;   // accepting
              }
            }
            else {
              transitionTo = (int)lookup;
            }
            // set the transition for the symbol
            t[node.Symbol] = transitionTo;
          }
        }
        state++;
      }
      // now convert transition table to array
      this.transitionTable = (int[][])transitionTable.ToArray(typeof(int[]));
    }