示例#1
0
static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  // Attribute can be applied only to functions or variables.
  FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
  if (!FD && !isa<VarDecl>(D)) {
    // Apparently Visual C++ thinks it is okay to not emit a warning
    // in this case, so only emit a warning when -fms-extensions is not
    // specified.
    if (!S.getLangOpts().MicrosoftExt)
      S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
        << Attr.getName() << 2 /*variable and function*/;
    return;
  }

  // Currently, the dllimport attribute is ignored for inlined functions.
  // Warning is emitted.
  if (FD && FD->isInlineSpecified()) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
    return;
  }

  unsigned Index = Attr.getAttributeSpellingListIndex();
  DLLImportAttr *NewAttr = S.mergeDLLImportAttr(D, Attr.getRange(), Index);
  if (NewAttr)
    D->addAttr(NewAttr);
}
示例#2
0
static void HandleMSP430InterruptAttr(Decl *d,
                                      const AttributeList &Attr, Sema &S) {
  if (Attr.getNumArgs() != 1) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
      << Attr.getName() << 1;
    return;
  }

  if (!Attr.isArgExpr(0)) {
    S.Diag(Attr.getLoc(), diag::err_attribute_argument_type) << Attr.getName()
      << AANT_ArgumentIntegerConstant;
    return;
  }

  // FIXME: Check for decl - it should be void ()(void).
  Expr *NumParamsExpr = Attr.getArgAsExpr(0);
  llvm::APSInt NumParams(32);
  if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context)) {
    S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
      << Attr.getName() << AANT_ArgumentIntegerConstant
      << NumParamsExpr->getSourceRange();
    return;
  }

  unsigned Num = NumParams.getLimitedValue(255);
  if ((Num & 1) || Num > 30) {
    S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds)
      << "interrupt" << (int)NumParams.getSExtValue()
      << NumParamsExpr->getSourceRange();
    return;
  }

  d->addAttr(::new (S.Context) MSP430InterruptAttr(Attr.getLoc(), S.Context, Num));
  d->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context));
}
void BulletMLParserXercesSAXHandler::startElement(const XMLCh* const name,
												  AttributeList& attributes)
{
	BulletMLNode* node = parser_->addContent(parser_->uc2string(name));

	if (node->getName() == BulletMLNode::bulletml) {
		for (unsigned int i = 0; i < attributes.getLength(); i++) {
			if (parser_->uc2string(attributes.getName(i)) == "type" &&
				parser_->uc2string(attributes.getValue(i)) == "horizontal")
			{
				parser_->setHorizontal();
			}
		}
	}
	else {
		BulletMLParserXerces::MyAttributes mattr;
		for (unsigned int i = 0; i < attributes.getLength(); i++) {
			mattr.push_back(parser_->uc2string(attributes.getName(i)));
			mattr.push_back(parser_->uc2string(attributes.getValue(i)));
		}
		parser_->addAttribute(mattr, node);
	}

	if (curNode_ != 0) curNode_->addChild(node);
	curNode_ = node;
}
/*
 * Stores the attributes from a name value type element.
 * Parse out the probe array type into its own member.
 */
