⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parserstate.cxx

📁 SP是一个基于GNU C++编译器
💻 CXX
📖 第 1 页 / 共 2 页
字号:
void ParserState::startInstance(){  if (!instanceSyntax_.isNull())    syntax_ = instanceSyntax_;  currentMode_ = econMode;  currentDtd_ = dtd_[0];  currentDtdConst_ = dtd_[0];  startContent(currentDtd());  inInstance_ = 1;  if (sd().rank())    currentRank_.assign(currentDtd().nRankStem(), StringC());  currentAttributes_.clear();  currentAttributes_.resize(currentDtd().nCurrentAttribute());  idTable_.clear();}Id *ParserState::lookupCreateId(const StringC &name){  Id *id = idTable_.lookup(name);  if (!id) {    id = new Id(name);    idTable_.insert(id);  }  return id;}ConstPtr<Entity>ParserState::lookupEntity(Boolean isParameter,			  const StringC &name,			  const Location &useLocation,			  Boolean referenced){  Dtd *dtd;  if (resultAttributeSpecMode_)    dtd = defComplexLpd().resultDtd().pointer();  else    dtd = currentDtd_.pointer();  if (dtd) {    Ptr<Entity> entity(dtd->lookupEntity(isParameter, name));    // Did we find it in pass1Dtd?    // Did we look at the defaultEntity?    if (!inInstance_ && pass2() && dtd->isBase()	&& !resultAttributeSpecMode_	&& (entity.isNull() || !entity->declInActiveLpd())) {      ConstPtr<Entity> entity1	= pass1Dtd_->lookupEntity(isParameter, name);      if (!entity1.isNull() && entity1->declInActiveLpd()	  && !entity1->defaulted()) {	if (referenced)	  noteReferencedEntity(entity1, 1, 0);	return entity1;      }      else if (!entity.isNull()) {	if (referenced)	  noteReferencedEntity(entity, 0, 0);	entity->setUsed();	return entity;      }    }    else if (!entity.isNull()) {      entity->setUsed();      return entity;    }    if (!isParameter) {      ConstPtr<Entity> entity(dtd->defaultEntity());      Boolean note = 0;      Boolean usedPass1 = 0;      if (!inInstance_ && pass2() && dtd->isBase()	  && !resultAttributeSpecMode_	  && (entity.isNull() || !entity->declInActiveLpd())) {	if (referenced)	  note = 1;	ConstPtr<Entity> entity1 = pass1Dtd_->defaultEntity();	if (!entity1.isNull() && entity1->declInActiveLpd()) {	  usedPass1 = 1;	  entity = entity1;	}      }      if (!entity.isNull()) {	Boolean mustCopy = 1;	if (inInstance_) {	  ConstPtr<Entity> tem 	    = instanceDefaultedEntityTable_.lookupConst(name);	  if (!tem.isNull()) {	    entity = tem;	    mustCopy = 0;	  }	}	if (mustCopy) {	  Ptr<Entity> p(entity->copy());	  p->setName(name);	  p->generateSystemId(*this);	  p->setDefaulted();	  entity = p;	  if (inInstance_) {	    instanceDefaultedEntityTable_.insert(p);	    eventHandler().entityDefaulted(new (eventAllocator())					   EntityDefaultedEvent(entity,								useLocation));	  }	  else	    dtd->insertEntity(p);	}	if (note)	  noteReferencedEntity(entity, usedPass1, 1);      }      else	entity = undefinedEntityTable_.lookupConst(name);      return entity;    }  }  return (Entity *)0;}ConstPtr<Entity> ParserState::createUndefinedEntity(const StringC &name, const Location &loc){  Text text;  Ptr<Entity> entity(new InternalCdataEntity(name, loc, text));  undefinedEntityTable_.insert(entity);  return entity;}void ParserState::noteReferencedEntity(const ConstPtr<Entity> &entity,				       Boolean foundInPass1Dtd,				       Boolean lookedAtDefault){  LpdEntityRef ref;  ref.entity = entity;  ref.lookedAtDefault = lookedAtDefault;  ref.foundInPass1Dtd = foundInPass1Dtd;  LpdEntityRef *old = lpdEntityRefs_.lookup(ref);  if (!old)    lpdEntityRefs_.insert(new LpdEntityRef(ref));}// Compare entity definitions.// e1 is the original (will not be an external non-text entity).// FIXME should look at generated sysids as well.staticBoolean sameEntityDef(const Entity *e1, const Entity *e2){  if (e1->dataType() != e2->dataType())    return 0;  const InternalEntity *i1 = e1->asInternalEntity();  const InternalEntity *i2 = e2->asInternalEntity();  if (i1) {    if (!i2)      return 0;    if (i1->string() != i2->string())      return 0;    return 1;  }  else if (i2)    return 0;  const ExternalEntity *x1 = e1->asExternalEntity();  const ExternalEntity *x2 = e2->asExternalEntity();  const StringC *s1 = x1->externalId().systemIdString();  const StringC *s2 = x2->externalId().systemIdString();  if (s1) {    if (!s2)      return 0;    if (*s1 != *s2)      return 0;  }  else if (s2)    return 0;  s1 = x1->externalId().publicIdString();  s2 = x2->externalId().publicIdString();  if (s1) {    if (!s2)      return 0;    if (*s1 != *s2)      return 0;  }  else if (s2)    return 0;  return 1;}void ParserState::checkEntityStability(){  LpdEntityRefSetIter iter(lpdEntityRefs_);  LpdEntityRef *ref;  while ((ref = iter.next()) != 0) {    ConstPtr<Entity> entity      = dtd_[0]->lookupEntity(ref->entity->declType()			      == Entity::parameterEntity,			      ref->entity->name());    if (entity.isNull() && ref->lookedAtDefault)      entity = dtd_[0]->defaultEntity();    if (entity.isNull()	? ref->foundInPass1Dtd	: !sameEntityDef(ref->entity.pointer(), entity.pointer()))      message(((ref->entity->declType()		== Entity::parameterEntity)	       ? ParserMessages::unstableLpdParameterEntity	       : ParserMessages::unstableLpdGeneralEntity),	      StringMessageArg(ref->entity->name()));  }  {    // Ensure that the memory is released.    LpdEntityRefSet tem;    lpdEntityRefs_.swap(tem);  }}    Boolean ParserState::appendCurrentRank(StringC &str, const RankStem *stem)     const{  const StringC &suffix = currentRank_[stem->index()];  if (suffix.size() > 0) {    str += suffix;    return 1;  }  return 0;}void ParserState::setCurrentRank(const RankStem *stem, const StringC &suffix){  currentRank_[stem->index()] = suffix;}void ParserState::getCurrentToken(const SubstTable<Char> *subst,				  StringC &str) const{  InputSource *in = currentInput();  const Char *p = in->currentTokenStart();  size_t count = in->currentTokenLength();  str.resize(count);  StringC::iterator s = str.begin();  for (; count > 0; --count)    *s++ = (*subst)[*p++];}void ParserState::queueMessage(MessageEvent *event){  if (cancelled()) {    delete event;    return;  }  if (keepingMessages_)    keptMessages_.append(event);  else    handler_->message(event);}void ParserState::releaseKeptMessages(){  keepingMessages_ = 0;  while (!keptMessages_.empty()) {    if (cancelled()) {      allDone();      return;    }    handler_->message(keptMessages_.get());  }}void ParserState::discardKeptMessages(){  keepingMessages_ = 0;  keptMessages_.clear();}void ParserState::initMessage(Message &msg){  if (inInstance()) {    StringC rniPcdata = syntax().delimGeneral(Syntax::dRNI);    rniPcdata += syntax().reservedName(Syntax::rPCDATA);    getOpenElementInfo(msg.openElementInfo, rniPcdata);  }  msg.loc = currentLocation();}void ParserState::dispatchMessage(Message &msg){  queueMessage(new MessageEvent(msg));}void ParserState::dispatchMessage(const Message &msg){  queueMessage(new MessageEvent(msg));}AttributeList *ParserState::allocAttributeList(const ConstPtr<AttributeDefinitionList> &def,				unsigned i){  if (i < attributeLists_.size())    attributeLists_[i]->init(def);  else {    attributeLists_.resize(i + 1);    attributeLists_[i] = new AttributeList(def);  }  return attributeLists_[i].pointer();}void ParserState::activateLinkType(const StringC &name){  if (!hadPass2Start_ && !pass2_)    activeLinkTypes_.push_back(name);  else    message(ParserMessages::linkActivateTooLate);}Boolean ParserState::shouldActivateLink(const StringC &name) const{  if (!activeLinkTypesSubsted_) {    // FIXME use mutable    ParserState *state = (ParserState *)this;    for (size_t i = 0; i < activeLinkTypes_.size(); i++)      for (size_t j = 0; j < activeLinkTypes_[i].size(); j++)	syntax().generalSubstTable()->subst(state->activeLinkTypes_[i][j]);    state->activeLinkTypesSubsted_ = 1;  }  for (size_t i = 0; i < activeLinkTypes_.size(); i++)    if (name == activeLinkTypes_[i])      return 1;  return 0;}Ptr<Dtd> ParserState::lookupDtd(const StringC &name){  for (size_t i = 0; i < dtd_.size(); i++)    if (dtd_[i]->name() == name)      return dtd_[i];  return Ptr<Dtd>();}ConstPtr<Lpd> ParserState::lookupLpd(const StringC &name) const{  for (size_t i = 0; i < allLpd_.size(); i++)    if (allLpd_[i]->name() == name)      return allLpd_[i];  return ConstPtr<Lpd>();}ConstPtr<Notation> ParserState::getAttributeNotation(const StringC &name,						     const Location &){  ConstPtr<Notation> notation;  if (haveCurrentDtd())    notation = currentDtd().lookupNotation(name);  else if (resultAttributeSpecMode_) {    const Dtd *resultDtd = defComplexLpd().resultDtd().pointer();    if (!resultDtd)      return 0;    notation = resultDtd->lookupNotation(name);  }  return notation; }ConstPtr<Entity> ParserState::getAttributeEntity(const StringC &str,						 const Location &loc){  ConstPtr<Entity> entity = lookupEntity(0, str, loc, 0);  if (!entity.isNull()      && entity->defaulted()      && options().warnDefaultEntityReference) {    setNextLocation(loc);    message(ParserMessages::defaultEntityInAttribute,	    StringMessageArg(str));  }  return entity;}Boolean ParserState::defineId(const StringC &str, const Location &loc,			      Location &prevLoc){  if (!inInstance() || !validate())    return 1;  Id *id = lookupCreateId(str);  if (id->defined()) {    prevLoc = id->defLocation();    return 0;  }  id->define(loc);  return 1;}void ParserState::noteIdref(const StringC &str, const Location &loc){  if (!inInstance() || !options().errorIdref || !validate())    return;  Id *id = lookupCreateId(str);  if (!id->defined())    id->addPendingRef(loc);}void ParserState::noteCurrentAttribute(size_t i, AttributeValue *value){  if (inInstance())    currentAttributes_[i] = value;}ConstPtr<AttributeValue> ParserState::getCurrentAttribute(size_t i) const{  if (!inInstance())    return ConstPtr<AttributeValue>();  return currentAttributes_[i];}const Syntax &ParserState::attributeSyntax() const{  return syntax();}#ifdef SP_NAMESPACE}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -