source: icXML/icXML-devel/src/xercesc/validators/common/CMBinaryOp.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.9 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: CMBinaryOp.cpp 677396 2008-07-16 19:36:20Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/util/XercesDefs.hpp>
27#include <xercesc/util/RuntimeException.hpp>
28#include <xercesc/validators/common/ContentSpecNode.hpp>
29#include <xercesc/validators/common/CMBinaryOp.hpp>
30#include <icxercesc/validators/common/CMStateSet.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34// ---------------------------------------------------------------------------
35//  CMBinaryOp: Constructors
36// ---------------------------------------------------------------------------
37CMBinaryOp::CMBinaryOp( ContentSpecNode::NodeTypes  type
38                        , CMNode* const             leftToAdopt
39                        , CMNode* const             rightToAdopt
40                        , unsigned int              maxStates
41                        , MemoryManager* const      manager) :
42    CMNode(type, maxStates, manager)
43    , fLeftChild(leftToAdopt)
44    , fRightChild(rightToAdopt)
45{
46    // Insure that its one of the types we require
47    if (((type & 0x0f) != ContentSpecNode::Choice)
48    &&  ((type & 0x0f) != ContentSpecNode::Sequence))
49    {
50        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::CM_BinOpHadUnaryType, manager);
51    }
52    //
53    //  If its an alternation, then if either child is nullable then
54    //  this node is nullable. If its a concatenation, then both of
55    //  them have to be nullable.
56    //
57    if ((type & 0x0f) == ContentSpecNode::Choice)
58        fIsNullable=(fLeftChild->isNullable() || fRightChild->isNullable());
59    else
60        fIsNullable=(fLeftChild->isNullable() && fRightChild->isNullable());
61}
62
63CMBinaryOp::~CMBinaryOp()
64{
65    delete fLeftChild;
66    delete fRightChild;
67}
68
69
70// ---------------------------------------------------------------------------
71//  CMBinaryOp: Getter methods
72// ---------------------------------------------------------------------------
73const CMNode* CMBinaryOp::getLeft() const
74{
75    return fLeftChild;
76}
77
78CMNode* CMBinaryOp::getLeft()
79{
80    return fLeftChild;
81}
82
83const CMNode* CMBinaryOp::getRight() const
84{
85    return fRightChild;
86}
87
88CMNode* CMBinaryOp::getRight()
89{
90    return fRightChild;
91}
92
93
94// ---------------------------------------------------------------------------
95//  CMBinaryOp: Implementation of the public CMNode virtual interface
96// ---------------------------------------------------------------------------
97void CMBinaryOp::orphanChild()
98{
99    delete fLeftChild;
100    fLeftChild=0;
101    delete fRightChild;
102    fRightChild=0;
103}
104
105// ---------------------------------------------------------------------------
106//  CMBinaryOp: Implementation of the protected CMNode virtual interface
107// ---------------------------------------------------------------------------
108void CMBinaryOp::calcFirstPos(CMStateSet& toSet) const
109{
110    if ((getType() & 0x0f) == ContentSpecNode::Choice)
111    {
112        // Its the the union of the first positions of our children.
113        toSet = fLeftChild->getFirstPos();
114        toSet |= fRightChild->getFirstPos();
115    }
116    else if ((getType() & 0x0f) == ContentSpecNode::Sequence)
117    {
118        //
119        //  If our left child is nullable, then its the union of our
120        //  children's first positions. Else is our left child's first
121        //  positions.
122        //
123        toSet = fLeftChild->getFirstPos();
124        if (fLeftChild->isNullable())
125            toSet |= fRightChild->getFirstPos();
126    }
127}
128
129void CMBinaryOp::calcLastPos(CMStateSet& toSet) const
130{
131    if ((getType() & 0x0f) == ContentSpecNode::Choice)
132    {
133        // Its the the union of the first positions of our children.
134        toSet = fLeftChild->getLastPos();
135        toSet |= fRightChild->getLastPos();
136    }
137    else if ((getType() & 0x0f) == ContentSpecNode::Sequence)
138    {
139        //
140        //  If our right child is nullable, then its the union of our
141        //  children's last positions. Else is our right child's last
142        //  positions.
143        //
144        toSet = fRightChild->getLastPos();
145        if (fRightChild->isNullable())
146            toSet |= fLeftChild->getLastPos();
147    }
148}
149
150XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.