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_FUNCTIONS_SIGNATURE_H 18 #define ZORBA_FUNCTIONS_SIGNATURE_H 19 20 #include "zorbautils/checked_vector.h" 21 22 #include "common/shared_types.h" 23 24 #include "types/root_typemanager.h" 25 26 namespace zorba { 27 28 #define VARIADIC_SIG_SIZE 1000000 29 30 /******************************************************************************* 31 32 By convention, theTypes[0] = return type 33 theTypes[1] = first param type 34 theTypes[2] = second param type 35 ... = ... 36 37 ********************************************************************************/ 38 class signature: public SimpleRCObject 39 { 40 protected: 41 store::Item_t theQName; 42 checked_vector<xqtref_t> theTypes; 43 bool theIsVariadic; 44 45 public: 46 SERIALIZABLE_CLASS(signature) 47 SERIALIZABLE_CLASS_CONSTRUCTOR2(signature, SimpleRCObject) 48 void serialize(::zorba::serialization::Archiver& ar); 49 50 public: 51 signature( 52 const store::Item_t& name, 53 const xqtref_t& paramType1, 54 bool variadic, 55 const xqtref_t& returnType); 56 57 signature( 58 const store::Item_t& name, 59 const xqtref_t& paramType1, 60 const xqtref_t& paramType2, 61 bool variadic, 62 const xqtref_t& returnType); 63 64 signature( 65 const store::Item_t& name, 66 const xqtref_t& returnType); 67 68 signature( 69 const store::Item_t& name, 70 const xqtref_t& paramType1, 71 const xqtref_t& returnType); 72 73 signature( 74 const store::Item_t& name, 75 const xqtref_t& paramType1, 76 const xqtref_t& paramType2, 77 const xqtref_t& returnType); 78 79 signature( 80 const store::Item_t& name, 81 const xqtref_t& paramType1, 82 const xqtref_t& paramType2, 83 const xqtref_t& paramType3, 84 const xqtref_t& returnType); 85 86 signature( 87 const store::Item_t& name, 88 const xqtref_t& paramType1, 89 const xqtref_t& paramType2, 90 const xqtref_t& paramType3, 91 const xqtref_t& paramType4, 92 const xqtref_t& returnType); 93 94 signature( 95 const store::Item_t& name, 96 const xqtref_t& paramType1, 97 const xqtref_t& paramType2, 98 const xqtref_t& paramType3, 99 const xqtref_t& paramType4, 100 const xqtref_t& paramType5, 101 const xqtref_t& returnType); 102 103 signature( 104 const store::Item_t& name, 105 const xqtref_t& paramType1, 106 const xqtref_t& paramType2, 107 const xqtref_t& paramType3, 108 const xqtref_t& paramType4, 109 const xqtref_t& paramType5, 110 const xqtref_t& paramType6, 111 const xqtref_t& returnType); 112 113 signature( 114 const store::Item_t& name, 115 const xqtref_t& paramType1, 116 const xqtref_t& paramType2, 117 const xqtref_t& paramType3, 118 const xqtref_t& paramType4, 119 const xqtref_t& paramType5, 120 const xqtref_t& paramType6, 121 const xqtref_t& paramType7, 122 const xqtref_t& returnType); 123 124 signature( 125 const store::Item_t& name, 126 const xqtref_t& paramType1, 127 const xqtref_t& paramType2, 128 const xqtref_t& paramType3, 129 const xqtref_t& paramType4, 130 const xqtref_t& paramType5, 131 const xqtref_t& paramType6, 132 const xqtref_t& paramType7, 133 const xqtref_t& paramType8, 134 const xqtref_t& returnType); 135 136 signature( 137 const store::Item_t& name, 138 const std::vector<xqtref_t>& paramTypes, 139 const xqtref_t& returnType, 140 bool isVariadic = false); 141 getName()142 store::Item* getName() const { return theQName.getp(); } 143 isVariadic()144 bool isVariadic() const { return theIsVariadic; } 145 paramCount()146 size_t paramCount() const 147 { 148 return isVariadic() ? VARIADIC_SIG_SIZE : (uint32_t)(theTypes.size() - 1); 149 } 150 definedParamCount()151 size_t definedParamCount() const 152 { 153 return (uint32_t)(theTypes.size() - 1); 154 } 155 156 xqtref_t const& operator[](int i) const 157 { 158 return theTypes[theIsVariadic 159 ? i >= (int)theTypes.size() - 1 160 ? theTypes.size() - 1 161 : i + 1 162 : i + 1]; 163 } 164 165 xqtref_t& operator[](int i) 166 { 167 return theTypes[theIsVariadic 168 ? i >= (int)theTypes.size() - 1 169 ? theTypes.size() - 1 170 : i + 1 171 : i + 1]; 172 } 173 returnType()174 const xqtref_t& returnType() const { return theTypes[0]; } 175 returnType()176 xqtref_t& returnType() { return theTypes[0]; } 177 178 bool equals( 179 const TypeManager* tm, 180 const signature& s, 181 const QueryLoc& loc) const; 182 183 bool subtype( 184 const TypeManager* tm, 185 const signature& s, 186 const QueryLoc& loc) const; 187 }; 188 189 } /* namespace zorba */ 190 #endif /* ZORBA_SIGNATURE_H */ 191 192 193 /* 194 * Local variables: 195 * mode: c++ 196 * End: 197 */ 198 /* vim:set et sw=2 ts=2: */ 199