• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KHTML

parsedstatement.cpp

Go to the documentation of this file.
00001 /*
00002  * parsedstatement.cc - Copyright 2005 Frerich Raabe <raabe@kde.org>
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00015  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00016  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00017  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00018  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00019  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00021  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00023  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 #include "parsedstatement.h"
00026 #include "path.h"
00027 
00028 #include "xml/dom_nodeimpl.h"
00029 #include "xml/dom_nodelistimpl.h"
00030 #include "xml/dom3_xpathimpl.h"
00031 
00032 using namespace DOM;
00033 
00034 namespace khtml {
00035 namespace XPath {
00036 
00037 Expression *khtmlParseXPathStatement( const DOMString &statement, int& ec );
00038 
00039 ParsedStatement::ParsedStatement( const DOMString &statement, khtml::XPathNSResolverImpl* res )
00040     : m_res( res ), m_expr( 0 ), m_ec( 0 ) 
00041 {
00042     parse( statement );
00043 }
00044 
00045 ParsedStatement::~ParsedStatement()
00046 {
00047     delete m_expr;
00048 }
00049 
00050 void ParsedStatement::parse( const DOMString &statement )
00051 {
00052     kDebug(6011) << "parsing:" << statement.string();
00053     m_ec = 0;
00054     delete m_expr;
00055     Expression::evaluationContext().reset( 0, m_res.get() );
00056     
00057     m_expr = khtmlParseXPathStatement( statement, m_ec );
00058     
00059     kDebug(6011) << "AST:" << (m_expr ? m_expr->dump() : QString::fromLatin1("*** parse error ***"));
00060 }
00061 
00062 void ParsedStatement::optimize()
00063 {
00064     if ( !m_expr ) {
00065         return;
00066     }
00067     m_expr->optimize();
00068 }
00069 
00070 Value ParsedStatement::evaluate(NodeImpl* context, int& ec) const
00071 {
00072     Expression::evaluationContext().reset(context, m_res.get());
00073     Value res = m_expr->evaluate();
00074     ec = Expression::evaluationContext().exceptionCode;
00075 
00076     // If the result is a nodeset, we need to put it in document order
00077     // and remove duplicates.
00078     if ( res.isNodeset() )
00079         res.toNodeset()->normalizeUpto(StaticNodeListImpl::DocumentOrder);
00080     return res;
00081 }
00082 
00083 QString ParsedStatement::dump() const
00084 {
00085     return m_expr->dump();
00086 }
00087 
00088 } // namespace XPath
00089 } // namespace khtml
00090 
00091 // kate: indent-width 4; replace-tabs off; tab-width 4; space-indent off;

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal