src/xmlpatterns/functions/qxslt20corefunctions.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qanyuri_p.h"
       
    43 #include "qcommonnamespaces_p.h"
       
    44 #include "qcommonsequencetypes_p.h"
       
    45 #include "qcurrentfn_p.h"
       
    46 #include "qdocumentfn_p.h"
       
    47 #include "qelementavailablefn_p.h"
       
    48 #include "qfunctionavailablefn_p.h"
       
    49 #include "qgenerateidfn_p.h"
       
    50 #include "qsystempropertyfn_p.h"
       
    51 #include "qtypeavailablefn_p.h"
       
    52 #include "qunparsedentitypublicidfn_p.h"
       
    53 #include "qunparsedentityurifn_p.h"
       
    54 #include "qunparsedtextavailablefn_p.h"
       
    55 #include "qunparsedtextfn_p.h"
       
    56 
       
    57 #include "qxslt20corefunctions_p.h"
       
    58 
       
    59 QT_BEGIN_NAMESPACE
       
    60 
       
    61 using namespace QPatternist;
       
    62 
       
    63 Expression::Ptr XSLT20CoreFunctions::retrieveExpression(const QXmlName lname,
       
    64                                                         const Expression::List &args,
       
    65                                                         const FunctionSignature::Ptr &sign) const
       
    66 {
       
    67     Q_ASSERT(sign);
       
    68 
       
    69     Expression::Ptr fn;
       
    70 #define testXSLTFN(ln, cname) else if(lname.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname())
       
    71 
       
    72     if(false) /* Dummy for the macro handling. Will be optimized away anyway. */
       
    73         return Expression::Ptr();
       
    74     /* Alphabetic order. */
       
    75     testXSLTFN(current,                     CurrentFN);
       
    76     testXSLTFN(document,                    DocumentFN);
       
    77     testXSLTFN(element_available,           ElementAvailableFN);
       
    78     testXSLTFN(function_available,          FunctionAvailableFN);
       
    79     testXSLTFN(generate_id,                 GenerateIDFN);
       
    80     testXSLTFN(system_property,             SystemPropertyFN);
       
    81     testXSLTFN(type_available,              TypeAvailableFN);
       
    82     testXSLTFN(unparsed_entity_public_id,   UnparsedEntityPublicIDFN);
       
    83     testXSLTFN(unparsed_entity_uri,         UnparsedEntityURIFN);
       
    84     testXSLTFN(unparsed_text_available,     UnparsedTextAvailableFN);
       
    85     testXSLTFN(unparsed_text,               UnparsedTextFN);
       
    86 #undef testXSLTFN
       
    87 
       
    88     Q_ASSERT(fn);
       
    89     fn->setOperands(args);
       
    90     fn->as<FunctionCall>()->setSignature(sign);
       
    91 
       
    92     return fn;
       
    93 }
       
    94 
       
    95 FunctionSignature::Ptr XSLT20CoreFunctions::retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name)
       
    96 {
       
    97     if(StandardNamespaces::fn != name.namespaceURI())
       
    98         return FunctionSignature::Ptr();
       
    99 
       
   100     FunctionSignature::Ptr s(functionSignatures().value(name));
       
   101 
       
   102     if(!s)
       
   103     {
       
   104         /* Alphabetic order. */
       
   105         if(name.localName() == StandardLocalNames::element_available)
       
   106         {
       
   107             s = addFunction(StandardLocalNames::element_available, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
       
   108             s->appendArgument(argument(np, "element-name"), CommonSequenceTypes::ExactlyOneString);
       
   109         }
       
   110         else if(name.localName() == StandardLocalNames::function_available)
       
   111         {
       
   112             s = addFunction(StandardLocalNames::function_available, 1, 2, CommonSequenceTypes::ExactlyOneBoolean);
       
   113             s->appendArgument(argument(np, "function_name"), CommonSequenceTypes::ExactlyOneString);
       
   114             s->appendArgument(argument(np, "arity"), CommonSequenceTypes::ExactlyOneInteger);
       
   115         }
       
   116         else if(name.localName() == StandardLocalNames::type_available)
       
   117         {
       
   118             s = addFunction(StandardLocalNames::type_available, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
       
   119             s->appendArgument(argument(np, "type_name"), CommonSequenceTypes::ExactlyOneString);
       
   120         }
       
   121         else if(name.localName() == StandardLocalNames::system_property)
       
   122         {
       
   123             s = addFunction(StandardLocalNames::system_property, 1, 1, CommonSequenceTypes::ExactlyOneString);
       
   124             s->appendArgument(argument(np, "property_name"), CommonSequenceTypes::ExactlyOneString);
       
   125         }
       
   126         else if(name.localName() == StandardLocalNames::generate_id)
       
   127         {
       
   128             s = addFunction(StandardLocalNames::generate_id, 0, 1, CommonSequenceTypes::ExactlyOneString,
       
   129                             Expression::UseContextItem);
       
   130             s->appendArgument(argument(np, "node"), CommonSequenceTypes::ZeroOrOneNode);
       
   131         }
       
   132         else if(name.localName() == StandardLocalNames::unparsed_text)
       
   133         {
       
   134             s = addFunction(StandardLocalNames::unparsed_text, 1, 2, CommonSequenceTypes::ZeroOrOneString,
       
   135                             Expression::DisableElimination);
       
   136             s->appendArgument(argument(np, "href"), CommonSequenceTypes::ZeroOrOneString);
       
   137             s->appendArgument(argument(np, "encoding"), CommonSequenceTypes::ExactlyOneString);
       
   138         }
       
   139         else if(name.localName() == StandardLocalNames::unparsed_text_available)
       
   140         {
       
   141             s = addFunction(StandardLocalNames::unparsed_text_available, 1, 2, CommonSequenceTypes::ExactlyOneBoolean,
       
   142                             Expression::DisableElimination);
       
   143             s->appendArgument(argument(np, "href"), CommonSequenceTypes::ZeroOrOneString);
       
   144             s->appendArgument(argument(np, "encoding"), CommonSequenceTypes::ZeroOrOneString);
       
   145         }
       
   146         else if(name.localName() == StandardLocalNames::current)
       
   147         {
       
   148             s = addFunction(StandardLocalNames::current, 0, 0, CommonSequenceTypes::ExactlyOneItem,
       
   149                             Expression::DisableElimination | Expression::RequiresCurrentItem);
       
   150         }
       
   151         else if(name.localName() == StandardLocalNames::document)
       
   152         {
       
   153             s = addFunction(StandardLocalNames::document, 1, 2, CommonSequenceTypes::OneOrMoreDocumentNodes,
       
   154                             Expression::DisableElimination);
       
   155             s->appendArgument(argument(np, "uri-sequence"), CommonSequenceTypes::ZeroOrMoreStrings);
       
   156             s->appendArgument(argument(np, "base-uri-node"), CommonSequenceTypes::ExactlyOneNode);
       
   157         }
       
   158         else if(name.localName() == StandardLocalNames::unparsed_entity_uri)
       
   159         {
       
   160             s = addFunction(StandardLocalNames::unparsed_entity_uri, 1, 1, CommonSequenceTypes::ExactlyOneAnyURI,
       
   161                             Expression::RequiresFocus | Expression::DisableElimination);
       
   162             s->appendArgument(argument(np, "entity-name"), CommonSequenceTypes::ExactlyOneString);
       
   163         }
       
   164         else if(name.localName() == StandardLocalNames::unparsed_entity_public_id)
       
   165         {
       
   166             s = addFunction(StandardLocalNames::unparsed_entity_public_id, 1, 1, CommonSequenceTypes::ExactlyOneString,
       
   167                             Expression::RequiresFocus | Expression::DisableElimination);
       
   168             s->appendArgument(argument(np, "entity-name"), CommonSequenceTypes::ExactlyOneString);
       
   169         }
       
   170     }
       
   171 
       
   172     return s;
       
   173 }
       
   174 
       
   175 QT_END_NAMESPACE