Exemplo n.º 1
0
/***************************************************************
* Function: CodeParser::parseXMLText()
* Purpose : Helper function for parsing source code
* Initial : Maxime Chevalier-Boisvert on October 23, 2008
****************************************************************
Revisions and bug fixes: Nurudeen A. Lameed on May 5, 2009.
*/
CompUnits CodeParser::parseXMLText(const std::string& input)
{
	// Create an XML parser object
	XML::Parser parser;

	// Setup a try block to catch any errors
	try
	{
		// Parse the IR code string
		XML::Document xmlIR = parser.parseString(input);

		// If the verbose output flag is set
		if (ConfigManager::s_verboseVar.getBoolValue() == true)
		{
			//  Output the parsed XML
			std::cout << std::endl;
			std::cout << "Parsed XML: " << std::endl;
			std::cout << xmlIR.toString() << std::endl;
			std::cout << std::endl;
		}

		// Get a pointer to the XML tree root
		const XML::Element* pTreeRoot = xmlIR.getTree();

		// Parse the XML tree
		return parseXMLRoot(pTreeRoot);
	}

	// If XML parsing error occur
	catch (XML::ParseError error)
	{
		// Log the error
		std::cout << "ERROR: XML parsing failed " + error.toString() << std::endl;

		// Exit this function
		return CompUnits();
	}
}