void SAXArrayHandlers::StoreNameValueAttributes(AttributeList&  attributes)
{
	unsigned int len = attributes.getLength();
	AttributeNameValueType param;
	for (unsigned int index = 0; index < len; index++)
	{
		if (attributes.getName(index) == NAME_ATTRIBUTE)
		{
			param.name = XMLChToString(attributes.getValue(index));
		}
		else if (attributes.getName(index) == VALUE_ATTRIBUTE)
		{
			param.value = XMLChToString(attributes.getValue(index));
		}
		else if (attributes.getName(index) == TYPE_ATTRIBUTE)
		{
			param.type = XMLChToString(attributes.getValue(index));
			if (param.name == PROBE_ARRAY_TYPE_PARAMETER_NAME)
			{
				arrayData->SetArrayType(param.value);
			}
			else
			{
				arrayData->Attributes().push_back(param);
			}
		}
	}
}
static void HandleARMInterruptAttr(Decl *d,
                                   const AttributeList &Attr, Sema &S) {
  // Check the attribute arguments.
  if (Attr.getNumArgs() > 1) {
    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
      << Attr.getName() << 1;
    return;
  }

  StringRef Str;
  SourceLocation ArgLoc;

  if (Attr.getNumArgs() == 0)
    Str = "";
  else if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str, &ArgLoc))
    return;

  ARMInterruptAttr::InterruptType Kind;
  if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_type_not_supported)
        << Attr.getName() << Str << ArgLoc;
    return;
  }

  unsigned Index = Attr.getAttributeSpellingListIndex();
  d->addAttr(::new (S.Context)
             ARMInterruptAttr(Attr.getLoc(), S.Context, Kind, Index));
}
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  // check the attribute arguments.
  if (Attr.getNumArgs() != 0) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
      << Attr.getName() << 0;
    return;
  }

  // Attribute can be applied only to functions or variables.
  FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
  if (!FD && !isa<VarDecl>(D)) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
      << Attr.getName() << 2 /*variable and function*/;
    return;
  }

  // Currently, the dllexport attribute is ignored for inlined functions, unless
  // the -fkeep-inline-functions flag has been used. Warning is emitted;
  if (FD && FD->isInlineSpecified()) {
    // FIXME: ... unless the -fkeep-inline-functions flag has been used.
    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllexport";
    return;
  }

  unsigned Index = Attr.getAttributeSpellingListIndex();
  DLLExportAttr *NewAttr = S.mergeDLLExportAttr(D, Attr.getRange(), Index);
  if (NewAttr)
    D->addAttr(NewAttr);
}
static void HandleX86ForceAlignArgPointerAttr(Decl *D,
                                              const AttributeList& Attr,
                                              Sema &S) {
  // Check the attribute arguments.
  if (Attr.getNumArgs() != 0) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
      << Attr.getName() << 0;
    return;
  }

  // If we try to apply it to a function pointer, don't warn, but don't
  // do anything, either. It doesn't matter anyway, because there's nothing
  // special about calling a force_align_arg_pointer function.
  ValueDecl *VD = dyn_cast<ValueDecl>(D);
  if (VD && VD->getType()->isFunctionPointerType())
    return;
  // Also don't warn on function pointer typedefs.
  TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D);
  if (TD && (TD->getUnderlyingType()->isFunctionPointerType() ||
             TD->getUnderlyingType()->isFunctionType()))
    return;
  // Attribute can only be applied to function types.
  if (!isa<FunctionDecl>(D)) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
      << Attr.getName() << /* function */0;
    return;
  }

  D->addAttr(::new (S.Context) X86ForceAlignArgPointerAttr(Attr.getRange(),
                                                           S.Context));
}
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  // check the attribute arguments.
  if (Attr.getNumArgs() != 0) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
    return;
  }

  // Attribute can be applied only to functions or variables.
  if (isa<VarDecl>(D)) {
    D->addAttr(::new (S.Context) DLLExportAttr(Attr.getLoc(), S.Context));
    return;
  }

  FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
  if (!FD) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
      << Attr.getName() << 2 /*variable and function*/;
    return;
  }

  // Currently, the dllexport attribute is ignored for inlined functions, unless
  // the -fkeep-inline-functions flag has been used. Warning is emitted;
  if (FD->isInlineSpecified()) {
    // FIXME: ... unless the -fkeep-inline-functions flag has been used.
    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllexport";
    return;
  }

  D->addAttr(::new (S.Context) DLLExportAttr(Attr.getLoc(), S.Context));
}
void SAX_TransAGHandler::structuredMetaStart
(const XMLCh* const name, AttributeList& attr)
{
  string s;
  // if start-of-element is reported,
  // store structured element as XML string in feature value
  // and push structuredMetaEnd handler
  //  storeMetaValueStart(name, attr);
  if ( ! prevValue.empty() ) prevValue += " ";
  prevValue += "<";
  prevValue += set_string(s, name);
  for ( int i = 0; i < attr.getLength(); ++i ) {
    prevValue += " ";
    prevValue += set_string(s, attr.getName(i));
    prevValue += "=\"";
    prevValue += set_string(s, attr.getValue(i));
    prevValue += "\"";
  }

  prevValue += ">";
  prevPos = prevValue.length();

  StartStack.push(&SAX_TransAGHandler::structuredMetaStart);
  EndStack.push(&SAX_TransAGHandler::structuredMetaEnd);
}
void SAXPrintHandlers::startElement(const   XMLCh* const    name
                                    ,       AttributeList&  attributes)
{
    // The name has to be representable without any escapes
    fFormatter  << XMLFormatter::NoEscapes
                << chOpenAngle << name;

    unsigned int len = attributes.getLength();
    for (unsigned int index = 0; index < len; index++)
    {
        //
        //  Again the name has to be completely representable. But the
        //  attribute can have refs and requires the attribute style
        //  escaping.
        //
        fFormatter  << XMLFormatter::NoEscapes
                    << chSpace << attributes.getName(index)
                    << chEqual << chDoubleQuote
                    << XMLFormatter::AttrEscapes
		            << attributes.getValue(index)
                    << XMLFormatter::NoEscapes
                    << chDoubleQuote;
    }
    fFormatter << chCloseAngle;
}
示例#11
0
static void HandleMips16Attr(Decl *D, const AttributeList &Attr, Sema &S) {
  // check the attribute arguments.
  if (Attr.hasParameterOrArguments()) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
      << Attr.getName() << 0;
    return;
  }
  // Attribute can only be applied to function types.
  if (!isa<FunctionDecl>(D)) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_decl_type)
      << Attr.getName() << /* function */0;
    return;
  }
  D->addAttr(::new (S.Context) Mips16Attr(Attr.getRange(), S.Context,
                                          Attr.getAttributeSpellingListIndex()));
}
示例#12
0
 void startElement(const XMLCh* const name, AttributeList& attrList)
 {
   string label=XMLString::transcode(name);
   map<string,string> attrs;
   for (unsigned int i=0;i<attrList.getLength();i++)
     attrs[XMLString::transcode(attrList.getName(i))] = XMLString::transcode(attrList.getValue(i));
   myStream.onElement(label, attrs);
 }
