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_COMPILER_UPDATE_EXPRS 18 #define ZORBA_COMPILER_UPDATE_EXPRS 19 20 #include "store/api/update_consts.h" 21 22 #include "compiler/expression/expr_base.h" 23 24 25 namespace zorba 26 { 27 28 29 ///////////////////////////////////////////////////////////////////////// 30 // // 31 // Update expressions // 32 // [http://www.w3.org/TR/xqupdate/] // 33 // // 34 ///////////////////////////////////////////////////////////////////////// 35 36 37 /******************************************************************************* 38 39 ********************************************************************************/ 40 class update_expr_base : public expr 41 { 42 protected: 43 expr * theTargetExpr; 44 expr * theSourceExpr; 45 46 public: 47 update_expr_base( 48 CompilerCB* ccb, 49 static_context* sctx, 50 const QueryLoc&, 51 expr_kind_t kind, 52 expr* targetExpr, 53 expr* sourceExpr); 54 getTargetExpr()55 expr* getTargetExpr() const { return theTargetExpr; } 56 getSourceExpr()57 expr* getSourceExpr() const { return theSourceExpr; } 58 59 void compute_scripting_kind(); 60 }; 61 62 63 /******************************************************************************* 64 65 ********************************************************************************/ 66 class insert_expr : public update_expr_base 67 { 68 friend class ExprIterator; 69 friend class expr; 70 friend class ExprManager; 71 72 protected: 73 store::UpdateConsts::InsertType theType; 74 75 76 protected: 77 insert_expr( 78 CompilerCB* ccb, 79 static_context* sctx, 80 const QueryLoc&, 81 store::UpdateConsts::InsertType, 82 expr* aSourceExpr, 83 expr* aTargetExpr); 84 85 public: getType()86 store::UpdateConsts::InsertType getType() const { return theType; } 87 88 expr* cloneImpl(substitution_t& s) const; 89 90 void accept(expr_visitor&); 91 92 std::ostream& put(std::ostream&) const; 93 }; 94 95 96 /******************************************************************************* 97 98 ********************************************************************************/ 99 class delete_expr : public update_expr_base 100 { 101 friend class ExprIterator; 102 friend class expr; 103 friend class ExprManager; 104 105 106 protected: 107 delete_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc&, expr*); 108 109 public: 110 expr* cloneImpl(substitution_t& s) const; 111 112 void accept(expr_visitor&); 113 114 std::ostream& put(std::ostream&) const; 115 }; 116 117 118 /******************************************************************************* 119 120 ********************************************************************************/ 121 class replace_expr : public update_expr_base 122 { 123 friend class ExprIterator; 124 friend class expr; 125 friend class ExprManager; 126 127 protected: 128 store::UpdateConsts::ReplaceType theType; 129 130 protected: 131 replace_expr( 132 CompilerCB* ccb, 133 static_context* sctx, 134 const QueryLoc&, 135 store::UpdateConsts::ReplaceType aType, 136 expr*, 137 expr*); 138 139 public: getType()140 store::UpdateConsts::ReplaceType getType() const { return theType; } 141 getReplaceExpr()142 expr* getReplaceExpr() const { return theSourceExpr; } 143 144 expr* cloneImpl(substitution_t& s) const; 145 146 void accept(expr_visitor&); 147 148 std::ostream& put(std::ostream&) const; 149 }; 150 151 152 /******************************************************************************* 153 154 ********************************************************************************/ 155 class rename_expr : public update_expr_base 156 { 157 friend class ExprIterator; 158 friend class expr; 159 friend class ExprManager; 160 161 protected: 162 rename_expr( 163 CompilerCB* ccb, 164 static_context* sctx, 165 const QueryLoc&, 166 expr*, 167 expr*); 168 169 public: getNameExpr()170 expr* getNameExpr() const { return theSourceExpr; } 171 172 expr* cloneImpl(substitution_t& s) const; 173 174 void accept(expr_visitor&); 175 176 std::ostream& put(std::ostream&) const; 177 }; 178 179 180 /******************************************************************************* 181 TransformExpr ::= "copy" "$" VarName ":=" ExprSingle 182 ("," "$" VarName ":=" ExprSingle)* 183 "modify" ExprSingle "return" ExprSingle 184 ********************************************************************************/ 185 class copy_clause 186 { 187 friend class expr; 188 friend class transform_expr; 189 friend class ExprIterator; 190 friend class ExprManager; 191 192 private: 193 var_expr * theVar; 194 expr * theExpr; 195 CompilerCB *const theCCB; 196 197 protected: 198 copy_clause(CompilerCB* ccb, var_expr* aVar, expr* aExpr); 199 200 public: 201 ~copy_clause(); 202 free()203 void free() {} 204 getVar()205 var_expr* getVar() const { return theVar; } 206 getExpr()207 expr* getExpr() const { return theExpr; } 208 209 copy_clause* clone(expr::substitution_t& s) const; 210 211 std::ostream& put(std::ostream&) const; 212 }; 213 214 215 class transform_expr : public expr 216 { 217 friend class ExprIterator; 218 friend class expr; 219 friend class ExprManager; 220 221 protected: 222 std::vector<copy_clause*> theCopyClauses; 223 expr * theModifyExpr; 224 expr * theReturnExpr; 225 226 protected: 227 transform_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc); 228 229 public: getModifyExpr()230 expr* getModifyExpr() const { return theModifyExpr; } 231 getReturnExpr()232 expr* getReturnExpr() const { return theReturnExpr; } 233 234 void setModifyExpr(expr* e); 235 236 void setReturnExpr(expr* e); 237 238 void add_back(copy_clause* c); 239 240 copy_clause* const& operator[](int i) const { return theCopyClauses[i]; } 241 begin()242 std::vector<copy_clause*>::const_iterator begin() const 243 { return theCopyClauses.begin(); } 244 end()245 std::vector<copy_clause*>::const_iterator end() const 246 { return theCopyClauses.end(); } 247 size()248 csize size() const { return theCopyClauses.size(); } 249 250 void compute_scripting_kind(); 251 252 expr* cloneImpl(substitution_t& s) const; 253 254 void accept(expr_visitor&); 255 256 std::ostream& put(std::ostream&) const; 257 }; 258 259 260 261 } 262 #endif 263 264 /* 265 * Local variables: 266 * mode: c++ 267 * End: 268 */ 269 /* vim:set et sw=2 ts=2: */ 270