📄 contenttoken.cxx
字号:
} if (pcdataMinCovered > 0 || pcdataTransitionType_ == 0) pcdataUnreachable = 1; follow_.resize(j); andInfo_->follow.resize(j);}void ContentToken::analyze(GroupInfo &info, const AndModelGroup *andAncestor, unsigned andGroupIndex, FirstSet &first, LastSet &last){ analyze1(info, andAncestor, andGroupIndex, first, last); if (occurrenceIndicator_ & opt) inherentlyOptional_ = 1; if (inherentlyOptional_) first.setNotRequired(); if (occurrenceIndicator_ & plus) addTransitions(last, first, 0, andIndex(andAncestor), andDepth(andAncestor));}void LeafContentToken::analyze1(GroupInfo &info, const AndModelGroup *andAncestor, unsigned andGroupIndex, FirstSet &first, LastSet &last){ leafIndex_ = info.nextLeafIndex++; typeIndex_ = info.nextTypeIndex[element_ ? element_->index() : 0]++; if (andAncestor) { andInfo_ = new AndInfo; andInfo_->andAncestor = andAncestor; andInfo_->andGroupIndex = andGroupIndex; } first.init(this); last.assign(1, this); inherentlyOptional_ = 0;}void PcdataToken::analyze1(GroupInfo &info, const AndModelGroup *andAncestor, unsigned andGroupIndex, FirstSet &first, LastSet &last){ info.containsPcdata = 1; LeafContentToken::analyze1(info, andAncestor, andGroupIndex, first, last);}void OrModelGroup::analyze1(GroupInfo &info, const AndModelGroup *andAncestor, unsigned andGroupIndex, FirstSet &first, LastSet &last){ member(0).analyze(info, andAncestor, andGroupIndex, first, last); first.setNotRequired(); inherentlyOptional_ = member(0).inherentlyOptional(); for (unsigned i = 1; i < nMembers(); i++) { FirstSet tempFirst; LastSet tempLast; member(i).analyze(info, andAncestor, andGroupIndex, tempFirst, tempLast); first.append(tempFirst); first.setNotRequired(); last.append(tempLast); inherentlyOptional_ |= member(i).inherentlyOptional(); }}void SeqModelGroup::analyze1(GroupInfo &info, const AndModelGroup *andAncestor, unsigned andGroupIndex, FirstSet &first, LastSet &last){ member(0).analyze(info, andAncestor, andGroupIndex, first, last); inherentlyOptional_ = member(0).inherentlyOptional(); for (unsigned i = 1; i < nMembers(); i++) { FirstSet tempFirst; LastSet tempLast; member(i).analyze(info, andAncestor, andGroupIndex, tempFirst, tempLast); addTransitions(last, tempFirst, 1, andIndex(andAncestor), andDepth(andAncestor)); if (inherentlyOptional_) first.append(tempFirst); if (member(i).inherentlyOptional()) last.append(tempLast); else tempLast.swap(last); inherentlyOptional_ &= member(i).inherentlyOptional(); }}void AndModelGroup::analyze1(GroupInfo &info, const AndModelGroup *andAncestor, unsigned andGroupIndex, FirstSet &first, LastSet &last){ andDepth_ = ContentToken::andDepth(andAncestor); andIndex_ = ContentToken::andIndex(andAncestor); andAncestor_ = andAncestor; andGroupIndex_ = andGroupIndex; if (andIndex_ + nMembers() > info.andStateSize) info.andStateSize = andIndex_ + nMembers(); Vector<FirstSet> firstVec(nMembers()); Vector<LastSet> lastVec(nMembers()); member(0).analyze(info, this, 0, firstVec[0], lastVec[0]); first = firstVec[0]; first.setNotRequired(); last = lastVec[0]; inherentlyOptional_ = member(0).inherentlyOptional(); unsigned i; for (i = 1; i < nMembers(); i++) { member(i).analyze(info, this, i, firstVec[i], lastVec[i]); first.append(firstVec[i]); first.setNotRequired(); last.append(lastVec[i]); inherentlyOptional_ &= member(i).inherentlyOptional(); } for (i = 0; i < nMembers(); i++) { for (unsigned j = 0; j < nMembers(); j++) if (j != i) addTransitions(lastVec[i], firstVec[j], 0, andIndex() + nMembers(), andDepth() + 1, !member(j).inherentlyOptional(), andIndex() + j, andIndex() + i); }}void ContentToken::addTransitions(const LastSet &from, const FirstSet &to, Boolean maybeRequired, unsigned andClearIndex, unsigned andDepth, Boolean isolated, unsigned requireClear, unsigned toSet){ size_t length = from.size(); for (unsigned i = 0; i < length; i++) from[i]->addTransitions(to, maybeRequired, andClearIndex, andDepth, isolated, requireClear, toSet);}void LeafContentToken::addTransitions(const FirstSet &to, Boolean maybeRequired, unsigned andClearIndex, unsigned andDepth, Boolean isolated, unsigned requireClear, unsigned toSet){ if (maybeRequired && to.requiredIndex() != size_t(-1)) { ASSERT(requiredIndex_ == size_t(-1)); requiredIndex_ = to.requiredIndex() + follow_.size(); } size_t length = follow_.size(); size_t n = to.size(); follow_.resize(length + n); for (size_t i = 0; i < n; i++) follow_[length + i] = to.token(i); if (andInfo_) { andInfo_->follow.resize(length + n); for (size_t i = 0; i < n; i++) { Transition &t = andInfo_->follow[length + i]; t.clearAndStateStartIndex = andClearIndex; t.andDepth = andDepth; t.isolated = isolated; t.requireClear = requireClear; t.toSet = toSet; } }}AndState::AndState(unsigned n): v_(n, PackedBoolean(0)), clearFrom_(0){}void AndState::clearFrom1(unsigned i){ while (clearFrom_ > i) v_[--clearFrom_] = 0;}MatchState::MatchState(): andState_(0){}MatchState::MatchState(const CompiledModelGroup *model): pos_(model ? model->initial() : 0), andState_(model ? model->andStateSize() : 0), minAndDepth_(0){}const LeafContentToken *MatchState::invalidExclusion(const ElementType *e) const{ const LeafContentToken *token = pos_->transitionToken(e, andState_, minAndDepth_); if (token && !token->inherentlyOptional() && !token->orGroupMember()) return token; else return 0;}Boolean MatchState::operator==(const MatchState &state) const{ return (pos_ == state.pos_ && andState_ == state.andState_ && minAndDepth_ == state.minAndDepth_);}Boolean AndState::operator==(const AndState &state) const{ ASSERT(v_.size() == state.v_.size()); for (size_t i = 0; i < v_.size(); i++) { if (i >= clearFrom_ && i >= state.clearFrom_) break; if (v_[i] != state.v_[i]) return 0; } return 1;}const LeafContentToken *LeafContentToken::transitionToken(const ElementType *to, const AndState &andState, unsigned minAndDepth) const{ Vector<LeafContentToken *>::const_iterator p = follow_.begin(); if (!andInfo_) { for (size_t n = follow_.size(); n > 0; n--, p++) if ((*p)->elementType() == to) return *p; } else { Vector<Transition>::const_iterator q = andInfo_->follow.begin(); for (size_t n = follow_.size(); n > 0; n--, p++, q++) if ((*p)->elementType() == to && ((q->requireClear == unsigned(Transition::invalidIndex) || andState.isClear(q->requireClear)) && q->andDepth >= minAndDepth)) return (*p); } return 0;}BooleanLeafContentToken::tryTransition(const ElementType *to, AndState &andState, unsigned &minAndDepth, const LeafContentToken *&newpos) const{ Vector<LeafContentToken *>::const_iterator p = follow_.begin(); if (!andInfo_) { for (size_t n = follow_.size(); n > 0; n--, p++) { if ((*p)->elementType() == to) { newpos = *p; minAndDepth = newpos->computeMinAndDepth(andState); return 1; } } } else { Vector<Transition>::const_iterator q = andInfo_->follow.begin(); for (size_t n = follow_.size(); n > 0; n--, p++, q++) { if ((*p)->elementType() == to && ((q->requireClear == unsigned(Transition::invalidIndex) || andState.isClear(q->requireClear)) && q->andDepth >= minAndDepth)) { if (q->toSet != unsigned(Transition::invalidIndex)) andState.set(q->toSet); andState.clearFrom(q->clearAndStateStartIndex); newpos = *p; minAndDepth = newpos->computeMinAndDepth(andState); return 1; } } } return 0;}voidLeafContentToken::possibleTransitions(const AndState &andState, unsigned minAndDepth, Vector<const ElementType *> &v) const{ Vector<LeafContentToken *>::const_iterator p = follow_.begin(); if (!andInfo_) { for (size_t n = follow_.size(); n > 0; n--, p++) v.push_back((*p)->elementType()); } else { Vector<Transition>::const_iterator q = andInfo_->follow.begin(); for (size_t n = follow_.size(); n > 0; n--, p++, q++) if ((q->requireClear == unsigned(Transition::invalidIndex) || andState.isClear(q->requireClear)) && q->andDepth >= minAndDepth) v.push_back((*p)->elementType()); }}unsigned LeafContentToken::computeMinAndDepth1(const AndState &andState) const{ ASSERT(andInfo_ != 0); unsigned groupIndex = andInfo_->andGroupIndex; for (const AndModelGroup *group = andInfo_->andAncestor; group; groupIndex = group->andGroupIndex(), group = group->andAncestor()) for (unsigned i = 0; i < group->nMembers(); i++) if (i != groupIndex && !group->member(i).inherentlyOptional() && andState.isClear(group->andIndex() + i)) return group->andDepth() + 1; return 0;}const LeafContentToken *LeafContentToken::impliedStartTag(const AndState &andState, unsigned minAndDepth) const{ if (requiredIndex_ != size_t(-1)) { if (!andInfo_) return follow_[requiredIndex_]; const Transition &t = andInfo_->follow[requiredIndex_]; if ((t.requireClear == unsigned(Transition::invalidIndex) || andState.isClear(t.requireClear)) && t.andDepth >= minAndDepth) return follow_[requiredIndex_]; } return 0;}void LeafContentToken::doRequiredTransition(AndState &andState, unsigned &minAndDepth, const LeafContentToken *&newpos) const{ ASSERT(requiredIndex_ != size_t(-1)); if (andInfo_) { const Transition &t = andInfo_->follow[requiredIndex_]; if (t.toSet != unsigned(Transition::invalidIndex)) andState.set(t.toSet); andState.clearFrom(t.clearAndStateStartIndex); } newpos = follow_[requiredIndex_]; minAndDepth = newpos->computeMinAndDepth(andState);}FirstSet::FirstSet(): requiredIndex_(size_t(-1)){}void FirstSet::init(LeafContentToken *p){ v_.assign(1, p); v_.reserve(256); requiredIndex_ = 0;}void FirstSet::append(const FirstSet &set){ if (set.requiredIndex_ != size_t(-1)) { ASSERT(requiredIndex_ == size_t(-1)); requiredIndex_ = set.requiredIndex_ + v_.size(); } size_t oldSize = v_.size(); v_.resize(v_.size() + set.v_.size()); for (size_t i = 0; i < set.v_.size(); i++) v_[oldSize + i] = set.v_[i];}void LastSet::append(const LastSet &set){ size_t oldSize = size(); resize(size() + set.size()); for (size_t i = 0; i < set.size(); i++) (*this)[oldSize + i] = set[i];}#ifdef SP_NAMESPACE}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -