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 #pragma once 17 #ifndef ZORBA_PARSENODE_BASE_H 18 #define ZORBA_PARSENODE_BASE_H 19 20 #include <zorba/config.h> 21 #include <zorba/diagnostic_list.h> 22 23 #include "compiler/parser/parse_constants.h" 24 #include "compiler/parser/query_loc.h" 25 #include "compiler/parser/xqdoc_comment.h" 26 #include "zorbatypes/rchandle.h" 27 28 #include "store/api/update_consts.h" 29 #include "zorbatypes/zstring.h" 30 31 namespace zorba { 32 33 class parsenode_visitor; 34 35 36 /* 37 ** base class: syntax-only nodes 38 */ 39 // exported for unit testing only 40 class ZORBA_DLL_PUBLIC parsenode : public SimpleRCObject 41 { 42 protected: 43 QueryLoc loc; 44 45 friend class ParseNodePrintXMLVisitor; 46 47 public: parsenode(const QueryLoc & loc_)48 parsenode(const QueryLoc& loc_) : loc(loc_) { } ~parsenode()49 virtual ~parsenode() {} 50 51 public: get_location()52 const QueryLoc& get_location() const { return loc; } 53 54 virtual void accept(parsenode_visitor&) const = 0; 55 56 }; 57 58 /** 59 * XQDocumentable: nodes with XQDoc comments attached 60 */ 61 class XQDocumentable: public parsenode 62 { 63 private: 64 zstring theStringComment; 65 mutable const XQDocComment* theComment; 66 67 public: XQDocumentable(const QueryLoc & loc)68 XQDocumentable(const QueryLoc& loc): parsenode(loc), theComment(0){} ~XQDocumentable()69 ~XQDocumentable(){ delete theComment; } 70 setComment(const zstring & aComment)71 XQDocumentable* setComment(const zstring& aComment) 72 { 73 theStringComment = aComment; 74 return this; 75 } 76 getComment()77 const XQDocComment* getComment() const 78 { 79 if(theComment == 0) 80 { 81 theComment = new XQDocComment(theStringComment); 82 } 83 return theComment; 84 } 85 getCommentString()86 zstring getCommentString() const { return theStringComment; } 87 }; 88 89 90 /** 91 * exprnode: nodes with values. 92 */ 93 class exprnode : public parsenode 94 { 95 public: exprnode(const QueryLoc & loc)96 exprnode(const QueryLoc& loc) : parsenode(loc) { } 97 98 public: 99 virtual void accept(parsenode_visitor&) const = 0; 100 101 }; 102 103 104 class ZORBA_DLL_PUBLIC ParseErrorNode : public parsenode 105 { 106 public: 107 Error const &err; 108 zstring const msg; 109 bool const useParam; // if true, msg is a parameter for the ZORBA_ERROR_LOC_PARAM() macro 110 111 ParseErrorNode(const QueryLoc& loc_, Error const &err_ = err::XPST0003, zstring msg_ = "", bool useParam_ = false) 112 : parsenode(loc_)113 parsenode (loc_), err(err_), msg(msg_), useParam(useParam_) 114 {} 115 accept(parsenode_visitor &)116 void accept(parsenode_visitor&) const {} 117 }; 118 119 120 } // namespace zorba 121 122 #endif /* ZORBA_PARSENODE_BASE_H */ 123 /* 124 * Local variables: 125 * mode: c++ 126 * End: 127 */ 128 /* vim:set et sw=2 ts=2: */ 129