void 
SBlogErrorMapper::MySAXHandler::startElement(const XMLCh* const name,
					     AttributeList& attributes)
{
  // 1. parse module name from the root
  XMLCh2VXIchar(name, tempString, 4096); 
  if(wcscmp(tempString, L"ErrorMessages") == 0)
  {
    for(unsigned int i = 0; i < attributes.getLength(); i++)
    {
      XMLCh2VXIchar(attributes.getName(i), tempString, 4096); 
      if(wcscmp(tempString, L"moduleName") == 0)
      {
        XMLCh2VXIchar(attributes.getValue(i), tempString, 4096);
        moduleName = tempString;
      }
    }
  }
  // 2. only care about <error> elements
  else if(wcscmp(tempString, L"error") == 0) {
    isProcessing = 1;
    errorMessage = L"";

    // Find the error number and severity (tag attributes)
    for (unsigned int i = 0; i < attributes.getLength(); i++) {
      XMLCh2VXIchar(attributes.getName(i), tempString, 4096); 
      if(wcscmp(tempString, L"num") == 0) {
        XMLCh2VXIchar(attributes.getValue(i), tempString, 4096); 
        errorNumber = wtoint(tempString);
      }
      else if(wcscmp(tempString, L"severity") == 0) {
        XMLCh2VXIchar(attributes.getValue(i), tempString, 4096); 
        errorSeverity = wtoint(tempString);
      }
    }
  }
  else if(wcscmp(tempString, L"advice") == 0) {
    // ignore the advice tag, just concate the advice's message    
  }
  else if(isProcessing)
    errorMessage += L"???"; // Runtime-determined value, unknown
}
/*
 * Stores the experiment name attribute from the experiment element.
 */
