1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// Copyright (c) 1994, 1996 James Clark
// See the file COPYING for copying permission.
#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "ContentState.h"
#include "IListIter.h"
#include "NCVector.h"
#include "macros.h"
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
const ShortReferenceMap ContentState::theEmptyMap;
#ifdef __GNUG__
typedef IListIter<OpenElement> Dummy_IListIter_OpenElement;
#endif
ContentState::ContentState()
: documentElementContainer_(StringC(), size_t(-1))
{
}
void ContentState::startContent(const Dtd &dtd)
{
NCVector<Owner<ContentToken> > tokens(1);
tokens[0] = new ElementToken(dtd.documentElementType(),
ContentToken::none);
Owner<ModelGroup> model(new SeqModelGroup(tokens, ContentToken::none));
Owner<CompiledModelGroup> compiledModel(new CompiledModelGroup(model));
Vector<ContentModelAmbiguity> ambiguities;
Boolean pcdataUnreachable;
compiledModel->compile(dtd.nElementTypeIndex(), ambiguities,
pcdataUnreachable);
ASSERT(ambiguities.size() == 0);
ConstPtr<ElementDefinition> def
= new ElementDefinition(Location(),
0,
0,
ElementDefinition::modelGroup,
compiledModel);
documentElementContainer_.setElementDefinition(def, 0);
tagLevel_ = 0;
while (!openElements_.empty())
delete openElements_.get();
openElements_.insert(new OpenElement(&documentElementContainer_,
0,
0,
&theEmptyMap,
Location()));
includeCount_.assign(dtd.nElementTypeIndex(), 0);
excludeCount_.assign(dtd.nElementTypeIndex(), 0);
openElementCount_.assign(dtd.nElementTypeIndex(), 0);
netEnablingCount_ = 0;
totalExcludeCount_ = 0;
lastEndedElementType_ = 0;
nextIndex_ = 0;
}
void ContentState::pushElement(OpenElement *e)
{
tagLevel_++;
openElementCount_[e->type()->index()]++;
const ElementDefinition *def = e->type()->definition();
if (def) {
size_t i;
for (i = 0; i < def->nInclusions(); i++)
includeCount_[def->inclusion(i)->index()]++;
for (i = 0; i < def->nExclusions(); i++) {
excludeCount_[def->exclusion(i)->index()]++;
totalExcludeCount_++;
}
}
if (e->netEnabling())
netEnablingCount_++;
e->setIndex(nextIndex_++);
openElements_.insert(e);
}
OpenElement *ContentState::popSaveElement()
{
ASSERT(tagLevel_ > 0);
OpenElement *e = openElements_.get();
tagLevel_--;
openElementCount_[e->type()->index()]--;
const ElementDefinition *def = e->type()->definition();
if (def) {
size_t i;
for (i = 0; i < def->nInclusions(); i++)
includeCount_[def->inclusion(i)->index()]--;
for (i = 0; i < def->nExclusions(); i++) {
excludeCount_[def->exclusion(i)->index()]--;
totalExcludeCount_--;
}
}
if (e->netEnabling())
netEnablingCount_--;
lastEndedElementType_ = e->type();
return e;
}
void ContentState::popElement()
{
delete popSaveElement();
}
Boolean ContentState::checkImplyLoop(unsigned count)
{
for (IListIter<OpenElement> iter(openElements_);
count > 0;
iter.next(), count--)
if (iter.cur()->type() == openElements_.head()->type()
// I'm not sure whether this is necessary.
&& iter.cur()->matchState() == openElements_.head()->matchState())
return 0;
return 1;
}
void ContentState::getOpenElementInfo(Vector<OpenElementInfo> &v,
const StringC &rniPcdata) const
{
v.clear();
v.resize(tagLevel_);
unsigned i = tagLevel_;
for (IListIter<OpenElement> iter(openElements_);
!iter.done() && i > 0;
iter.next()) {
OpenElementInfo &e = v[--i];
e.gi = iter.cur()->type()->name();
const LeafContentToken *token = iter.cur()->currentPosition();
if (token && !token->isInitial()) {
e.matchIndex = token->typeIndex() + 1;
const ElementType *type = token->elementType();
e.matchType = type ? type->name() : rniPcdata;
}
e.included = iter.cur()->included();
}
}
ElementType *
ContentState::lookupCreateUndefinedElement(const StringC &name,
const Location &loc,
Dtd &dtd,
Boolean allowImmediateRecursion)
{
ElementType *p = new ElementType(name,
dtd.allocElementTypeIndex());
dtd.insertElementType(p);
p->setElementDefinition(new ElementDefinition(loc,
size_t(ElementDefinition::undefinedIndex),
ElementDefinition::omitEnd,
ElementDefinition::any,
allowImmediateRecursion
),
0);
p->setAttributeDef(dtd.implicitElementAttributeDef());
includeCount_.push_back(0);
excludeCount_.push_back(0);
openElementCount_.push_back(0);
return p;
}
#ifdef SP_NAMESPACE
}
#endif
|