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

📄 parsedecl.cxx

📁 SP是一个基于GNU C++编译器
💻 CXX
📖 第 1 页 / 共 5 页
字号:
  }  return r;}Boolean Parser::parseExceptions(unsigned declInputLevel,				Ptr<ElementDefinition> &def){  Param parm;  static AllowedParams    allowExceptionsMdc(Param::mdc, Param::exclusions, Param::inclusions);  if (!parseParam(allowExceptionsMdc, declInputLevel, parm))    return 0;  if (parm.type == Param::exclusions) {    if (options().warnExclusion)      message(ParserMessages::exclusion);    def->setExclusions(parm.elementVector);    static AllowedParams allowInclusionsMdc(Param::mdc, Param::inclusions);    if (!parseParam(allowInclusionsMdc, declInputLevel, parm))      return 0;  }  if (parm.type == Param::inclusions) {    if (options().warnInclusion)      message(ParserMessages::inclusion);    def->setInclusions(parm.elementVector);    size_t nI = def->nInclusions();    size_t nE = def->nExclusions();    if (nE) {      for (size_t i = 0; i < nI; i++) {	const ElementType *e = def->inclusion(i);	for (size_t j = 0; j < nE; j++)	  if (def->exclusion(j) == e)	    message(ParserMessages::excludeIncludeSame,		    StringMessageArg(e->name()));      }    }    if (!parseParam(allowMdc, declInputLevel, parm))      return 0;  }  return 1;}Boolean Parser::parseAttlistDecl(){  unsigned declInputLevel = inputLevel();  Param parm;  size_t attcnt = 0;  size_t idIndex = size_t(-1);  size_t notationIndex = size_t(-1);  Boolean anyCurrent = 0;    Boolean isNotation;  Vector<Attributed *> attributed;  if (!parseAttributed(declInputLevel, parm, attributed, isNotation))    return 0;  Vector<CopyOwner<AttributeDefinition> > defs;  if (!parseParam(sd().www() ? allowNameMdc : allowName, declInputLevel, parm))    return 0;  while (parm.type != Param::mdc) {    StringC attributeName;    parm.token.swap(attributeName);    attcnt++;    Boolean duplicate = 0;    size_t i;    for (i = 0; i < defs.size(); i++)      if (defs[i]->name() == attributeName) {	message(ParserMessages::duplicateAttributeDef,		StringMessageArg(attributeName));	duplicate = 1;	break;      }    Owner<DeclaredValue> declaredValue;    if (!parseDeclaredValue(declInputLevel, isNotation, parm, declaredValue))      return 0;    if (!duplicate) {      if (declaredValue->isId()) {	if (idIndex != size_t(-1))	  message(ParserMessages::multipleIdAttributes,		  StringMessageArg(defs[idIndex]->name()));	idIndex = defs.size();      }      else if (declaredValue->isNotation()) {	if (notationIndex != size_t(-1))	  message(ParserMessages::multipleNotationAttributes,		  StringMessageArg(defs[notationIndex]->name()));	notationIndex = defs.size();      }    }    const Vector<StringC> *tokensPtr = declaredValue->getTokens();    if (tokensPtr) {      size_t nTokens = tokensPtr->size();      if (!sd().www()) {	Vector<StringC>::const_iterator tokens = tokensPtr->begin();	for (i = 0; i < nTokens; i++) {	  for (size_t j = 0; j < defs.size(); j++)	    if (defs[j]->containsToken(tokens[i])) {	      message(ParserMessages::duplicateAttributeToken,		      StringMessageArg(tokens[i]));	      break;	    }	}      }      attcnt += nTokens;    }    Owner<AttributeDefinition> def;    if (!parseDefaultValue(declInputLevel, isNotation, parm, attributeName,			   declaredValue, def, anyCurrent))      return 0;    if (haveDefLpd() && defLpd().type() == Lpd::simpleLink && !def->isFixed())      message(ParserMessages::simpleLinkFixedAttribute);    if (!duplicate) {      defs.resize(defs.size() + 1);      defs.back() = def.extract();    }    static AllowedParams allowNameMdc(Param::name, Param::mdc);    if (!parseParam(allowNameMdc, declInputLevel, parm))      return 0;  }  if (attcnt > syntax().attcnt())    message(ParserMessages::attcnt,	    NumberMessageArg(attcnt),	    NumberMessageArg(syntax().attcnt()));  if (haveDefLpd() && !isNotation) {    if (defLpd().type() == Lpd::simpleLink) {      for (size_t i = 0; i < attributed.size(); i++) {	const ElementType *e = (const ElementType *)attributed[i];	if (e) {	  if (e->name() == defLpd().sourceDtd()->name()) {	    SimpleLpd &lpd = (SimpleLpd &)defLpd();	    if (lpd.attributeDef().isNull())	      lpd.setAttributeDef(new AttributeDefinitionList(defs, 0));	    else	      message(ParserMessages::duplicateAttlistElement,		      StringMessageArg(e->name()));	  }	  else	    message(ParserMessages::simpleLinkAttlistElement,		    StringMessageArg(e->name()));	}      }    }    else {      Ptr<AttributeDefinitionList>	adl(new AttributeDefinitionList(defs,					defComplexLpd()					.allocAttributeDefinitionListIndex()));      for (size_t i = 0; i < attributed.size(); i++) {	const ElementType *e = (const ElementType *)attributed[i];	if (e) {	  if (defComplexLpd().attributeDef(e).isNull())	    defComplexLpd().setAttributeDef(e, adl);	  else	    message(ParserMessages::duplicateAttlistElement,		    StringMessageArg(e->name()));	}      }    }  }  else {    Ptr<AttributeDefinitionList>      adl(new AttributeDefinitionList(defs,				      defDtd()				      .allocAttributeDefinitionListIndex(),				      anyCurrent,				      idIndex,				      notationIndex));    for (size_t i = 0; i < attributed.size(); i++) {      if (attributed[i]->attributeDef().isNull()) {	attributed[i]->setAttributeDef(adl);	if (!isNotation) {	  ElementType *e = (ElementType *)attributed[i];	  if (e->definition() != 0)	    checkElementAttribute(e);	}      }      else if (options().errorAfdr && !sd().www()) {	if (isNotation)	  message(ParserMessages::duplicateAttlistNotation,		  StringMessageArg(((Notation *)attributed[i])->name()));	else	  message(ParserMessages::duplicateAttlistElement,		  StringMessageArg(((ElementType *)attributed[i])->name()));      }      else {	if (!hadAfdrDecl() && !sd().www()) {	  message(ParserMessages::missingAfdrDecl);	  setHadAfdrDecl();	}	AttributeDefinitionList *curAdl;	{	  // Use block to make sure temporary gets destroyed.	  curAdl = attributed[i]->attributeDef().pointer();	}	size_t oldSize = curAdl->size();	if (curAdl->count() != 1) {	  Vector<CopyOwner<AttributeDefinition> > copy(oldSize);	  for (size_t j = 0; j < oldSize; j++)	    copy[j] = curAdl->def(j)->copy();	  Ptr<AttributeDefinitionList> adlCopy	    = new AttributeDefinitionList(copy,					  defDtd().allocAttributeDefinitionListIndex(),					  curAdl->anyCurrent(),					  curAdl->idIndex(),					  curAdl->notationIndex());	  attributed[i]->setAttributeDef(adlCopy);	  curAdl = adlCopy.pointer();	}	// FIXME check for multiple ID and NOTATION attributes	for (size_t j = 0; j < adl->size(); j++) {	  unsigned tem;	  if (!curAdl->attributeIndex(adl->def(j)->name(), tem))	    curAdl->append(adl->def(j)->copy());	}	if (!isNotation) {	  ElementType *e = (ElementType *)attributed[i];	  if (e->definition() != 0)	    checkElementAttribute(e, oldSize);	}      }    }  }  if (currentMarkup()) {    if (isNotation) {      Vector<ConstPtr<Notation> > v(attributed.size());      for (size_t i = 0; i < attributed.size(); i++)	v[i] = (Notation *)attributed[i];      eventHandler()	.attlistNotationDecl(new (eventAllocator())			     AttlistNotationDeclEvent(v,						      markupLocation(),						      currentMarkup()));    }    else {      Vector<const ElementType *> v(attributed.size());      for (size_t i = 0; i < attributed.size(); i++)	v[i] = (ElementType *)attributed[i];      if (haveDefLpd())	eventHandler()	  .linkAttlistDecl(new (eventAllocator())			   LinkAttlistDeclEvent(v,						defLpdPointer(),						markupLocation(),						currentMarkup()));      else	eventHandler().attlistDecl(new (eventAllocator())				   AttlistDeclEvent(v,						    currentDtdPointer(),						    markupLocation(),						    currentMarkup()));    }  }  if (isNotation) {    Dtd::EntityIter entityIter(defDtd().generalEntityIter());    for (;;) {      Ptr<Entity> entity(entityIter.next());      if (entity.isNull())	break;      const ExternalDataEntity *external = entity->asExternalDataEntity();      if (external) {	const Notation *entityNotation = external->notation();	for (size_t  i = 0; i < attributed.size(); i++)	  if ((Notation *)attributed[i] == entityNotation) {	    AttributeList attributes(entityNotation->attributeDef());	    attributes.finish(*this);	    ((ExternalDataEntity *)entity.pointer())	      ->setNotation((Notation *)attributed[i], attributes);	  }      }    }  }  return 1;}Boolean Parser::parseAttributed(unsigned declInputLevel,				Param &parm,				Vector<Attributed *> &attributed,				Boolean &isNotation){  static AllowedParams    allowNameGroupNotation(Param::name,			   Param::nameGroup,			   Param::indicatedReservedName + Syntax::rNOTATION);  static AllowedParams    allowNameGroupNotationAll(Param::name,			      Param::nameGroup,			      Param::indicatedReservedName			      + Syntax::rNOTATION,			      Param::indicatedReservedName			      + Syntax::rALL,			      Param::indicatedReservedName			      + Syntax::rIMPLICIT);  if (!parseParam(haveDefLpd()		  ? allowNameGroupNotation		  : allowNameGroupNotationAll,		  declInputLevel, parm))    return 0;  if (parm.type == Param::indicatedReservedName + Syntax::rNOTATION) {    if (options().warnDataAttributes)      message(ParserMessages::dataAttributes);    isNotation = 1;    static AllowedParams      allowNameGroupAll(Param::name,			Param::nameGroup,			Param::indicatedReservedName + Syntax::rALL,			Param::indicatedReservedName + Syntax::rIMPLICIT);    if (!parseParam(haveDefLpd()		    ? allowNameNameGroup		    : allowNameGroupAll,		    declInputLevel, parm))      return 0;    if (parm.type == Param::nameGroup) {      attributed.resize(parm.nameTokenVector.size());      for (size_t i = 0; i < attributed.size(); i++)	attributed[i] = lookupCreateNotation(parm.nameTokenVector[i].name);    }    else {      if (parm.type != Param::name && !hadAfdrDecl() && !sd().www()) {	message(ParserMessages::missingAfdrDecl);	setHadAfdrDecl();      }      attributed.resize(1);      attributed[0]	= lookupCreateNotation(parm.type == Param::name			       ? parm.token			       : syntax().rniReservedName(Syntax::ReservedName(parm.type - Param::indicatedReservedName)));    }  }  else {    isNotation = 0;    if (parm.type == Param::nameGroup) {      if (options().warnAttlistGroupDecl)	message(ParserMessages::attlistGroupDecl);      attributed.resize(parm.nameTokenVector.size());      for (size_t i = 0; i < attributed.size(); i++)	attributed[i] = lookupCreateElement(parm.nameTokenVector[i].name);    }    else {      if (parm.type != Param::name && !hadAfdrDecl() && !sd().www()) {	message(ParserMessages::missingAfdrDecl);	setHadAfdrDecl();      }      attributed.resize(1);      attributed[0]	= lookupCreateElement(parm.type == Param::name			      ? parm.token			      : syntax().rniReservedName(Syntax::ReservedName(parm.type - Param::indicatedReservedName)));    }  }  return 1;}Boolean Parser::parseDeclaredValue(unsigned declInputLevel,				   Boolean isNotation,				   Param &parm,				   Owner<DeclaredValue> &declaredValue){  static Param::Type declaredValues[] = {    Param::reservedName + Syntax::rCDATA,    Param::reservedName + Syntax::rENTITY,    Param::reservedName + Syntax::rENTITIES,    Param::reservedName + Syntax::rID,    Param::reservedName + Syntax::rIDREF,    Param::reservedName + Syntax::rIDREFS,    Param::reservedName + Syntax::rNAME,    Param::reservedName + Syntax::rNAMES,    Param::reservedName + Syntax::rNMTOKEN,    Param::reservedName + Syntax::rNMTOKENS,    Param::reservedName + Syntax::rNUMBER,    Param::reservedName + Syntax::rNUMBERS,    Param::reservedName + Syntax::rNUTOKEN,    Param::reservedName + Syntax::rNUTOKENS,    Param::reservedName + Syntax::rNOTATION,    Param::nameTokenGroup    };  static AllowedParams allowDeclaredValue(declaredValues,					  SIZEOF(declaredValues));  if (!parseParam(allowDeclaredValue, declInputLevel, parm))    return 0;  enum { asDataAttribute = 01, asLinkAttribute = 02 };  unsigned allowedFlags = asDataAttribute|asLinkAttribute;  switch (parm.type) {  case Param::reservedName + Syntax::rCDATA:    declaredValue = new CdataDeclaredValue;    break;  case Param::reservedName + Syntax::rENTITY:    declaredValue = new EntityDeclaredValue(0);    allowedFlags = asLinkAttribute;    break;  case Param::reservedName + Syntax::rENTITIES:    declaredValue = new EntityDeclaredValue(1);    allowedFlags = asLinkAttribute;    break;  case Param::reservedName + Syntax::rID:    declaredValue = new IdDeclaredValue;    allowedFlags = 0;    break;  case Param::reservedName + Syntax::rIDREF:    declaredValue = new IdrefDeclaredValue(0);    allowedFlags = 0;    break;  case Param::reservedName + Syntax::rIDREFS:    declaredValue = new IdrefDeclaredValue(1);    allowedFlags = 0;    break;  case Param::reservedName + Syntax::rNAME:    declaredValue      = new TokenizedDeclaredValue(TokenizedDeclaredValue::name, 0);    if (options().warnNameDeclaredValue)      message(ParserMessages::nameDeclaredValue);    break;  case Param::reservedName + Syntax::rNAMES:    declaredValue      = new TokenizedDeclaredValue(TokenizedDeclaredValue::name, 1);    if (options().warnNameDeclaredValue)      message(ParserMessages::nameDeclaredValue);    break;  case Param::reservedName + Syntax::rNMTOKEN:    declaredValue      = new TokenizedDeclaredValue(TokenizedDeclaredValue::nameToken, 0);    break;  case Param::reservedName + Syntax::rNMTOKENS:    declaredValue      = new TokenizedDeclaredValue(TokenizedDeclaredValue::nameToken, 1);    break;

⌨️ 快捷键说明

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