void SAXArrayHandlers::StoreExperimentNameAttribute(AttributeList&  attributes)
{
	unsigned int len = attributes.getLength();
	for (unsigned int index = 0; index < len; index++)
	{
		if (attributes.getName(index) == NAME_ATTRIBUTE)
		{
			arrayData->SetExperimentName(XMLChToString(attributes.getValue(index)));
			break;
		}
	}
}
示例#15
0
//
// startElement - our SAX handler callback function for startElement.
//                Update the document checksum with the element name
//                and any attribute names and values.
//
 void ThreadParser::SAXHandler::startElement(const XMLCh *const name, AttributeList &attributes)
{
    SAXInstance->addToCheckSum(name);
    XMLSize_t n = attributes.getLength();
    XMLSize_t i;
    for (i=0; i<n; i++)
    {
        const XMLCh *attNam = attributes.getName(i);
        SAXInstance->addToCheckSum(attNam);
        const XMLCh *attVal = attributes.getValue(i);
        SAXInstance->addToCheckSum(attVal);
    }
}
示例#16
0
void OptionsLoader::startElement(const XMLCh* const name,
                                 AttributeList& attributes) {
    myItem = TplConvert<XMLCh>::_2str(name);
    for (int i = 0; i < (int) attributes.getLength(); i++) {
        std::string key = TplConvert<XMLCh>::_2str(attributes.getName(i));
        std::string value = TplConvert<XMLCh>::_2str(attributes.getValue(i));
        if (key == "value" || key == "v") {
            key = myItem;
        }
        setValue(key, value);
    }
    myValue = "";
}
示例#17
0
static void HandleDLLExportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  // Currently, the dllexport attribute is ignored for inlined functions, unless
  // the -fkeep-inline-functions flag has been used. Warning is emitted;
  if (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isInlineSpecified()) {
    // FIXME: ... unless the -fkeep-inline-functions flag has been used.
    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
    return;
  }

  unsigned Index = Attr.getAttributeSpellingListIndex();
  DLLExportAttr *NewAttr = S.mergeDLLExportAttr(D, Attr.getRange(), Index);
  if (NewAttr)
    D->addAttr(NewAttr);
}
示例#18
0
static void HandleMBlazeSaveVolatilesAttr(Decl *d, const AttributeList &Attr,
                                          Sema &S) {
  // Check the attribute arguments.
  if (Attr.getNumArgs() != 0) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
      << Attr.getName() << 1;
    return;
  }

  // FIXME: Check for decl - it should be void ()(void).

  d->addAttr(::new (S.Context) MBlazeSaveVolatilesAttr(Attr.getLoc(),
                                                       S.Context));
  d->addAttr(::new (S.Context) UsedAttr(Attr.getLoc(), S.Context));
}
static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  // check the attribute arguments.
  if (Attr.getNumArgs() != 0) {
    S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
    return;
  }

  // Attribute can be applied only to functions or variables.
  if (isa<VarDecl>(D)) {
    D->addAttr(::new (S.Context) DLLImportAttr(Attr.getLoc(), S.Context));
    return;
  }

  FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
  if (!FD) {
    // Apparently Visual C++ thinks it is okay to not emit a warning
    // in this case, so only emit a warning when -fms-extensions is not
    // specified.
    if (!S.getLangOptions().Microsoft)
      S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
        << Attr.getName() << 2 /*variable and function*/;
    return;
  }

  // Currently, the dllimport attribute is ignored for inlined functions.
  // Warning is emitted.
  if (FD->isInlineSpecified()) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
    return;
  }

  // The attribute is also overridden by a subsequent declaration as dllexport.
  // Warning is emitted.
  for (AttributeList *nextAttr = Attr.getNext(); nextAttr;
       nextAttr = nextAttr->getNext()) {
    if (nextAttr->getKind() == AttributeList::AT_dllexport) {
      S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
      return;
    }
  }

  if (D->getAttr<DLLExportAttr>()) {
    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "dllimport";
    return;
  }

  D->addAttr(::new (S.Context) DLLImportAttr(Attr.getLoc(), S.Context));
}
/*
 * Stores the sample project attribute from the biosource/characteristics element.
 */
void SAXArrayHandlers::StoreSampleProjectAttribute(AttributeList&  attributes)
{
	unsigned int len = attributes.getLength();
	for (unsigned int index = 0; index < len; index++)
	{
		if (attributes.getName(index) == ONTOLOGY_VALUE_ATTRIBUTE)
		{
			AttributeNameValueType param;
			param.name = GCOS_SAMPLE_PROJECT_PARAMETER_NAME;
			param.value = XMLChToString(attributes.getValue(index));
			param.type = STRING_TYPE;
			arrayData->Attributes().push_back(param);
			break;
		}
	}
}
示例#21
0
    const std::string jsonize(AttributeList &attrs) {
        StringBuffer s;
        Writer<StringBuffer> w(s);

        w.StartObject();
        for (int i = 0; i < attrs.getLength(); ++i) {
            const XMLCh* name = attrs.getName(i);
            char *tmpName = XMLString::transcode(name),
                 *tmpValue = XMLString::transcode(attrs.getValue(name));
            w.String(tmpName);
            w.String(tmpValue);
            XMLString::release(&tmpName);
            XMLString::release(&tmpValue);
        }
        w.EndObject();

        return s.GetString();
    }
