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_API_ANNOTATIONS_H 18 #define ZORBA_API_ANNOTATIONS_H 19 20 #include <vector> 21 #include <bitset> 22 23 #include "common/shared_types.h" 24 25 //#include "compiler/parsetree/parsenodes.h" 26 27 #include "zorbautils/hashmap_itemh.h" 28 29 namespace zorba 30 { 31 32 class AnnotationInternal; 33 class AnnotationList; 34 35 typedef rchandle<AnnotationInternal> AnnotationInternal_t; 36 typedef rchandle<AnnotationList> AnnotationList_t; 37 38 class const_expr; 39 40 /******************************************************************************* 41 Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")? 42 ********************************************************************************/ 43 class AnnotationInternal : public SimpleRCObject 44 { 45 friend class AnnotationList; 46 47 public: 48 enum AnnotationId 49 { 50 fn_public = 0, 51 fn_private, 52 zann_deterministic, 53 zann_nondeterministic, 54 zann_assignable, 55 zann_nonassignable, 56 zann_sequential, 57 zann_nonsequential, 58 zann_propagates_input_nodes, 59 zann_must_copy_input_nodes, 60 zann_cache, 61 zann_nocache, 62 zann_variadic, 63 zann_streamable, 64 zann_unique, 65 zann_nonunique, 66 zann_value_equality, 67 zann_general_equality, 68 zann_value_range, 69 zann_general_range, 70 zann_automatic, 71 zann_manual, 72 zann_mutable, 73 zann_queue, 74 zann_append_only, 75 zann_const, 76 zann_ordered, 77 zann_unordered, 78 zann_read_only_nodes, 79 zann_mutable_nodes, 80 81 // must be at the end 82 zann_end 83 }; 84 85 protected: 86 typedef std::bitset<static_cast<int>(zann_end) + 1> RuleBitSet; 87 88 protected: 89 static std::vector<store::Item_t> theAnnotId2NameMap; 90 91 static ItemHandleHashMap<AnnotationId> theAnnotName2IdMap; 92 93 static std::vector<RuleBitSet> theRuleSet; 94 95 protected: 96 AnnotationId theId; 97 store::Item_t theQName; 98 std::vector<store::Item_t> theLiterals; 99 100 public: 101 static void createBuiltIn(); 102 103 static void destroyBuiltIn(); 104 105 static AnnotationId lookup(const store::Item_t& qname); 106 107 static store::Item* lookup(AnnotationId id); 108 109 public: 110 AnnotationInternal(const store::Item_t& qname); 111 112 AnnotationInternal( 113 const store::Item_t& qname, 114 std::vector<store::Item_t>& literals); 115 116 public: 117 SERIALIZABLE_CLASS(AnnotationInternal); 118 SERIALIZABLE_CLASS_CONSTRUCTOR2(AnnotationInternal, SimpleRCObject) 119 void serialize(::zorba::serialization::Archiver& ar); 120 121 public: ~AnnotationInternal()122 ~AnnotationInternal() { }; 123 getId()124 AnnotationId getId() const { return theId; } 125 126 const store::Item* getQName() const; 127 128 csize getNumLiterals() const; 129 130 store::Item* getLiteral(csize index) const; 131 }; 132 133 134 /******************************************************************************* 135 AnnotationList := Annotation* 136 137 Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")? 138 ********************************************************************************/ 139 class AnnotationList : public SimpleRCObject 140 { 141 public: 142 typedef AnnotationInternal::RuleBitSet RuleBitSet; 143 144 typedef AnnotationInternal::AnnotationId AnnotationId; 145 146 typedef std::vector<AnnotationInternal_t> List_t; 147 148 typedef List_t::const_iterator ListConstIter_t; 149 150 protected: 151 List_t theAnnotationList; 152 153 public: 154 SERIALIZABLE_CLASS(AnnotationList); 155 SERIALIZABLE_CLASS_CONSTRUCTOR2(AnnotationList, SimpleRCObject) 156 void serialize(::zorba::serialization::Archiver& ar); 157 158 public: 159 AnnotationList(); 160 161 ~AnnotationList(); 162 size()163 csize size() const { return theAnnotationList.size(); } 164 165 AnnotationInternal* get(csize index) const; 166 167 AnnotationInternal* get(AnnotationInternal::AnnotationId id) const; 168 169 bool contains(AnnotationInternal::AnnotationId id) const; 170 171 void push_back( 172 const store::Item_t& qname, 173 const std::vector<const_expr*>& literals); 174 175 void checkConflictingDeclarations(const QueryLoc& loc) const; 176 }; 177 178 179 } /* namespace zorba */ 180 #endif 181 182 /* 183 * Local variables: 184 * mode: c++ 185 * End: 186 */ 187 /* vim:set et sw=2 ts=2: */ 188