Matthias Brantner has proposed merging 
lp:~zorba-coders/zorba/deprecate-true_false_null into lp:zorba.

Commit message:
raise deprecated warning for true, false, null in xquery mode

Requested reviews:
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/deprecate-true_false_null/+merge/160980
-- 
https://code.launchpad.net/~zorba-coders/zorba/deprecate-true_false_null/+merge/160980
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h	2013-04-23 13:12:58 +0000
+++ include/zorba/pregenerated/diagnostic_list.h	2013-04-25 18:31:30 +0000
@@ -944,6 +944,8 @@
 
 extern ZORBA_DLL_PUBLIC ZorbaWarningCode ZWST0007_LOADER_PARSING_WARNING;
 
+extern ZORBA_DLL_PUBLIC ZorbaWarningCode ZWST0008_DEPRECATED;
+
 } // namespace zwarn
 } // namespace zorba
 #endif /* ZORBA_DIAGNOSTIC_LIST_API_H */

=== modified file 'modules/com/zorba-xquery/www/modules/pregenerated/warnings.xq'
--- modules/com/zorba-xquery/www/modules/pregenerated/warnings.xq	2013-03-06 00:18:36 +0000
+++ modules/com/zorba-xquery/www/modules/pregenerated/warnings.xq	2013-04-25 18:31:30 +0000
@@ -76,4 +76,8 @@
 
 (:~
 :)
-declare variable $zwarn:ZWST0007 as xs:QName := fn:QName($zwarn:NS, "zwarn:ZWST0007");
\ No newline at end of file
+declare variable $zwarn:ZWST0007 as xs:QName := fn:QName($zwarn:NS, "zwarn:ZWST0007");
+
+(:~
+:)
+declare variable $zwarn:ZWST0008 as xs:QName := fn:QName($zwarn:NS, "zwarn:ZWST0008");
\ No newline at end of file

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2013-04-24 03:54:58 +0000
+++ src/compiler/translator/translator.cpp	2013-04-25 18:31:30 +0000
@@ -9530,6 +9530,87 @@
 
   ParseConstants::pathtype_t pe_type = pe.get_type();
 
+  // terrible hack to allow for a standalone true, false or null to be
+  // interpreted as a boolean. User must use ./true, ./false or ./null for
+  // navigating XML elements named that way.
+#ifdef ZORBA_WITH_JSON
+  if (pe_type == ParseConstants::path_relative)
+  {
+    RelativePathExpr* lRootRelPathExpr =
+    dynamic_cast<RelativePathExpr*>(pe.get_relpath_expr().getp());
+
+    ContextItemExpr* lStepExpr =
+    dynamic_cast<ContextItemExpr*>(lRootRelPathExpr->get_step_expr());
+
+    AxisStep* lRelPathExpr =
+    dynamic_cast<AxisStep*>(lRootRelPathExpr->get_relpath_expr());
+
+    // Only rewrites if expression consists of a context item step on the left
+    // and of an axis step on the right,
+    // AND if this context item was set implicitly by the parser, meaning,
+    // the original expression was only an axis step.
+    if (lRelPathExpr && lStepExpr && lRootRelPathExpr->is_implicit())
+    {
+      ForwardStep* lFwdStep =
+      dynamic_cast<ForwardStep*>(lRelPathExpr->get_forward_step());
+
+      if (lFwdStep && lFwdStep->get_axis_kind() == ParseConstants::axis_child)
+      {
+        AbbrevForwardStep* lAbbrFwdStep =
+        dynamic_cast<AbbrevForwardStep*>(lFwdStep->get_abbrev_step());
+
+        if (lAbbrFwdStep)
+        {
+          const NameTest* lNodetest =
+          dynamic_cast<const NameTest*>(lAbbrFwdStep->get_node_test());
+
+          if (lNodetest)
+          {
+            const rchandle<QName> lQName = lNodetest->getQName();
+
+            if (lQName && lQName->get_prefix() == "")
+            {
+              const zstring& lLocal = lQName->get_localname();
+
+              bool lRet = false;
+
+              if (lLocal == "true")
+              {
+                push_nodestack(theExprManager->create_const_expr(theRootSctx, theUDF, loc, true));
+                lRet = true;
+              }
+              else if (lLocal == "false")
+              {
+                push_nodestack(theExprManager->create_const_expr(theRootSctx, theUDF, loc, false));
+                lRet = true;
+              }
+              else if (lLocal == "null")
+              {
+                store::Item_t lNull;
+                GENV_ITEMFACTORY->createJSONNull(lNull);
+                push_nodestack(theExprManager->create_const_expr(theRootSctx, theUDF, loc, lNull));
+                lRet = true;
+              }
+
+              if (lRet)
+              {
+                std::ostringstream lInstead;
+                lInstead << ((lLocal == "null")?"jn:":"fn:");
+                lInstead << lLocal << "()";
+                theCCB->theXQueryDiagnostics->add_warning(
+                  NEW_XQUERY_WARNING(zwarn::ZWST0008_DEPRECATED,
+                                     WARN_PARAMS(lLocal, lInstead.str()),
+                                     WARN_LOC(loc)));
+                return (void*)1;
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+#endif
+
   relpath_expr* pathExpr = NULL;
 
   // Put a NULL in the stack to mark the beginning of a PathExp tree.

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2013-04-23 13:12:58 +0000
+++ src/diagnostics/diagnostic_en.xml	2013-04-25 18:31:30 +0000
@@ -3350,6 +3350,10 @@
       <value>"$1":$2,$3: loader parsing warning${: 4}</value>
     </diagnostic>
 
+    <diagnostic code="ZWST0008" name="DEPRECATED">
+      <value>"$1": has been deprecated; use "$2" instead</value>
+    </diagnostic>
+
   </namespace>
 
   <!--////////// Subvalues /////////////////////////////////////////////////-->

=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp	2013-04-23 13:12:58 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp	2013-04-25 18:31:30 +0000
@@ -1389,6 +1389,9 @@
 ZorbaWarningCode ZWST0007_LOADER_PARSING_WARNING( "ZWST0007" );
 
 
+ZorbaWarningCode ZWST0008_DEPRECATED( "ZWST0008" );
+
+
 } // namespace zwarn
 
 } // namespace zorba

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2013-04-23 13:12:58 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2013-04-25 18:31:30 +0000
@@ -491,6 +491,7 @@
   { "ZWST0005", "\"$1\": function caching not possible; $2" },
   { "ZWST0006", "\"$1\": function caching might not give the intended result because the function is declared as $2" },
   { "ZWST0007", "\"$1\":$2,$3: loader parsing warning${: 4}" },
+  { "ZWST0008", "\"$1\": has been deprecated; use \"$2\" instead" },
   { "ZXQD0001", "\"$1\": prefix not declared when calling function \"$2\" from $3" },
   { "ZXQD0002", "\"$1\": $2" },
   { "ZXQD0003", "inconsistent options to the parse-xml() function: $1" },

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to