示例#22
0
string DictionaryHandler::findName( AttributeList& attributes )
{
	string str;
	XMLSize_t i = 0;
	XMLSize_t numAttributes = attributes.getLength();

	for ( i = 0; i < numAttributes; i++ ) {
		const XMLCh *xmlName = attributes.getName( i );
		char *name = XMLString::transcode( xmlName );
		if ( strncmp( name, "name", 5 ) == 0 ) {
			const XMLCh *xmlValue = attributes.getValue( i );
			char *value = XMLString::transcode( xmlValue );
			str = string( static_cast<const char *>( value ) );
			XMLString::release( &value );
		}
		XMLString::release( &name );
	}

	return str;
}
示例#23
0
void TestCasesHandler::startElement(const XMLCh* const name, AttributeList& attributes)
{
	Transcode attributeName;
	Transcode attributeType;
	Transcode attributeValue;
	Transcode message;

	try 
	{
		message.translate(name);		
		cout << "<" << message.getString() << ">" << endl;
		const string messageString(message.getChar());

		m_currentStartElement = createTagClass(messageString);
		m_tagStack.push(m_currentStartElement);
	}
	catch(nullString &)
	{

		//Do nothing	
		cout << "caught nullString on message.getChar()" << endl;
	}

	for(unsigned int i = 0; i < attributes.getLength(); i++)
	{
		try
		{
			attributeName.translate(attributes.getName(static_cast<unsigned int>(i)));
			cout << "Attribute name:" << attributeName.getString() << endl;

			attributeValue.translate(attributes.getValue(static_cast<unsigned int>(i)));
			cout << "Attribute Value:" + attributeValue.getString() << endl;
			m_currentStartElement->setAttribute(attributeName.getStringPimpl(), attributeValue.getStringPimpl());
		}
		catch(nullString &)
		{
			//Do nothing	
			cout << "caught nullString on attributeValue.getChar()" << endl;
		}
	}
}
    void FeatureDocumentHandler::startElement(const XMLCh* const name, AttributeList& attrs)
    {
        char elementName[1024];

        XMLString::transcode(name, elementName, 1024 - 1);
        std::string elemName(elementName);
        std::map<std::string, std::string> attributes;
        
        for (unsigned int c = 0; c < attrs.getLength() ; c++) 
        {
            char attributeName[1024];
            char attributeValue [1024];
            XMLString::transcode(attrs.getName(c), attributeName, 1024 - 1);
            XMLString::transcode(attrs.getValue(c), attributeValue, 1024 - 1);
            std::string attribName(attributeName);
            std::string attribVal(attributeValue);

            attributes.insert(Pair_Attrib(attribName, attribVal));
        }
        m_pFeatureMat->StartElement(elemName, attributes);
    }
