1 /*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "stdafx.h"
17
18 #include "compiler/parsetree/parsenode_print_xquery_visitor.h"
19
20 #include <ostream>
21 #include <string>
22 #include <map>
23 #include <stack>
24
25 #include "compiler/parsetree/parsenode_visitor.h"
26
27 #include "store/api/update_consts.h"
28
29 #include "diagnostics/assert.h"
30
31
32 #define DEFAULT_BEGIN_VISIT(type) \
33 void* begin_visit(const type&){ return no_state; }
34
35 #define DEFAULT_END_VISIT(type) \
36 void end_visit(const type&, void*){}
37
38 #define DEFAULT_VISIT(type) \
39 DEFAULT_BEGIN_VISIT(type) \
40 DEFAULT_END_VISIT(type) \
41
42 using namespace std;
43
44 namespace zorba {
45
46 class ParseNodePrintXQueryVisitor: public parsenode_visitor
47 {
48 private:
49 std::ostream& os;
50 FunctionIndex theFunctionIndex;
51
52 public:
53
ParseNodePrintXQueryVisitor(std::ostream & aStream)54 ParseNodePrintXQueryVisitor(std::ostream& aStream): os(aStream)
55 {
56 }
57
58
getFunctionIndex()59 FunctionIndex& getFunctionIndex()
60 {
61 return theFunctionIndex;
62 }
63
64
print(const parsenode * p)65 ParseNodePrintXQueryVisitor* print(const parsenode* p)
66 {
67 p->accept(*this);
68 return this;
69 }
70
71
begin_visit(const AbbrevForwardStep & n)72 void* begin_visit(const AbbrevForwardStep& n)
73 {
74 if(n.get_attr_bit())
75 {
76 os << '@';
77 }
78 return no_state;
79 }
80
81
82 DEFAULT_END_VISIT(AbbrevForwardStep)
83
DEFAULT_VISIT(AnnotationParsenode)84 DEFAULT_VISIT (AnnotationParsenode)
85
86 DEFAULT_VISIT (AnnotationListParsenode)
87
88 DEFAULT_VISIT (AnnotationLiteralListParsenode)
89
90 DEFAULT_BEGIN_VISIT (AnyKindTest)
91
92
93 void end_visit(const AnyKindTest& n, void* state)
94 {
95 os << "node()";
96 }
97
98
DEFAULT_VISIT(AposAttrContentList)99 DEFAULT_VISIT (AposAttrContentList)
100
101
102 void* begin_visit(const AposAttrValueContent& n)
103 {
104 if(!n.get_apos_atcontent().empty())
105 {
106 os << n.get_apos_atcontent();
107 }
108 else
109 {
110 n.get_common_content()->accept(*this);
111 }
112 return 0;
113 }
114
115
DEFAULT_END_VISIT(AposAttrValueContent)116 DEFAULT_END_VISIT (AposAttrValueContent)
117
118
119 void* begin_visit(const ArgList& n)
120 {
121 for (int i=0; i<(int)n.size(); ++i) {
122 if(i > 0)
123 {
124 os << ", ";
125 }
126 const exprnode* e_p = &*(n[i]);
127 e_p->accept(*this);
128 }
129 return 0;
130 }
131
132
133 DEFAULT_END_VISIT (ArgList)
134
DEFAULT_BEGIN_VISIT(AtomicType)135 DEFAULT_BEGIN_VISIT (AtomicType)
136
137
138 void end_visit(const AtomicType& n, void* state)
139 {
140 os << n.get_qname()->get_qname();
141 }
142
143
begin_visit(const AttributeTest & n)144 void* begin_visit(const AttributeTest& n)
145 {
146 os << "attribute(";
147 return no_state;
148 }
149
150
end_visit(const AttributeTest & n,void *)151 void end_visit(const AttributeTest& n, void*)
152 {
153 os << ")";
154 }
155
156
begin_visit(const BaseURIDecl & n)157 void* begin_visit(const BaseURIDecl& n)
158 {
159 os << "declare base-uri \"" << n.get_base_uri() << "\";";
160 return no_state;
161 }
162
163
164 DEFAULT_END_VISIT (BaseURIDecl);
165
166
begin_visit(const BoundarySpaceDecl & n)167 void* begin_visit(const BoundarySpaceDecl& n)
168 {
169 os << "declare boundary-space ";
170 switch(n.get_boundary_space_mode())
171 {
172 case StaticContextConsts::preserve_space:
173 os << "preserve";
174 break;
175 case StaticContextConsts::strip_space:
176 os << "strip";
177 break;
178 default:
179 ZORBA_ASSERT(false);
180 }
181 os << ';';
182 return no_state;
183 }
184
DEFAULT_END_VISIT(BoundarySpaceDecl)185 DEFAULT_END_VISIT (BoundarySpaceDecl)
186
187
188 void* begin_visit(const CaseClause& n)
189 {
190 os << "case ";
191 if(n.get_varname())
192 {
193 os << "$" << n.get_varname()->get_qname() << " as ";
194 }
195 n.get_type()->accept(*this);
196 os << "return ";
197 n.get_expr()->accept(*this);
198 return no_state;
199 }
200
201
202 DEFAULT_END_VISIT (CaseClause)
203
204
DEFAULT_VISIT(CaseClauseList)205 DEFAULT_VISIT (CaseClauseList) //@checked
206
207
208 void* begin_visit(const CommentTest& n)
209 {
210 os << "comment()";
211 return no_state;
212 }
213
214
215 DEFAULT_END_VISIT (CommentTest);
216
begin_visit(const ConstructionDecl & n)217 void* begin_visit(const ConstructionDecl& n)
218 {
219 os << "declare construction ";
220 switch(n.get_mode())
221 {
222 case StaticContextConsts::cons_preserve:
223 os << "preserve";
224 break;
225 case StaticContextConsts::cons_strip:
226 os << "strip";
227 break;
228 default:
229 ZORBA_ASSERT(false);
230 }
231 os << ';';
232 return no_state;
233 }
234
DEFAULT_END_VISIT(ConstructionDecl)235 DEFAULT_END_VISIT (ConstructionDecl)
236
237 void* begin_visit(const CopyNamespacesDecl& n)
238 {
239 os << "declare copy-namespaces ";
240
241 if (n.preserve_ns())
242 os << "preserve,";
243 else
244 os << "no-preserve,";
245
246 if (n.inherit_ns())
247 os << "inherit";
248 else
249 os << "no-inherit";
250
251 return 0;
252 }
253
DEFAULT_END_VISIT(CopyNamespacesDecl)254 DEFAULT_END_VISIT (CopyNamespacesDecl)
255
256 void* begin_visit(const DefaultCollationDecl& n)
257 {
258 os << "declare default collation " << n.get_collation();
259 return 0;
260 }
261
DEFAULT_END_VISIT(DefaultCollationDecl)262 DEFAULT_END_VISIT (DefaultCollationDecl)
263
264 void* begin_visit(const DefaultNamespaceDecl& n)
265 {
266 os << "declare default ";
267 switch(n.get_mode())
268 {
269 case ParseConstants::ns_element_default:
270 os << "element ";
271 break;
272 case ParseConstants::ns_function_default:
273 os << "function ";
274 break;
275 }
276 os << "namespace ";
277 os << n.get_default_namespace();
278 return 0;
279 }
280
DEFAULT_END_VISIT(DefaultNamespaceDecl)281 DEFAULT_END_VISIT (DefaultNamespaceDecl)
282
283 void* begin_visit(const DirAttr& n)
284 {
285 n.get_name()->accept(*this);
286 os << '=';
287 n.get_value()->accept(*this);
288 return 0;
289 }
290 DEFAULT_END_VISIT (DirAttr)
291
DEFAULT_VISIT(DirAttributeList)292 DEFAULT_VISIT (DirAttributeList) //@checked
293
294 void* begin_visit(const DirAttributeValue& n)
295 {
296 if(n.get_quot_attr_content())
297 {
298 os << '"';
299 n.get_quot_attr_content()->accept(*this);
300 os << '"';
301 } else {
302 os << '\'';
303 n.get_apos_attr_content()->accept(*this);
304 os << '\'';
305 }
306 return 0;
307 }
308 DEFAULT_END_VISIT (DirAttributeValue)
309
DEFAULT_VISIT(DirElemContentList)310 DEFAULT_VISIT (DirElemContentList) //@checked
311
312 void* begin_visit(const DocumentTest& n)
313 {
314 os << "document(";
315 return no_state;
316 }
end_visit(const DocumentTest & n,void *)317 void end_visit(const DocumentTest& n, void*)
318 {
319 os << ')';
320 }
321
begin_visit(const ElementTest & n)322 void* begin_visit(const ElementTest& n)
323 {
324 os << "element(";
325 if(n.isWildcard())
326 {
327 os << '*';
328 } else {
329 os << n.getElementName()->get_qname();
330 }
331 if(n.getTypeName() != 0)
332 {
333 os << "," << n.getTypeName()->get_name()->get_qname();
334 }
335 os << ")";
336 return no_state;
337 }
DEFAULT_END_VISIT(ElementTest)338 DEFAULT_END_VISIT (ElementTest)
339
340 void* begin_visit(const EmptyOrderDecl& n)
341 {
342 os << "declare default order empty ";
343 switch(n.get_mode())
344 {
345 case StaticContextConsts::empty_greatest:
346 os << "greatest";
347 break;
348 case StaticContextConsts::empty_least:
349 os << "least";
350 break;
351 default:
352 ZORBA_ASSERT(false);
353 }
354 return 0;
355 }
356
357
DEFAULT_END_VISIT(EmptyOrderDecl)358 DEFAULT_END_VISIT (EmptyOrderDecl)
359
360 void* begin_visit(const ForClause& n)
361 {
362 os << "for $";
363 n.get_vardecl_list()->accept(*this);
364 return 0;
365 }
366 DEFAULT_END_VISIT (ForClause)
367
DEFAULT_VISIT(FLWORClauseList)368 DEFAULT_VISIT (FLWORClauseList) //@checked
369
370
371 void* begin_visit(const ForwardAxis& n)
372 {
373 os << ParseConstants::decode_axis_kind(n.get_axis());
374 os << "::";
375 return no_state;
376 }
377
378 DEFAULT_END_VISIT (ForwardAxis)
379
380
DEFAULT_VISIT(ForwardStep)381 DEFAULT_VISIT (ForwardStep)//@checked
382
383
384 void* begin_visit(const FunctionDecl& n)
385 {
386 Parameters lParameters;
387 os << "declare ";
388
389 if (n.is_updating())
390 os << "updating ";
391
392 AnnotationListParsenode* lAnns = n.get_annotations();
393 if (lAnns) {
394
395 for (size_t i = 0; i < lAnns->size(); ++i)
396 {
397 AnnotationParsenode* lAnn = (*lAnns)[i];
398
399 AnnotationLiteralListParsenode* lLits = lAnn->get_literals().getp();
400
401 std::ostringstream lAttrValue;
402 if (lLits)
403 {
404 for (size_t j = 0; j < lLits->size(); ++j)
405 {
406 if (j > 0)
407 lAttrValue << " ";
408
409 exprnode* lLit = (*lLits)[j].getp();
410 Literal* l = static_cast<Literal*>(lLit);
411 if (l->get_type() == Literal::STRING_LITERAL)
412 {
413 StringLiteral* s = l->get_string_literal().getp();
414 lAttrValue << s->get_strval();
415 }
416 else
417 {
418 NumericLiteral* n = l->get_numeric_literal().getp();
419 lAttrValue << n->toString();
420 }
421 }
422 }
423
424 os << "%";
425 if(lAnn->get_qname()->is_eqname())
426 {
427 os << '"' << lAnn->get_qname()->get_namespace() << '"' << ":";
428 }
429 else
430 {
431 if(!lAnn->get_qname()->get_prefix().empty())
432 {
433 os << lAnn->get_qname()->get_prefix() << ":";
434 }
435 }
436 os << lAnn->get_qname()->get_localname();
437 if (!lAttrValue.str().empty())
438 {
439 os << "(" << lAttrValue.str() << ")";
440 }
441 os << " ";
442 }
443 }
444
445 os << "function ";
446
447 n.get_name()->accept(*this);
448
449 os << '(';
450 if(n.get_paramlist()) {
451 n.get_paramlist()->accept(*this);
452 }
453 os << ')';
454
455 if(n.get_return_type()) {
456 os << " as ";
457 stringstream lReturnType;
458 print_parsetree_xquery(lReturnType, n.get_return_type().getp());
459 //n.get_return_type()->accept(*this);
460 os << lReturnType.str();
461 lParameters.push(lReturnType.str());
462 }
463
464 if(n.get_body())
465 {
466 os << '{';
467 n.get_body()->accept(*this);
468 os << '}';
469 }
470 else if(n.is_external())
471 {
472 os << " external";
473 }
474
475 if(n.get_paramlist())
476 {
477 const rchandle<ParamList> paramList = n.get_paramlist();
478 for (vector<rchandle<Param> >::const_iterator it = paramList->begin();
479 it != paramList->end();
480 ++it)
481 {
482 const Param* param = &**it;
483 stringstream lParamString;
484 print_parsetree_xquery(lParamString, param);
485 lParameters.push(lParamString.str());
486 }
487 }
488 theFunctionIndex.insert(make_pair(n.get_name()->get_qname(), lParameters));
489 return 0;
490 }
491
492
DEFAULT_END_VISIT(FunctionDecl)493 DEFAULT_END_VISIT (FunctionDecl)
494
495
496 void* begin_visit(const GeneralComp& n)
497 {
498 switch(n.get_type())
499 {
500 case ParseConstants::op_eq:
501 os << '=';
502 break;
503 case ParseConstants::op_ne:
504 os << "!=";
505 break;
506 case ParseConstants::op_lt:
507 os << '<';
508 break;
509 case ParseConstants::op_le:
510 os << "<=";
511 break;
512 case ParseConstants::op_gt:
513 os << '>';
514 break;
515 case ParseConstants::op_ge:
516 os << ">=";
517 break;
518 }
519 return no_state;
520 }
521
DEFAULT_END_VISIT(GeneralComp)522 DEFAULT_END_VISIT (GeneralComp)
523
524
525 void* begin_visit(const ItemType& n)
526 {
527 os << "item()";
528 return no_state;
529 }
530
DEFAULT_END_VISIT(ItemType)531 DEFAULT_END_VISIT (ItemType)
532
533
534 void* begin_visit(const StructuredItemType& n)
535 {
536 os << "structured-item()";
537 return no_state;
538 }
539
DEFAULT_END_VISIT(StructuredItemType)540 DEFAULT_END_VISIT(StructuredItemType)
541
542
543 void* begin_visit(const LetClause& n)
544 {
545 os << "let ";
546 switch(n.for_or_let())
547 {
548 case ForOrLetClause::for_clause:
549 os << "score ";
550 break;
551 case ForOrLetClause::let_clause:
552 break;
553 }
554 return no_state;
555 }
556 DEFAULT_END_VISIT (LetClause)
557
DEFAULT_VISIT(LibraryModule)558 DEFAULT_VISIT (LibraryModule) //@checked
559
560 DEFAULT_VISIT (Literal)
561
562 DEFAULT_VISIT (MainModule) //@checked
563
564 void* begin_visit(const ModuleDecl& n)
565 {
566 os << "module namespace " << n.get_prefix() << "=" << n.get_target_namespace() << ';';
567 return 0;
568 }
DEFAULT_END_VISIT(ModuleDecl)569 DEFAULT_END_VISIT (ModuleDecl)
570
571
572 void* begin_visit(const ModuleImport& n)
573 {
574 os << "import module ";
575 if(!n.get_prefix().empty())
576 {
577 os << "namespace " << n.get_prefix() << '=';
578 }
579 os << n.get_uri();
580 if(n.get_at_list())
581 {
582 n.get_at_list()->accept(*this);
583 }
584 return 0;
585 }
DEFAULT_END_VISIT(ModuleImport)586 DEFAULT_END_VISIT (ModuleImport)
587
588
589 void* begin_visit(const NameTest& n)
590 {
591 if(n.getQName() != 0)
592 {
593 os << n.getQName()->get_qname();
594 } else {
595 n.getWildcard()->accept(*this);
596 }
597 return no_state;
598 }
599 DEFAULT_END_VISIT (NameTest)
600
DEFAULT_VISIT(NamespaceDecl)601 DEFAULT_VISIT (NamespaceDecl)
602
603 void* begin_visit(const NodeComp& n)
604 {
605 switch(n.get_type())
606 {
607 case ParseConstants::op_is:
608 os << "is";
609 break;
610 case ParseConstants::op_precedes:
611 os << "<<";
612 break;
613 case ParseConstants::op_follows:
614 os << ">>";
615 break;
616 }
617 return no_state;
618 }
DEFAULT_END_VISIT(NodeComp)619 DEFAULT_END_VISIT (NodeComp)
620
621 void* begin_visit(const OccurrenceIndicator& n)
622 {
623 switch(n.get_type())
624 {
625 case ParseConstants::occurs_never:
626 break;
627 case ParseConstants::occurs_exactly_one:
628 break;
629 case ParseConstants::occurs_optionally:
630 os << '?';
631 break;
632 case ParseConstants::occurs_zero_or_more:
633 os << '*';
634 break;
635 case ParseConstants::occurs_one_or_more:
636 os << '+';
637 break;
638 }
639 return no_state;
640 }
DEFAULT_END_VISIT(OccurrenceIndicator)641 DEFAULT_END_VISIT (OccurrenceIndicator)
642
643 void* begin_visit(const OptionDecl& n)
644 {
645 os << "declare option " << n.get_qname()->get_qname() << ' ' << n.get_val() << ';';
646 return 0;
647 }
DEFAULT_END_VISIT(OptionDecl)648 DEFAULT_END_VISIT (OptionDecl)
649
650 void* begin_visit(const GroupByClause& n)
651 {
652 os << "group by ";
653 return no_state;
654 }
DEFAULT_END_VISIT(GroupByClause)655 DEFAULT_END_VISIT (GroupByClause)
656
657 void* begin_visit(const GroupSpecList& n)
658 {
659 for (unsigned int i=0; i<n.size(); ++i)
660 {
661 const GroupSpec *e_p = &*n[i];
662 e_p->accept(*this);
663 }
664 return 0;
665 }
DEFAULT_END_VISIT(GroupSpecList)666 DEFAULT_END_VISIT (GroupSpecList)
667
668 void* begin_visit(const GroupSpec& n)
669 {
670 os << "$" << n.get_var_name();
671 n.get_collation_spec()->accept(*this);
672 return 0;
673 }
674 DEFAULT_END_VISIT (GroupSpec)
675
DEFAULT_VISIT(GroupCollationSpec)676 DEFAULT_VISIT (GroupCollationSpec)
677
678 void* begin_visit(const OrderByClause& n)
679 {
680 if(n.get_stable_bit())
681 {
682 os << "stable ";
683 }
684 os << "order by ";
685 n.get_spec_list()->accept(*this);
686 return 0;
687 }
DEFAULT_END_VISIT(OrderByClause)688 DEFAULT_END_VISIT (OrderByClause)
689
690 void* begin_visit(const OrderCollationSpec& n)
691 {
692 os << "collation " << n.get_uri();
693 return 0;
694 }
DEFAULT_END_VISIT(OrderCollationSpec)695 DEFAULT_END_VISIT (OrderCollationSpec)
696
697
698 void* begin_visit(const OrderDirSpec& n)
699 {
700 switch(n.getValue())
701 {
702 case ParseConstants::dir_ascending:
703 os << "ascending ";
704 break;
705 case ParseConstants::dir_descending:
706 os << "descending ";
707 break;
708 }
709 return 0;
710 }
DEFAULT_END_VISIT(OrderDirSpec)711 DEFAULT_END_VISIT (OrderDirSpec)
712
713
714 void* begin_visit(const OrderEmptySpec& n)
715 {
716 os << "empty ";
717 switch(n.getValue())
718 {
719 case StaticContextConsts::empty_greatest:
720 os << "greatest ";
721 break;
722 case StaticContextConsts::empty_least:
723 os << "least ";
724 break;
725 default:
726 ZORBA_ASSERT(false);
727 }
728 return 0;
729 }
730
731 DEFAULT_END_VISIT (OrderEmptySpec)
732
DEFAULT_VISIT(OrderModifierPN)733 DEFAULT_VISIT (OrderModifierPN)//@checked
734
735 DEFAULT_VISIT (OrderSpec) //@checked
736
737 void* begin_visit(const OrderSpecList& n)
738 {
739 for(unsigned int i=0; i<n.size(); i++)
740 {
741 if(i>0)
742 {
743 os << ',';
744 }
745 const parsenode *e_p = &*(n[i]);
746 e_p->accept(*this);
747 }
748 return 0;
749 }
DEFAULT_END_VISIT(OrderSpecList)750 DEFAULT_END_VISIT (OrderSpecList)
751
752 void* begin_visit(const PITest& n)
753 {
754 os << "processing-instruction(";
755 os << n.get_target();
756 os << ")";
757 return no_state;
758 }
759 DEFAULT_END_VISIT (PITest);
760
begin_visit(const OrderingModeDecl & n)761 void* begin_visit(const OrderingModeDecl& n)
762 {
763 os << "declare ordering";
764 switch(n.get_mode())
765 {
766 case StaticContextConsts::ordered:
767 os << "ordered ";
768 break;
769 case StaticContextConsts::unordered:
770 os << "unordered ";
771 break;
772 default:
773 ZORBA_ASSERT(false);
774 }
775 return 0;
776 }
777
778
DEFAULT_END_VISIT(OrderingModeDecl)779 DEFAULT_END_VISIT (OrderingModeDecl)
780
781
782 void* begin_visit(const Param& n)
783 {
784 os << '$';
785 os << n.get_name()->get_qname();
786
787 if(n.get_typedecl())
788 {
789 os << " as ";
790 }
791
792 return no_state;
793 }
794
795
DEFAULT_END_VISIT(Param)796 DEFAULT_END_VISIT (Param)
797
798
799
800 void* begin_visit(const ParamList& n)
801 {
802 for (vector<rchandle<Param> >::const_iterator it = n.begin();
803 it != n.end();
804 ++it)
805 {
806 if(it != n.begin())
807 {
808 os << ", ";
809 }
810 const parsenode *e_p = &**it;
811 if(e_p)
812 {
813 e_p->accept(*this);
814 }
815 }
816 return 0;
817 }
818
819
DEFAULT_END_VISIT(ParamList)820 DEFAULT_END_VISIT (ParamList)
821
822 void* begin_visit(const PositionalVar& n)
823 {
824 os << "at $" << n.get_name()->get_qname();
825 return 0;
826 }
DEFAULT_END_VISIT(PositionalVar)827 DEFAULT_END_VISIT (PositionalVar)
828
829 void* begin_visit(const Pragma& n)
830 {
831 os << "(#" << n.get_name()->get_qname() << ' ' << n.get_pragma_lit();
832 return 0;
833 }
834 DEFAULT_END_VISIT (Pragma)
835
DEFAULT_VISIT(PragmaList)836 DEFAULT_VISIT (PragmaList) //@checked
837 DEFAULT_VISIT (PredicateList)//@checked
838 DEFAULT_VISIT (Prolog)//@checked
839
840 void* begin_visit(const QVarInDecl& n)
841 {
842 os << n.get_name();
843 n.get_typedecl()->accept(*this);
844 os << " in ";
845 n.get_val()->accept(*this);
846 return 0;
847 }
DEFAULT_END_VISIT(QVarInDecl)848 DEFAULT_END_VISIT (QVarInDecl)
849
850 void* begin_visit(const QVarInDeclList& n)
851 {
852 for(int i=0; i<(int)n.size(); ++i)
853 {
854 if(i)
855 {
856 os << ',';
857 }
858 os << '$';
859 const QVarInDecl* node = &*n[i];
860 node->accept(*this);
861 }
862 return 0;
863 }
864 DEFAULT_END_VISIT (QVarInDeclList)
865
DEFAULT_VISIT(QuoteAttrValueContent)866 DEFAULT_VISIT (QuoteAttrValueContent)
867
868 DEFAULT_VISIT (QuoteAttrContentList)
869
870
871 void* begin_visit(const ReverseAxis& n)
872 {
873 os << ParseConstants::decode_axis_kind(n.get_axis());
874 os << "::";
875 return no_state;
876 }
877 DEFAULT_END_VISIT (ReverseAxis);
878
879
880 DEFAULT_VISIT (ReverseStep)
DEFAULT_VISIT(SIND_DeclList)881 DEFAULT_VISIT (SIND_DeclList)
882
883 void* begin_visit(const SchemaAttributeTest& n)
884 {
885 os << "schema-attribute(" << n.get_attr()->get_qname() << ")";
886 return 0;
887 }
888 DEFAULT_END_VISIT (SchemaAttributeTest);
889
begin_visit(const SchemaElementTest & n)890 void* begin_visit(const SchemaElementTest& n)
891 {
892 os << "schema-element(" << n.get_elem()->get_qname() << ")";
893 return 0;
894 }
DEFAULT_END_VISIT(SchemaElementTest)895 DEFAULT_END_VISIT (SchemaElementTest)
896
897 void* begin_visit(const SchemaPrefix& n)
898 {
899 if(n.get_default_bit())
900 {
901 os << "default element namespace ";
902 } else {
903 os << "namespace " << n.get_prefix() << '=';
904 }
905 return 0;
906 }
DEFAULT_END_VISIT(SchemaPrefix)907 DEFAULT_END_VISIT (SchemaPrefix)
908
909 void* begin_visit(const SchemaImport& n)
910 {
911 os << "import schema ";
912 if(n.get_prefix())
913 {
914 n.get_prefix()->accept(*this);;
915 }
916 os << n.get_uri() << " at ";
917 n.get_at_list()->accept(*this);
918 return 0;
919 }
DEFAULT_END_VISIT(SchemaImport)920 DEFAULT_END_VISIT (SchemaImport)
921
922 void* begin_visit(const SequenceType& n)
923 {
924 if(n.get_itemtype() == 0)
925 {
926 os << "empty-sequence()";
927 }
928 return no_state;
929 }
DEFAULT_END_VISIT(SequenceType)930 DEFAULT_END_VISIT (SequenceType)
931
932 void* begin_visit(const SignList& n)
933 {
934 if(n.get_sign())
935 {
936 os << '-';
937 } else {
938 os << '+';
939 }
940 return 0;
941 }
942 DEFAULT_END_VISIT (SignList)
943
DEFAULT_BEGIN_VISIT(SingleType)944 DEFAULT_BEGIN_VISIT (SingleType)
945 void end_visit(const SingleType& n, void*)
946 {
947 if(n.get_hook_bit())
948 {
949 os << '?';
950 }
951 }
952
begin_visit(const TextTest & n)953 void* begin_visit(const TextTest& n)
954 {
955 os << "text()";
956 return 0;
957 }
DEFAULT_END_VISIT(TextTest)958 DEFAULT_END_VISIT (TextTest)
959
960 void* begin_visit(const TypeName& n)
961 {
962 os << n.get_name()->get_qname();
963 return 0;
964 }
DEFAULT_END_VISIT(TypeName)965 DEFAULT_END_VISIT (TypeName)
966
967 void* begin_visit(const URILiteralList& n)
968 {
969 for(ulong i = 0; i < n.size(); i++)
970 {
971 if(i!=0)
972 {
973 os << ',';
974 }
975 os << n[i];
976 }
977 return 0;
978 }
DEFAULT_END_VISIT(URILiteralList)979 DEFAULT_END_VISIT (URILiteralList)
980
981 void* begin_visit(const ValueComp& n)
982 {
983 switch(n.get_type())
984 {
985 case ParseConstants::op_val_eq:
986 os << "eq";
987 break;
988 case ParseConstants::op_val_ne:
989 os << "ne";
990 break;
991 case ParseConstants::op_val_lt:
992 os << "lt";
993 break;
994 case ParseConstants::op_val_le:
995 os << "le";
996 break;
997 case ParseConstants::op_val_gt:
998 os << "gt";
999 break;
1000 case ParseConstants::op_val_ge:
1001 os << "ge";
1002 break;
1003 }
1004 return 0;
1005 }
DEFAULT_END_VISIT(ValueComp)1006 DEFAULT_END_VISIT (ValueComp)
1007
1008 void* begin_visit(const CtxItemDecl& n)
1009 {
1010 os << "declare context item ";
1011 if(n.get_type())
1012 {
1013 os << "as ";
1014 n.get_type()->accept(*this);
1015 }
1016 if(n.is_external())
1017 {
1018 os << "external ";
1019 }
1020 if(n.get_expr())
1021 {
1022 os << ":= ";
1023 n.get_expr()->accept(*this);
1024 }
1025 return 0;
1026 }
1027 DEFAULT_END_VISIT (CtxItemDecl);
1028
1029 DEFAULT_VISIT (CollectionDecl)
DEFAULT_VISIT(AST_IndexDecl)1030 DEFAULT_VISIT (AST_IndexDecl)
1031 DEFAULT_VISIT (IndexKeySpec)
1032 DEFAULT_VISIT (IndexKeyList)
1033 DEFAULT_VISIT (IntegrityConstraintDecl)
1034
1035 void* begin_visit(const GlobalVarDecl& n)
1036 {
1037 os << "declare variable $" << n.get_var_name()->get_qname();
1038
1039 if (n.get_var_type())
1040 {
1041 n.get_var_type()->accept(*this);
1042 }
1043
1044 if (n.is_extern())
1045 {
1046 os << "external";
1047 }
1048
1049 if (n.get_binding_expr())
1050 {
1051 os << ":=";
1052 n.get_binding_expr()->accept(*this);
1053 }
1054 return 0;
1055 }
1056
DEFAULT_END_VISIT(GlobalVarDecl)1057 DEFAULT_END_VISIT (GlobalVarDecl)
1058
1059 void* begin_visit(const LocalVarDecl& n)
1060 {
1061 os << "variable $" << n.get_var_name()->get_qname();
1062
1063 if (n.get_var_type())
1064 {
1065 n.get_var_type()->accept(*this);
1066 }
1067
1068 if (n.get_binding_expr())
1069 {
1070 os << ":=";
1071 n.get_binding_expr()->accept(*this);
1072 }
1073 return 0;
1074 }
1075
DEFAULT_END_VISIT(LocalVarDecl)1076 DEFAULT_END_VISIT (LocalVarDecl)
1077
1078
1079 void* begin_visit(const VarGetsDecl& n)
1080 {
1081 os << "$" << n.get_var_name()->get_qname() << " ";
1082 if(n.get_var_type())
1083 {
1084 os << "as ";
1085 n.get_var_type()->accept(*this);
1086 }
1087 if(n.get_binding_expr())
1088 {
1089 os << " := ";
1090 n.get_binding_expr()->accept(*this);
1091 }
1092 return 0;
1093 }
1094 DEFAULT_END_VISIT (VarGetsDecl);
1095
begin_visit(const VarGetsDeclList & n)1096 void* begin_visit(const VarGetsDeclList& n)
1097 {
1098 for(unsigned int i=0; i<n.size(); ++i)
1099 {
1100 if(i)
1101 {
1102 os << ", ";
1103 }
1104 const parsenode *e_p = &*(n[i]);
1105 e_p->accept(*this);
1106 }
1107 return 0;
1108 }
DEFAULT_END_VISIT(VarGetsDeclList)1109 DEFAULT_END_VISIT (VarGetsDeclList)
1110
1111 void* begin_visit(const VarInDecl& n)
1112 {
1113 os << n.get_var_name()->get_qname() << ' ';
1114 if(n.get_var_type())
1115 {
1116 os << "as ";
1117 n.get_var_type()->accept(*this);
1118 }
1119 if(n.get_posvar())
1120 {
1121 n.get_posvar()->accept(*this);
1122 }
1123 if(n.get_ftscorevar())
1124 {
1125 n.get_ftscorevar()->accept(*this);
1126 }
1127 os << "in ";
1128 n.get_binding_expr()->accept(*this);
1129 return 0;
1130 }
DEFAULT_END_VISIT(VarInDecl)1131 DEFAULT_END_VISIT (VarInDecl)
1132
1133 void* begin_visit(const VarInDeclList& n)
1134 {
1135 for(unsigned int i=0; i < n.size(); ++i)
1136 {
1137 if(i)
1138 {
1139 os << ", ";
1140 }
1141 os << '$';
1142 (&*(n[i]))->accept(*this);
1143 }
1144 return 0;
1145 }
DEFAULT_END_VISIT(VarInDeclList)1146 DEFAULT_END_VISIT (VarInDeclList)
1147
1148 void* begin_visit(const VersionDecl& n)
1149 {
1150 os << "xquery version" << n.get_version();
1151 if(!n.get_encoding().empty())
1152 {
1153 os << " encoding " << n.get_encoding();
1154 }
1155 os << ";";
1156 return 0;
1157 }
1158 DEFAULT_END_VISIT (VersionDecl)
1159
DEFAULT_VISIT(VFO_DeclList)1160 DEFAULT_VISIT (VFO_DeclList)
1161
1162 void* begin_visit(const WhereClause& n)
1163 {
1164 os << "where ";
1165 n.get_predicate()->accept(*this);
1166 return 0;
1167 }
DEFAULT_END_VISIT(WhereClause)1168 DEFAULT_END_VISIT (WhereClause)
1169
1170 void* begin_visit(const CountClause& n)
1171 {
1172 os << "count $" << n.get_varname();
1173 return 0;
1174 }
DEFAULT_END_VISIT(CountClause)1175 DEFAULT_END_VISIT (CountClause)
1176
1177 void* begin_visit(const Wildcard& n)
1178 {
1179 switch(n.getKind())
1180 {
1181 case ParseConstants::wild_all:
1182 os << '*';
1183 break;
1184 case ParseConstants::wild_elem:
1185 if (n.isEQnameMatch())
1186 os << "\"" << n.getNsOrPrefix() << "\":*";
1187 else
1188 os << n.getNsOrPrefix() << ":*";
1189 break;
1190 case ParseConstants::wild_prefix:
1191 os << "*:" << n.getLocalName();
1192 break;
1193 }
1194 return 0;
1195 }
DEFAULT_END_VISIT(Wildcard)1196 DEFAULT_END_VISIT (Wildcard)
1197
1198 void* begin_visit(const QName& n)
1199 {
1200 os << n.get_qname();
1201 return 0;
1202 }
1203 DEFAULT_END_VISIT (QName)
1204
1205 DEFAULT_VISIT (DecimalFormatNode);
1206
1207 /* expressions */
begin_visit(const AdditiveExpr & n)1208 void* begin_visit(const AdditiveExpr& n)
1209 {
1210 n.get_add_expr()->accept(*this);
1211 switch(n.get_add_op())
1212 {
1213 case ParseConstants::op_plus:
1214 os << '+';
1215 break;
1216 case ParseConstants::op_minus:
1217 os << '-';
1218 break;
1219 }
1220 n.get_mult_expr()->accept(*this);
1221 return 0;
1222 }
DEFAULT_END_VISIT(AdditiveExpr)1223 DEFAULT_END_VISIT (AdditiveExpr)
1224
1225 void* begin_visit(const AndExpr& n)
1226 {
1227 n.get_and_expr()->accept(*this);
1228 os << " and ";
1229 n.get_comp_expr();
1230 return 0;
1231 }
1232 DEFAULT_END_VISIT (AndExpr)
1233
DEFAULT_VISIT(AxisStep)1234 DEFAULT_VISIT (AxisStep)
1235
1236 void* begin_visit(const CDataSection& n)
1237 {
1238 os << "<![CDATA[" << n.get_cdata_content() << "]]>";
1239 return 0;
1240 }
DEFAULT_END_VISIT(CDataSection)1241 DEFAULT_END_VISIT (CDataSection)
1242
1243 void* begin_visit(const CastExpr& n)
1244 {
1245 n.get_unary_expr()->accept(*this);
1246 if(n.get_singletype())
1247 {
1248 os << " cast as ";
1249 }
1250 n.get_singletype()->accept(*this);
1251 return 0;
1252 }
DEFAULT_END_VISIT(CastExpr)1253 DEFAULT_END_VISIT (CastExpr)
1254
1255 void* begin_visit(const CastableExpr& n)
1256 {
1257 n.cast_expr()->accept(*this);
1258 if(n.singletype())
1259 {
1260 os << " castable as ";
1261 n.singletype()->accept(*this);
1262 }
1263 return 0;
1264 }
DEFAULT_END_VISIT(CastableExpr)1265 DEFAULT_END_VISIT (CastableExpr)
1266
1267 void* begin_visit(const CommonContent& n)
1268 {
1269 switch(n.get_type())
1270 {
1271 case ParseConstants::cont_escape_lbrace:
1272 os << "{{";
1273 break;
1274 case ParseConstants::cont_escape_rbrace:
1275 os << "}}";
1276 break;
1277 case ParseConstants::cont_charref:
1278 os << n.get_ref();
1279 break;
1280 default:
1281 n.get_expr()->accept(*this);
1282 }
1283 return 0;
1284 }
1285 DEFAULT_END_VISIT (CommonContent)
1286
DEFAULT_VISIT(ComparisonExpr)1287 DEFAULT_VISIT (ComparisonExpr)
1288
1289 void* begin_visit(const CompAttrConstructor& n)
1290 {
1291 os << "attribute" ;
1292 if(dynamic_cast<QName*>(n.get_qname_expr().getp()) != 0)
1293 {
1294 n.get_qname_expr()->accept(*this);
1295 os << '{';
1296 if(n.get_val_expr())
1297 {
1298 n.get_val_expr()->accept(*this);
1299 }
1300 os << '}';
1301 } else {
1302 os << '{';
1303 n.get_qname_expr()->accept(*this);
1304 os << '}';
1305 os << '{';
1306 if(n.get_val_expr())
1307 {
1308 n.get_val_expr()->accept(*this);
1309 }
1310 os << '}';
1311 }
1312 return 0;
1313 }
DEFAULT_END_VISIT(CompAttrConstructor)1314 DEFAULT_END_VISIT (CompAttrConstructor)
1315
1316 void* begin_visit(const CompCommentConstructor& n)
1317 {
1318 os << "comment {";
1319 n.get_comment_expr()->accept(*this);
1320 os << '}';
1321 return 0;
1322 }
DEFAULT_END_VISIT(CompCommentConstructor)1323 DEFAULT_END_VISIT (CompCommentConstructor)
1324
1325 void* begin_visit(const CompDocConstructor& n)
1326 {
1327 os << "document{ ";
1328 n.get_expr()->accept(*this);
1329 os << '}';
1330 return 0;
1331 }
DEFAULT_END_VISIT(CompDocConstructor)1332 DEFAULT_END_VISIT (CompDocConstructor)
1333
1334 void* begin_visit(const CompElemConstructor& n)
1335 {
1336 os << "element";
1337 if(dynamic_cast<QName*>(n.get_qname_expr().getp()) != 0)
1338 {
1339 n.get_qname_expr()->accept(*this);
1340 os << '{';
1341 if(n.get_content_expr())
1342 {
1343 n.get_content_expr()->accept(*this);
1344 }
1345 os << '}';
1346 } else {
1347 os << '{';
1348 n.get_qname_expr()->accept(*this);
1349 os << "}{";
1350 if(n.get_content_expr())
1351 {
1352 n.get_content_expr()->accept(*this);
1353 }
1354 os << '}';
1355 }
1356 return 0;
1357 }
DEFAULT_END_VISIT(CompElemConstructor)1358 DEFAULT_END_VISIT (CompElemConstructor)
1359
1360 void* begin_visit(const CompPIConstructor& n)
1361 {
1362 os << "processing-instruction";
1363 if(!n.get_target().empty())
1364 {
1365 os << n.get_target();
1366 } else {
1367 os << '{';
1368 n.get_target_expr()->accept(*this);
1369 os << '}';
1370 }
1371 os << '{';
1372 if(n.get_content_expr())
1373 {
1374 n.get_content_expr()->accept(*this);
1375 }
1376 os << '}';
1377 return 0;
1378 }
DEFAULT_END_VISIT(CompPIConstructor)1379 DEFAULT_END_VISIT (CompPIConstructor)
1380
1381 void* begin_visit(const CompTextConstructor& n)
1382 {
1383 os << "text {";
1384 n.get_text_expr()->accept(*this);
1385 os << '}';
1386 return 0;
1387 }
DEFAULT_END_VISIT(CompTextConstructor)1388 DEFAULT_END_VISIT (CompTextConstructor)
1389
1390 void* begin_visit(const ContextItemExpr& n)
1391 {
1392 os << '.';
1393 return 0;
1394 }
DEFAULT_END_VISIT(ContextItemExpr)1395 DEFAULT_END_VISIT (ContextItemExpr)
1396
1397 void* begin_visit(const DirCommentConstructor& n)
1398 {
1399 os << "<!-- " << n.get_comment() << " -->";
1400 return 0;
1401 }
1402 DEFAULT_END_VISIT (DirCommentConstructor);
1403
begin_visit(const DirElemConstructor & n)1404 void* begin_visit(const DirElemConstructor& n)
1405 {
1406 os << '<';
1407 n.get_elem_name()->accept(*this);
1408 if(n.get_attr_list() != 0)
1409 {
1410 n.get_attr_list()->accept(*this);
1411 }
1412 if(n.get_dir_content_list() != 0)
1413 {
1414 os << '>';
1415 n.get_dir_content_list()->accept(*this);
1416 os << "</";
1417 n.get_end_name()->accept(*this);
1418 os << '>';
1419 } else {
1420 os << "/>";
1421 }
1422 return 0;
1423 }
1424 DEFAULT_END_VISIT (DirElemConstructor)
1425
DEFAULT_VISIT(DirElemContent)1426 DEFAULT_VISIT (DirElemContent)
1427
1428 void* begin_visit(const DirPIConstructor& n)
1429 {
1430 os << "<? " << n.get_pi_target() << " " << n.get_pi_content() << " ?>";
1431 return 0;
1432 }
DEFAULT_END_VISIT(DirPIConstructor)1433 DEFAULT_END_VISIT (DirPIConstructor)
1434
1435 void* begin_visit(const EnclosedExpr& n)
1436 {
1437 os << '{';
1438 n.get_expr()->accept(*this);
1439 os << '}';
1440 return 0;
1441 }
1442 DEFAULT_END_VISIT (EnclosedExpr);
1443
1444 DEFAULT_VISIT (BlockBody)
DEFAULT_VISIT(ApplyExpr)1445 DEFAULT_VISIT (ApplyExpr)
1446 DEFAULT_VISIT (Expr)
1447
1448 void* begin_visit(const ExtensionExpr& n)
1449 {
1450 n.get_pragma_list()->accept(*this);
1451 os << "{ ";
1452 n.get_expr()->accept(*this);
1453 os << " }";
1454 return 0;
1455 }
DEFAULT_END_VISIT(ExtensionExpr)1456 DEFAULT_END_VISIT (ExtensionExpr)
1457
1458 void* begin_visit(const FLWORExpr& n)
1459 {
1460 n.get_clause_list()->accept(*this);
1461 os << "return ";
1462 n.get_return_val()->accept(*this);
1463 return 0;
1464 }
1465 DEFAULT_END_VISIT (FLWORExpr)
1466
1467
DEFAULT_VISIT(WindowClause)1468 DEFAULT_VISIT (WindowClause)
1469 DEFAULT_VISIT (WindowVarDecl)
1470 DEFAULT_VISIT (FLWORWinCond)
1471 DEFAULT_VISIT (WindowVars)
1472 DEFAULT_VISIT (FilterExpr) //@checked
1473
1474 void* begin_visit(const FunctionCall& n)
1475 {
1476 n.get_fname()->accept(*this);
1477 os << '(';
1478 if(n.get_arg_list())
1479 {
1480 n.get_arg_list()->accept(*this);
1481 }
1482 os << ')';
1483 return 0;
1484 }
DEFAULT_END_VISIT(FunctionCall)1485 DEFAULT_END_VISIT (FunctionCall)
1486
1487 void* begin_visit(const IfExpr& n)
1488 {
1489 os << "if(";
1490 n.get_cond_expr()->accept(*this);
1491 os << ") then ";
1492 n.get_then_expr()->accept(*this);
1493 os << " else ";
1494 n.get_else_expr()->accept(*this);
1495 return 0;
1496 }
DEFAULT_END_VISIT(IfExpr)1497 DEFAULT_END_VISIT (IfExpr)
1498
1499 void* begin_visit(const InstanceofExpr& n)
1500 {
1501 n.get_treat_expr()->accept(*this);
1502 if(n.get_seqtype())
1503 {
1504 os << " instanceof ";
1505 n.get_seqtype()->accept(*this);
1506 }
1507 return 0;
1508 }
1509 DEFAULT_END_VISIT (InstanceofExpr)
1510
DEFAULT_VISIT(IntersectExceptExpr)1511 DEFAULT_VISIT (IntersectExceptExpr)
1512
1513 void* begin_visit(const MultiplicativeExpr& n)
1514 {
1515 n.get_mult_expr()->accept(*this);
1516 switch(n.get_mult_op())
1517 {
1518 case ParseConstants::op_mul:
1519 os << '*';
1520 break;
1521 case ParseConstants::op_div:
1522 os << " div ";
1523 break;
1524 case ParseConstants::op_idiv:
1525 os << " idiv ";
1526 break;
1527 case ParseConstants::op_mod:
1528 os << " mod ";
1529 break;
1530 }
1531 n.get_union_expr()->accept(*this);
1532 return 0;
1533 }
DEFAULT_END_VISIT(MultiplicativeExpr)1534 DEFAULT_END_VISIT (MultiplicativeExpr)
1535
1536 void* begin_visit(const NumericLiteral& n)
1537 {
1538 os << n.toString();
1539 return 0;
1540 }
DEFAULT_END_VISIT(NumericLiteral)1541 DEFAULT_END_VISIT (NumericLiteral)
1542
1543 void* begin_visit(const OrExpr& n)
1544 {
1545 n.get_or_expr()->accept(*this);
1546 os << " or ";
1547 n.get_and_expr()->accept(*this);
1548 return 0;
1549 }
DEFAULT_END_VISIT(OrExpr)1550 DEFAULT_END_VISIT (OrExpr)
1551
1552 void* begin_visit(const OrderedExpr& n)
1553 {
1554 os << "ordered { ";
1555 n.get_expr()->accept(*this);
1556 os << " } ";
1557 return 0;
1558 }
1559 DEFAULT_END_VISIT (OrderedExpr);
1560
begin_visit(const ParenthesizedExpr & n)1561 void* begin_visit(const ParenthesizedExpr& n)
1562 {
1563 os << ')';
1564 return no_state;
1565 }
1566
end_visit(const ParenthesizedExpr & n,void *)1567 void end_visit(const ParenthesizedExpr& n, void*)
1568 {
1569 os << ')';
1570 }
1571
begin_visit(const PathExpr & n)1572 void* begin_visit(const PathExpr& n)
1573 {
1574 switch(n.get_type())
1575 {
1576 case ParseConstants::path_leading_lone_slash:
1577 os << '/';
1578 break;
1579 case ParseConstants::path_leading_slash:
1580 os << '/';
1581 break;
1582 case ParseConstants::path_leading_slashslash:
1583 os << "//";
1584 break;
1585 case ParseConstants::path_relative:
1586 break;
1587 }
1588 return no_state;
1589 }
DEFAULT_END_VISIT(PathExpr)1590 DEFAULT_END_VISIT (PathExpr)
1591
1592 void* begin_visit(const QuantifiedExpr& n)
1593 {
1594 switch(n.get_qmode())
1595 {
1596 case ParseConstants::quant_some:
1597 os << " some $";
1598 break;
1599 case ParseConstants::quant_every:
1600 os << " every $";
1601 }
1602 n.get_decl_list()->accept(*this);
1603 os << " in ";
1604 n.get_expr()->accept(*this);
1605 return 0;
1606 }
1607 DEFAULT_END_VISIT (QuantifiedExpr)
1608
DEFAULT_VISIT(QueryBody)1609 DEFAULT_VISIT (QueryBody) //@checked
1610
1611 void* begin_visit(const RangeExpr& n)
1612 {
1613 n.get_from_expr()->accept(*this);
1614 if(n.get_to_expr())
1615 {
1616 os << " to ";
1617 n.get_to_expr()->accept(*this);
1618 }
1619 return 0;
1620 }
DEFAULT_END_VISIT(RangeExpr)1621 DEFAULT_END_VISIT (RangeExpr)
1622
1623 void* begin_visit(const RelativePathExpr& n)
1624 {
1625 n.get_step_expr()->accept(*this);
1626 switch(n.get_step_type())
1627 {
1628 case ParseConstants::st_step:
1629 return 0;
1630 case ParseConstants::st_slash:
1631 os << '/';
1632 break;
1633 case ParseConstants::st_slashslash:
1634 os << "//";
1635 break;
1636 }
1637 n.get_relpath_expr()->accept(*this);
1638 return 0;
1639 }
DEFAULT_END_VISIT(RelativePathExpr)1640 DEFAULT_END_VISIT (RelativePathExpr)
1641
1642 void* begin_visit(const SimpleMapExpr& n)
1643 {
1644 n.get_left_expr()->accept(*this);
1645 os << "!";
1646 n.get_right_expr()->accept(*this);
1647 return 0;
1648 }
DEFAULT_END_VISIT(SimpleMapExpr)1649 DEFAULT_END_VISIT (SimpleMapExpr)
1650
1651
1652 void* begin_visit(const StringLiteral& n)
1653 {
1654 os << "\"" << n.get_strval() << '"';
1655 return 0;
1656 }
1657 DEFAULT_END_VISIT (StringLiteral);
1658
1659
begin_visit(const StringConcatExpr & n)1660 void* begin_visit(const StringConcatExpr& n)
1661 {
1662 n.get_left_expr()->accept(*this);
1663 os << " || ";
1664 n.get_right_expr()->accept(*this);
1665 return 0;
1666 }
1667 DEFAULT_END_VISIT(StringConcatExpr);
1668
begin_visit(const TreatExpr & n)1669 void* begin_visit(const TreatExpr& n)
1670 {
1671 n.get_castable_expr()->accept(*this);
1672 if(n.get_seqtype())
1673 {
1674 os << " treat as";
1675 n.get_seqtype()->accept(*this);
1676 }
1677 return 0;
1678 }
DEFAULT_END_VISIT(TreatExpr)1679 DEFAULT_END_VISIT (TreatExpr)
1680
1681 void* begin_visit(const SwitchExpr& n)
1682 {
1683 os << "switch(";
1684 n.get_switch_expr()->accept(*this);
1685 os << ')';
1686 n.get_clause_list()->accept(*this);
1687 os << " default return";
1688 n.get_default_expr()->accept(*this);
1689 return 0;
1690 }
DEFAULT_END_VISIT(SwitchExpr)1691 DEFAULT_END_VISIT (SwitchExpr)
1692
1693 void* begin_visit(const SwitchCaseClause& n)
1694 {
1695 n.get_operand_list()->accept(*this);
1696 os << " return";
1697 n.get_return_expr()->accept(*this);
1698 return 0;
1699 }
1700 DEFAULT_END_VISIT (SwitchCaseClause)
1701
DEFAULT_VISIT(SwitchCaseClauseList)1702 DEFAULT_VISIT (SwitchCaseClauseList)
1703
1704 DEFAULT_VISIT (SwitchCaseOperandList)
1705
1706
1707 void* begin_visit(const TypeswitchExpr& n)
1708 {
1709 os << "typeswitch(";
1710 n.get_switch_expr()->accept(*this);
1711 os << ')';
1712 n.get_clause_list()->accept(*this);
1713 os << " default";
1714 if(n.get_default_varname())
1715 {
1716 os << " $" << n.get_default_varname()->get_qname();
1717 }
1718 os << " return";
1719 n.get_default_clause()->accept(*this);
1720 return 0;
1721 }
1722 DEFAULT_END_VISIT (TypeswitchExpr)
1723
DEFAULT_VISIT(UnaryExpr)1724 DEFAULT_VISIT (UnaryExpr) //@checked
1725
1726 void* begin_visit(const UnionExpr& n)
1727 {
1728 if(n.union_expr())
1729 {
1730 n.union_expr()->accept(*this);
1731 os << " union";
1732 }
1733 n.intex_expr()->accept(*this);
1734 return 0;
1735 }
DEFAULT_END_VISIT(UnionExpr)1736 DEFAULT_END_VISIT (UnionExpr)
1737
1738 void* begin_visit(const UnorderedExpr& n)
1739 {
1740 os << " unodered{ ";
1741 n.get_expr()->accept(*this);
1742 os << " }";
1743 return 0;
1744 }
DEFAULT_END_VISIT(UnorderedExpr)1745 DEFAULT_END_VISIT (UnorderedExpr)
1746
1747 void* begin_visit(const ValidateExpr& n)
1748 {
1749 os << " validate";
1750 switch(n.get_valmode())
1751 {
1752 case ParseConstants::val_strict:
1753 os << " strict";
1754 break;
1755 case ParseConstants::val_lax:
1756 os << " lax";
1757 break;
1758 default: break;
1759 }
1760 os << " {";
1761 n.get_expr()->accept(*this);
1762 os << " }";
1763 return 0;
1764 }
DEFAULT_END_VISIT(ValidateExpr)1765 DEFAULT_END_VISIT (ValidateExpr)
1766
1767 void* begin_visit(const VarRef& n)
1768 {
1769 os << '$';
1770 os << n.get_name()->get_qname();
1771 return 0;
1772 }
DEFAULT_END_VISIT(VarRef)1773 DEFAULT_END_VISIT (VarRef)
1774
1775 /* update-related */
1776 void* begin_visit(const DeleteExpr& n)
1777 {
1778 os << "delete node ";
1779 n.getTargetExpr()->accept(*this);
1780 return 0;
1781 }
1782 DEFAULT_END_VISIT (DeleteExpr);
1783
begin_visit(const InsertExpr & n)1784 void* begin_visit(const InsertExpr& n)
1785 {
1786 os << "insert nodes ";
1787 n.getSourceExpr()->accept(*this);
1788 switch(n.getType())
1789 {
1790 case store::UpdateConsts::INTO:
1791 os << "into ";
1792 break;
1793 case store::UpdateConsts::AS_FIRST_INTO:
1794 os << "as first into ";
1795 break;
1796 case store::UpdateConsts::AS_LAST_INTO:
1797 os << "as last into ";
1798 break;
1799 case store::UpdateConsts::AFTER:
1800 os << "after ";
1801 break;
1802 case store::UpdateConsts::BEFORE:
1803 os << "before ";
1804 break;
1805 }
1806 return 0;
1807 }
DEFAULT_END_VISIT(InsertExpr)1808 DEFAULT_END_VISIT (InsertExpr)
1809
1810 void* begin_visit(const RenameExpr& n)
1811 {
1812 os << "insert nodes ";
1813 n.getTargetExpr()->accept(*this);
1814 os << "as ";
1815 n.getNameExpr()->accept(*this);
1816 return 0;
1817 }
DEFAULT_END_VISIT(RenameExpr)1818 DEFAULT_END_VISIT (RenameExpr)
1819
1820 void* begin_visit(const ReplaceExpr& n)
1821 {
1822 os << "replace ";
1823 switch(n.getType())
1824 {
1825 case store::UpdateConsts::VALUE_OF_NODE:
1826 os << "value of node ";
1827 break;
1828 case store::UpdateConsts::NODE:
1829 os << "node ";
1830 break;
1831 }
1832 n.getTargetExpr()->accept(*this);
1833 os << "with ";
1834 n.getReplaceExpr()->accept(*this);
1835 return 0;
1836 }
DEFAULT_END_VISIT(ReplaceExpr)1837 DEFAULT_END_VISIT (ReplaceExpr)
1838
1839 void* begin_visit(const RevalidationDecl& n)
1840 {
1841 os << "declare revalidation ";
1842 switch(n.get_mode())
1843 {
1844 case StaticContextConsts::strict_validation:
1845 os << "strict ";
1846 break;
1847 case StaticContextConsts::lax_validation:
1848 os << "lax ";
1849 break;
1850 case StaticContextConsts::skip_validation:
1851 os << "skip ";
1852 break;
1853 default:
1854 ZORBA_ASSERT(false);
1855 }
1856 return 0;
1857 }
DEFAULT_END_VISIT(RevalidationDecl)1858 DEFAULT_END_VISIT (RevalidationDecl)
1859
1860 void* begin_visit(const TransformExpr& n)
1861 {
1862 os << "copy $";
1863 n.get_var_list()->accept(*this);
1864 os << "modify ";
1865 n.get_modify_expr()->accept(*this);
1866 os << "return ";
1867 n.get_return_expr()->accept(*this);
1868 return 0;
1869 }
1870 DEFAULT_END_VISIT (TransformExpr)
1871
DEFAULT_VISIT(CopyVarList)1872 DEFAULT_VISIT (CopyVarList) //@checked
1873
1874 void* begin_visit(const VarBinding& n)
1875 {
1876 os << "$" << n.get_varname();
1877 os << " := ";
1878 n.get_expr()->accept(*this);
1879 return 0;
1880 }
DEFAULT_END_VISIT(VarBinding)1881 DEFAULT_END_VISIT (VarBinding)
1882
1883 /* try-catch-related */
1884 void* begin_visit(const TryExpr& n)
1885 {
1886 os << "try {";
1887 n.getExprSingle()->accept(*this);
1888 os << "}";
1889 n.getCatchListExpr()->accept(*this);
1890 return 0;
1891 }
1892 DEFAULT_END_VISIT (TryExpr);
1893
1894 DEFAULT_VISIT (CatchListExpr); //@checked
1895
begin_visit(const CatchExpr & n)1896 void* begin_visit(const CatchExpr& n)
1897 {
1898 os << "catch ";
1899 for(CatchExpr::NameTestList::const_iterator i = n.getNameTests().begin();
1900 i != n.getNameTests().end(); ++i)
1901 {
1902 (*i)->accept(*this);
1903 }
1904
1905 os << "{";
1906 n.getExprSingle()->accept(*this);
1907 os << "}";
1908 return 0;
1909 }
1910 DEFAULT_END_VISIT (CatchExpr);
1911
begin_visit(const AnyFunctionTest & n)1912 void* begin_visit(const AnyFunctionTest& n)
1913 {
1914 os << "function (*)";
1915 return 0;
1916 }
1917 DEFAULT_END_VISIT (AnyFunctionTest);
1918
begin_visit(const TypedFunctionTest & n)1919 void* begin_visit(const TypedFunctionTest& n)
1920 {
1921 os << "function (";
1922 n.getArgumentTypes()->accept(*this);
1923 os << ") as ";
1924 n.getReturnType()->accept(*this);
1925 return 0;
1926 }
1927 DEFAULT_END_VISIT (TypedFunctionTest);
1928
begin_visit(const TypeList & n)1929 void* begin_visit(const TypeList& n)
1930 {
1931 for (size_t i = 0; i < n.size(); ++i)
1932 {
1933 if (i > 0)
1934 {
1935 os << ", ";
1936 }
1937 const SequenceType* e_p = n[i];
1938 e_p->accept(*this);
1939 }
1940 return 0;
1941 }
1942 DEFAULT_END_VISIT (TypeList);
1943
1944 /* full-text-related */
1945 DEFAULT_VISIT (FTAnd);
1946 DEFAULT_VISIT (FTAnyallOption);
1947 DEFAULT_VISIT (FTBigUnit);
1948 DEFAULT_VISIT (FTCaseOption);
1949 DEFAULT_VISIT (FTContainsExpr);
1950 DEFAULT_VISIT (FTContent);
1951 DEFAULT_VISIT (FTDiacriticsOption);
1952 DEFAULT_VISIT (FTDistance);
1953 DEFAULT_VISIT (FTExtensionOption);
1954 DEFAULT_VISIT (FTExtensionSelection);
1955 DEFAULT_VISIT (FTIgnoreOption);
1956 DEFAULT_VISIT (FTLanguageOption);
1957 DEFAULT_VISIT (FTMatchOptions);
1958 DEFAULT_VISIT (FTMildNot);
1959 DEFAULT_VISIT (FTOptionDecl);
1960 DEFAULT_VISIT (FTOr);
1961 DEFAULT_VISIT (FTOrder);
1962 DEFAULT_VISIT (FTPrimaryWithOptions);
1963 DEFAULT_VISIT (FTRange);
1964 DEFAULT_VISIT (FTScope);
1965 DEFAULT_VISIT (FTScoreVar);
1966 DEFAULT_VISIT (FTSelection);
1967 DEFAULT_VISIT (FTStemOption);
1968 DEFAULT_VISIT (FTStopWordOption);
1969 DEFAULT_VISIT (FTStopWords);
1970 DEFAULT_VISIT (FTStopWordsInclExcl);
1971 DEFAULT_VISIT (FTThesaurusID);
1972 DEFAULT_VISIT (FTThesaurusOption);
1973 DEFAULT_VISIT (FTTimes);
1974 DEFAULT_VISIT (FTUnaryNot);
1975 DEFAULT_VISIT (FTUnit);
1976 DEFAULT_VISIT (FTWeight);
1977 DEFAULT_VISIT (FTWildCardOption);
1978 DEFAULT_VISIT (FTWindow);
1979 DEFAULT_VISIT (FTWords);
1980 DEFAULT_VISIT (FTWordsTimes);
1981 DEFAULT_VISIT (FTWordsValue);
1982
1983 /* JSON-related */
1984 DEFAULT_VISIT (JSONArrayConstructor);
1985
1986 DEFAULT_VISIT (JSONObjectConstructor);
1987
1988 DEFAULT_VISIT (JSONDirectObjectConstructor);
1989
1990 DEFAULT_VISIT (JSONPairList);
1991
1992 DEFAULT_VISIT (JSONPairConstructor);
1993
1994 DEFAULT_VISIT (JSONObjectInsertExpr);
1995
1996 DEFAULT_VISIT (JSONArrayInsertExpr);
1997
1998 DEFAULT_VISIT (JSONArrayAppendExpr);
1999
2000 DEFAULT_VISIT (JSONDeleteExpr);
2001
2002 DEFAULT_VISIT (JSONReplaceExpr);
2003
2004 DEFAULT_VISIT (JSONRenameExpr);
2005
begin_visit(const JSON_Test & n)2006 void* begin_visit(const JSON_Test& n)
2007 {
2008 os << store::StoreConsts::toString(n.get_kind()) << "()";
2009 return no_state;
2010 }
2011 DEFAULT_END_VISIT (JSON_Test);
2012
2013 DEFAULT_VISIT (AssignExpr);
2014 DEFAULT_VISIT (ExitExpr);
2015 DEFAULT_VISIT (WhileExpr);
2016 DEFAULT_VISIT (FlowCtlStatement);
2017
2018 DEFAULT_VISIT (LiteralFunctionItem);
2019 DEFAULT_VISIT (InlineFunction);
2020 DEFAULT_VISIT (DynamicFunctionInvocation);
2021
2022 DEFAULT_VISIT (ParseErrorNode);
2023 };
2024
print_parsetree_xquery(ostream & os,const parsenode * p)2025 FunctionIndex print_parsetree_xquery(ostream& os, const parsenode* p)
2026 {
2027 ParseNodePrintXQueryVisitor v(os);
2028 return v.print(p)->getFunctionIndex();
2029 }
2030 }//end of namespace
2031 /* vim:set et sw=2 ts=2: */
2032