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_FO_EXPR 18 #define ZORBA_COMPILER_FO_EXPR 19 20 #include "zorbautils/checked_vector.h" 21 22 #include "compiler/expression/expr_base.h" 23 24 25 namespace zorba 26 { 27 28 class function; 29 class signature; 30 31 32 /******************************************************************************* 33 first-order expressions 34 ********************************************************************************/ 35 class fo_expr : public expr 36 { 37 friend class ExprIterator; 38 friend class expr; 39 friend class ExprManager; 40 41 protected: 42 checked_vector<expr*> theArgs; 43 function * theFunction; 44 45 public: 46 47 protected: 48 static fo_expr* create_seq(CompilerCB* ccb, static_context* sctx, const QueryLoc&); 49 50 protected: 51 fo_expr( 52 CompilerCB* ccb, 53 static_context* sctx, 54 const QueryLoc& loc, 55 const function* f, 56 expr* arg); 57 58 fo_expr( 59 CompilerCB* ccb, 60 static_context* sctx, 61 const QueryLoc& loc, 62 const function* f, 63 expr* arg1, 64 expr* arg2); 65 66 fo_expr( 67 CompilerCB* ccb, 68 static_context* sctx, 69 const QueryLoc& loc, 70 const function* f, 71 const std::vector<expr*>& args); 72 73 public: get_func()74 function* get_func() const { return theFunction; } 75 set_func(function * f)76 void set_func(function* f) { theFunction = f; } 77 78 const signature& get_signature() const; 79 80 const store::Item* get_fname() const; 81 num_args()82 csize num_args() const { return theArgs.size(); } 83 get_arg(csize i)84 expr* get_arg(csize i) const { return theArgs[i]; } 85 get_args()86 const std::vector<expr*>& get_args() const { return theArgs; } 87 set_arg(csize i,expr * e)88 void set_arg(csize i, expr* e) { theArgs[i] = e; } 89 90 void add_arg(expr* e); 91 92 void add_args(const std::vector<expr*>& args); 93 94 void remove_arg(csize i); 95 96 void compute_scripting_kind(); 97 98 expr* cloneImpl(substitution_t& s) const; 99 100 void accept(expr_visitor&); 101 102 std::ostream& put(std::ostream&) const; 103 104 private: 105 fo_expr(CompilerCB* ccb, static_context* sctx, const QueryLoc& loc, const function* f); 106 }; 107 108 109 ////////// The following expressions in the AST "decay" into an fo_expr /////// 110 111 typedef fo_expr additive_expr; 112 113 typedef fo_expr and_expr; 114 115 typedef fo_expr comparison_expr; 116 117 typedef fo_expr enclosed_expr; 118 119 typedef fo_expr intersect_except_expr; 120 121 typedef fo_expr multiplicative_expr; 122 123 typedef fo_expr or_expr; 124 125 typedef fo_expr quantified_expr; 126 127 typedef fo_expr range_expr; 128 129 typedef fo_expr unary_expr; 130 131 typedef fo_expr union_expr; 132 133 } // namespace zorba 134 135 #endif 136 /* 137 * Local variables: 138 * mode: c++ 139 * End: 140 */ 141 /* vim:set et sw=2 ts=2: */ 142