示例#25
0
void UNIAlsCompileHandlers::startElement(const   XMLCh* const    name,
                                AttributeList&	attributes)
{
    unsigned int index = 0; 
    char *const target = 0; 
    unsigned int len;

    if (!strncmp("mapping", StrX(name).localForm(), 7))
    {
      mapcount++;

      len = attributes.getLength();
      for (index=0; index < len; index++)
      {
        /* get id */
        if (!strncmp("id", (StrX(attributes.getName(index))).localForm(), 2))
        {
	  XMLString::copyString(alMappingArray[mapindex].mapping_id, 
	       (StrX(attributes.getValue(index))).localForm());
        }
      }
    }
    else if (!strncmp("display", StrX(name).localForm(), 7))
    {
      /* get display name */
      len = attributes.getLength();
      for (index=0; index < len; index++)
      {
        /* get display name */
        if (!strncmp("name", (StrX(attributes.getName(index))).localForm(), 4))
        {
          XMLString::copyString(alMappingArray[mapindex].display_name,
               (StrX(attributes.getValue(index))).localForm());
        }
        /* get xml:lang */
        else if (!strncmp("xml:lang", 
		  (StrX(attributes.getName(index))).localForm(), 8))
        {
          XMLString::copyString(alMappingArray[mapindex].display_xmllang,
               (StrX(attributes.getValue(index))).localForm());
        }
      }
    }
    else if (!strncmp("alias", StrX(name).localForm(), 5))
    {
      aliascount++;
      /* get alias name */
      len = attributes.getLength();
      for (index=0; index < len; index++)
      {
        /* get display */
        if (!strncmp("name", 
		  (StrX(attributes.getName(index))).localForm(), 4))
        {
          XMLString::copyString(alAliasArray[aliasindex].aliasName,
                (StrX(attributes.getValue(index))).localForm());
        }
        /* get preferredBy information */
        else if (!strncmp("preferredBy", 
		  (StrX(attributes.getName(index))).localForm(), 11))
        {
          XMLString::copyString(alAliasArray[aliasindex].aliasPrefBy,
                (StrX(attributes.getValue(index))).localForm());
        }
        alAliasArray[aliasindex].aliasMapId = mapindex;
	  /* normalize the data and place in aliasNameNorm */
      }
      normalize(alAliasArray[aliasindex].aliasName, 
	  strlen(alAliasArray[aliasindex].aliasName), 
	  alAliasArray[aliasindex].aliasNameNorm);
    } 
}
示例#26
0
void SAX_TRSHandlers::saveElementFeatures(AttributeList& attr, map<string,string>& mapattr)
{
	for ( int i = 0; i < attr.getLength(); ++i )
		mapattr[trans(attr.getName(i))] = trans(attr.getValue(i)) ;
}
示例#27
0
void DocumentConverter::startElement(const XMLCh* const name,
                                     AttributeList & attrs)
{
  XMLChToVXIchar elementName(name);

  // (1) Convert name string to enum.
  int elemType;
  if (!ConvertElement(elementName.c_str(), elemType)) {
    vxistring temp(L"unrecognized element - ");
    temp += elementName.c_str();
    ParseException(temp.c_str());
  }

  // (2) Check for ignored nodes and do version number processing.

  // (2.1) Catch illegal nodes and do version number processing.
  switch (elemType) {
  case DEFAULTS_ROOT:
    version = 2.0f;
    break;
  case NODE_VXML:
  {
    for (unsigned int index = 0; index < attrs.getLength(); ++index) {
      if (!Compare(attrs.getName(index), L"version")) continue;
      const XMLCh * attributeValue = attrs.getValue(index);
      if (Compare(attributeValue, L"1.0")) version = 1.0f;
      else if (Compare(attributeValue, L"2.0")) version = 2.0f;
      else ParseException(L"illegal version");
      break;
    }
    break;
  }
  case PRIV_ELEM_DIV:
  case PRIV_ELEM_EMP:
  case PRIV_ELEM_PROS:
  case PRIV_ELEM_SAYAS:
    if (version != 1.0f) {
      vxistring temp(L"support for element '");
      temp += elementName.c_str();
      temp += L"' was dropped after VXML 1.0";
      ParseException(temp.c_str());
    }
    break;
  default:
    break;
  }

  // (2.2) Should we just ignore this node?
  if (IsIgnorable(elemType)) return;

  // (2.3) Convert nodes as necessary.
  switch (elemType) {
  case PRIV_ELEM_DIV: // Convert <div> into either <p> or <s>.
    if (attrs.getLength() == 1 && Compare(attrs.getName(0), L"paragraph"))
      elemType = NODE_PARAGRAPH;
    else
      elemType = NODE_SENTENCE;
    break;
  case PRIV_ELEM_EMP:
    elemType = NODE_EMPHASIS;
    break;
  case PRIV_ELEM_SAYAS:
  {
    elemType = NODE_SAYAS;

    for (unsigned int index = 0; index < attrs.getLength(); ++index)
      if (Compare(attrs.getName(index), L"phon")) {
        elemType = NODE_PHONEME;
        break;
    }
    break;
  }
  default:
    break;
  }

  // (3) Create new element.

  if (elemType > PRIV_ELEM_RangeStart) {
    vxistring temp(L"internal error for element - ");
    temp += elementName.c_str();
    ParseException(temp.c_str());
  }

  try {
    doc->StartElement(VXMLElementType(elemType));
  }
  catch (const VXMLDocumentModel::OutOfMemory &) {
    ParseException(L"unable to allocate memory for element");
  }
  catch (const VXMLDocumentModel::InternalError &) {
    ParseException(L"corrupted document tree; unable to add element");
  }

  // (4) Add attributes to element.
  for (unsigned int index = 0; index < attrs.getLength(); ++index) {
    int attrType;

    // (4.1) Convert string to integer.

    XMLChToVXIchar attributeName(attrs.getName(index));

    if (!ConvertAttribute(attributeName.c_str(), attrType)) {
      vxistring temp(L"unrecognized attribute - ");
      temp += attributeName.c_str();
      ParseException(temp.c_str());
    }

    // (4.2) Handle a few global settings.
    switch (attrType) {
    case PRIV_ATTRIB_CACHING:
      if (version != 1.0f)
        ParseException(L"the caching attribute was replaced by maxage and "
                       L"maxstale after VXML 1.0");

      if (Compare(attrs.getValue(index), L"safe")) {
        vxistring attr;
        if (!doc->GetAttribute(ATTRIBUTE_MAXAGE, attr))
          doc->AddAttribute(ATTRIBUTE_MAXAGE, L"0");
      }
      continue;

    default:
      break;
    }

    // (4.3) Handle internal values.
    XMLChToVXIchar attributeValue(attrs.getValue(index));
    ProcessNodeAttribute(VXMLElementType(elemType),
                         attrType, attributeValue.c_str());
  }

  // (5) Verify the node.
  ProcessNodeFinal(VXMLElementType(elemType));
}
示例#28
0
void UNIMapCompileHandlers::startElement(const   XMLCh* const    name,
                                AttributeList&	attributes)
{
    u_i2	len;
    i4		index;
    char	charbyte[12];
    char	ucode[10];
    char	ucode_sgt[5];
    char	ru[5];
    char	subchar[5];
    char	subchar1[5]; 
    char	*start;
    STATUS 	status;
    u_i4	byte_result;
    u_i4	uni_result;
    i4 		number = MAX_MAPPINGTBL_SIZE;
    ADU_MAP_HEADER	*map_header;
     u_i4 	sub, sub1;

    if ((buffer_size - (tptr - map_tbl)) < sizeof(ADU_MAP_ASSIGNMENT))
    {
      /* we have reached the threshold for the buffer increase the buffer size */
      char	*map_temp;
      i4	current_bytes = tptr - map_tbl;
		
      buffer_size += MAX_MAPPINGTBL_SIZE;
      buffer_size = (buffer_size + COL_BLOCK) & ~(COL_BLOCK-1);
        
      map_temp = (char *)MEreqmem(0, buffer_size, TRUE, &status);

      if ( status )
        cout<<"UNIMapCompile:ERROR:: Cannot allocate memory for mapping table"<<endl;

      MEcopy(map_tbl, current_bytes, map_temp);
      tptr = map_temp + current_bytes;
      tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

      /* free the old buffer */
      MEfree(map_tbl);

      map_tbl = map_temp;
      map_header = (ADU_MAP_HEADER *) map_tbl;
      validity_size_ptr = &map_header->validity_size;
      assignment_size_ptr = &map_header->assignment_size;
      subchar_ptr = &map_header->subchar;
      subchar1_ptr = &map_header->subchar1;
    }

    if (!strncmp("characterMapping", StrX(name).localForm(), 16))
    {
      len = attributes.getLength();
      map_header = (ADU_MAP_HEADER *)tptr;

      for (index=0; index < len; index++)
      {
        if (!strncmp("id",(StrX(attributes.getName(index))).localForm(), 2))
          XMLString::copyString(map_header->id,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("version",(StrX(attributes.getName(index))).localForm(), 7))
	XMLString::copyString(map_header->version,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("description",(StrX(attributes.getName(index))).localForm(), 11))
	XMLString::copyString(map_header->description,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("contact",(StrX(attributes.getName(index))).localForm(), 7))
	XMLString::copyString(map_header->contact,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("registrationAuthority",
	    (StrX(attributes.getName(index))).localForm(), 21))
	XMLString::copyString(map_header->registrationAuthority,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("registrationName",
	    (StrX(attributes.getName(index))).localForm(), 16))
	XMLString::copyString(map_header->registrationName,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("copyright",(StrX(attributes.getName(index))).localForm(), 9))
	XMLString::copyString(map_header->copyright,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("bidiOrder",(StrX(attributes.getName(index))).localForm(), 9))
        {
	XMLString::copyString (map_header->bidiOrder,
	    (char *)(StrX(attributes.getValue(index))).localForm());
        }
        else if (!strncmp("combiningOrder",(StrX(attributes.getName(index))).localForm(), 14))
        {
	XMLString::copyString(map_header->combiningOrder,
	    (char *)(StrX(attributes.getValue(index))).localForm());
        }
        else if (!strncmp("normalization",(StrX(attributes.getName(index))).localForm(), 13))
        {
	XMLString::copyString(map_header->normalization, 
	    (char *)(StrX(attributes.getValue(index))).localForm());
        }
      }

      validity_size_ptr = &map_header->validity_size;
      assignment_size_ptr = &map_header->assignment_size;
      subchar_ptr = &map_header->subchar;
      subchar1_ptr = &map_header->subchar1;

      tptr += sizeof(ADU_MAP_HEADER); 
      tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));
    }
    else if (!strncmp("state", StrX(name).localForm(), 5))
    {
      ADU_MAP_VALIDITY	map_validity;
      char 		state_start[3] = {' '};
      char		state_end[3] = {' '};
      char		state_max[5] = "FFFF";

      MEfill(sizeof(map_validity),0,&map_validity);
      len = attributes.getLength();
      for (index=0; index < len; index++)
      {
        if (!strncmp("type",(StrX(attributes.getName(index))).localForm(), 4))
	XMLString::copyString(map_validity.state_type,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("next",(StrX(attributes.getName(index))).localForm(), 4))
	XMLString::copyString(map_validity.state_next,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("s",(StrX(attributes.getName(index))).localForm(), 1))
	XMLString::copyString(state_start,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("e",(StrX(attributes.getName(index))).localForm(), 1))
	XMLString::copyString(state_end,
	    (StrX(attributes.getValue(index))).localForm());
        else if (!strncmp("max",(StrX(attributes.getName(index))).localForm(), 3))
	XMLString::copyString(state_max,
	    (StrX(attributes.getValue(index))).localForm());
      }

      status = CVahxl(state_start, &byte_result);
      if(status != OK)
      {
          cout<<"UNIMapCompile:ERROR:: Invalid validity state s= value "<<state_start<<" Status:"<<status<<"\n"<<endl;
      }
      map_validity.state_start = (u_i2)byte_result;

      status = CVahxl(state_end, &byte_result);
      if(status != OK)
      {
          cout<<"UNIMapCompile:ERROR:: Invalid validity state e= value "<<state_end<<" Status:"<<status<<"\n"<<endl;
      }
      map_validity.state_end = (u_i2)byte_result;

      status = CVahxl(state_max, &byte_result);
      if(status != OK)
      {
          cout<<"UNIMapCompile:ERROR:: Invalid validity state max= value "<<state_max<<" Status:"<<status<<"\n"<<endl;
      }
      map_validity.state_max = (u_i2)byte_result;

      tptr = ME_ALIGN_MACRO(tptr, sizeof(u_i2));
      start = tptr;
      MEcopy(&map_validity, sizeof(ADU_MAP_VALIDITY), tptr);
      tptr += sizeof(ADU_MAP_VALIDITY); 
      validity_cnt++;
      *validity_size_ptr += (SIZE_TYPE)(tptr - start);
    }
    else if (!strncmp("assignments", StrX(name).localForm(), 11))
    {
      if (align_validities == FALSE)
      {
        /* Align start of assignment section to PTR and update size */
        /* of validities section if padding is requried            */
        /* Only perform this alignment once.                       */
        start = tptr;
        tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));
        *validity_size_ptr += (SIZE_TYPE)(tptr - start);
        align_validities = TRUE;
      }
      len = attributes.getLength();
      for (index=0; index < len; index++)
      {
        if (!strncmp("sub",(StrX(attributes.getName(index))).localForm(), 3))
	{
          XMLString::copyString(subchar,
	      (StrX(attributes.getValue(index))).localForm());
	  STzapblank(subchar, subchar);
	  status = CVahxl (subchar, &sub);
	  if(status != OK)
	  {
              cout<<"UNIMapCompile:ERROR:: Invalid assignment sub= value "<<subchar<<" Status:"<<status<<"\n"<<endl;
	  }
	  *subchar_ptr = sub;
	}
        else if (!strncmp("sub1", (StrX(attributes.getName(index))).localForm(), 4))
	{
          XMLString::copyString(subchar1,
              (StrX(attributes.getValue(index))).localForm());
	  STzapblank(subchar1, subchar1);
	  status = CVahxl (subchar1, &sub1);
	  if(status != OK)
	  {
              cout<<"UNIMapCompile:ERROR:: Invalid assignment sub1= value "<<subchar1<<" Status:"<<status<<"\n"<<endl;
	  }
	  *subchar1_ptr = sub1;
	}
      }
    }
    else if (!strncmp("sub1", StrX(name).localForm(), 4))
    {
      /* FIX ME : Needs to be implemented */
    }	
    else if (!strncmp("a", StrX(name).localForm(), 5))
    {
        len = attributes.getLength();
        for (index=0; index < len; index++)
        {
          /* get b */
          if (!strncmp("b", 
		  (StrX(attributes.getName(index))).localForm(), 1))
          {
            XMLString::copyString(charbyte, 						
                      (StrX(attributes.getValue(index))).localForm());
	    STzapblank(charbyte, charbyte);
	    status = CVuahxl(charbyte, &byte_result);
	    if(status != OK)
	    {
                cout<<"UNIMapCompile:ERROR:: Invalid assignment byte value "<<charbyte<<" Status:"<<status<<"\n"<<endl;
	    }
          }
          /* get u */
          else if (!strncmp("u", 
		  (StrX(attributes.getName(index))).localForm(), 1))
          {
            XMLString::copyString(ucode,
                        (StrX(attributes.getValue(index))).localForm());
	    /* seperate the unicode values, separated by blanks */
	    STzapblank(ucode, ucode);
	    status = CVahxl (ucode, &uni_result);
	    if(status != OK)
	    {
                cout<<"UNIMapCompile:ERROR:: Invalid assignment unicode value "<<ucode<<" Status:"<<status<<"\n"<<endl;
	    }
          }
        }
        ADU_MAP_ASSIGNMENT map_assignment;
        map_assignment.bval = (u_i4) byte_result;
        map_assignment.uval = (u_i2) uni_result;
	map_assignment.uhsur = 0;

        tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));
        char *start = tptr;
        MEcopy(&map_assignment, sizeof(ADU_MAP_ASSIGNMENT), tptr);
        tptr += sizeof(ADU_MAP_ASSIGNMENT); 
        assignment_cnt++;
        *assignment_size_ptr += (SIZE_TYPE)(tptr - start);
    } /* assignments */
}