~nbrinza/zorba/parse-fragment

« back to all changes in this revision

Viewing changes to src/functions/func_fn_hof_functions_impl.cpp

  • Committer: nbrinza at gmail
  • Date: 2013-04-09 14:34:55 UTC
  • mfrom: (10477.1.877 zorba)
  • Revision ID: nbrinza@gmail.com-20130409143455-wofxpaysvqjci57p
Merged with Zorba trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "stdafx.h"
 
17
 
 
18
#include "common/shared_types.h"
 
19
#include "types/typeops.h"
 
20
 
 
21
#include "functions/function.h"
 
22
#include "functions/function_impl.h"
 
23
#include "functions/func_fn_hof_functions.h"
 
24
 
 
25
#include "runtime/hof/fn_hof_functions.h"
 
26
 
 
27
#include "system/globalenv.h"
 
28
 
 
29
 
 
30
namespace zorba
 
31
{
 
32
 
 
33
/*******************************************************************************
 
34
 
 
35
********************************************************************************/
 
36
class fn_map_3_0 : public function
 
37
{
 
38
public:
 
39
  fn_map_3_0(const signature& sig, FunctionConsts::FunctionKind kind)
 
40
    :
 
41
    function(sig, kind)
 
42
  {
 
43
    theXQueryVersion = StaticContextConsts::xquery_version_3_0;
 
44
  }
 
45
 
 
46
  bool accessesDynCtx() const { return true; }
 
47
 
 
48
  PlanIter_t codegen(CompilerCB* cb,
 
49
                     static_context* sctx,
 
50
                     const QueryLoc& loc,
 
51
                     std::vector<PlanIter_t>& argv,
 
52
                     expr& ann) const
 
53
  {
 
54
    return NULL;
 
55
  }
 
56
};
 
57
 
 
58
 
 
59
/*******************************************************************************
 
60
 
 
61
********************************************************************************/
 
62
class fn_filter : public function
 
63
{
 
64
public:
 
65
  fn_filter(const signature& sig, FunctionConsts::FunctionKind kind)
 
66
    :
 
67
    function(sig, kind)
 
68
  {
 
69
    theXQueryVersion = StaticContextConsts::xquery_version_3_0;
 
70
  }
 
71
 
 
72
  bool accessesDynCtx() const { return true; }
 
73
 
 
74
  PlanIter_t codegen(CompilerCB* ccb,
 
75
                     static_context* sctx,
 
76
                     const QueryLoc& loc,
 
77
                     std::vector<PlanIter_t>& argv,
 
78
                     expr& ann) const
 
79
  {
 
80
    return NULL;
 
81
  }
 
82
};
 
83
 
 
84
 
 
85
/*******************************************************************************
 
86
 
 
87
********************************************************************************/
 
88
PlanIter_t fn_fold_left_3_0::codegen(
 
89
  CompilerCB* ccb,
 
90
  static_context* sctx,
 
91
  const QueryLoc& loc,
 
92
  std::vector<PlanIter_t>& argv,
 
93
  expr& ann) const
 
94
{
 
95
  return new FnFoldLeftIterator(sctx, loc, argv, false);
 
96
}
 
97
 
 
98
 
 
99
/*******************************************************************************
 
100
 
 
101
********************************************************************************/
 
102
PlanIter_t fn_fold_right_3_0::codegen(
 
103
  CompilerCB* ccb,
 
104
  static_context* sctx,
 
105
  const QueryLoc& loc,
 
106
  std::vector<PlanIter_t>& argv,
 
107
  expr& ann) const
 
108
{
 
109
  return new FnFoldLeftIterator(sctx, loc, argv, true);
 
110
}
 
111
 
 
112
 
 
113
/*******************************************************************************
 
114
 
 
115
********************************************************************************/
 
116
PlanIter_t fn_function_lookup_3_0::codegen(
 
117
  CompilerCB* ccb,
 
118
  static_context* sctx,
 
119
  const QueryLoc& loc,
 
120
  std::vector<PlanIter_t>& argv,
 
121
  expr& ann) const
 
122
{
 
123
  return new FunctionLookupIterator(sctx, loc, argv, ccb);
 
124
}
 
125
 
 
126
 
 
127
/*******************************************************************************
 
128
 
 
129
********************************************************************************/
 
130
void populate_context_hof_impl(static_context* sctx)
 
131
{
 
132
  {
 
133
    std::vector<xqtref_t> args;
 
134
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_ONE);
 
135
 
 
136
    xqtref_t hofParamType = GENV_TYPESYSTEM.create_function_type(
 
137
                   args,
 
138
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
139
                   TypeConstants::QUANT_ONE);
 
140
 
 
141
    DECL_WITH_KIND(sctx,
 
142
                   fn_map_3_0,
 
143
                   (createQName(static_context::W3C_FN_NS, "", "map"),
 
144
                   hofParamType,
 
145
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
146
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR),
 
147
                   FunctionConsts::FN_MAP_2);
 
148
  }
 
149
 
 
150
  {
 
151
    std::vector<xqtref_t> args;
 
152
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_ONE);
 
153
 
 
154
    xqtref_t hofParamType = GENV_TYPESYSTEM.create_function_type(
 
155
                   args,
 
156
                   GENV_TYPESYSTEM.BOOLEAN_TYPE_ONE,
 
157
                   TypeConstants::QUANT_ONE);
 
158
 
 
159
    DECL_WITH_KIND(sctx,
 
160
                   fn_filter,
 
161
                   (createQName(static_context::W3C_FN_NS, "", "filter"),
 
162
                   hofParamType,
 
163
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
164
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR),
 
165
                   FunctionConsts::FN_FILTER_2);
 
166
  }
 
167
 
 
168
  {
 
169
    std::vector<xqtref_t> args;
 
170
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_ONE);
 
171
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_ONE);
 
172
 
 
173
    xqtref_t hofParamType = GENV_TYPESYSTEM.create_function_type(
 
174
                   args,
 
175
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
176
                   TypeConstants::QUANT_ONE);
 
177
 
 
178
    DECL_WITH_KIND(sctx,
 
179
                   fn_map_pairs_3_0,
 
180
                   (createQName(static_context::W3C_FN_NS, "", "map-pairs"),
 
181
                   hofParamType,
 
182
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
183
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
184
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR),
 
185
                   FunctionConsts::FN_MAP_PAIRS_3);
 
186
  }
 
187
 
 
188
  {
 
189
    std::vector<xqtref_t> args;
 
190
    xqtref_t hofParamType;
 
191
    
 
192
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_STAR);
 
193
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_ONE);
 
194
    hofParamType = GENV_TYPESYSTEM.create_function_type(
 
195
                   args,
 
196
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
197
                   TypeConstants::QUANT_ONE);
 
198
 
 
199
    DECL_WITH_KIND(sctx,
 
200
                   fn_fold_left_3_0,
 
201
                   (createQName(static_context::W3C_FN_NS, "", "fold-left"),
 
202
                   hofParamType,
 
203
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
204
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
205
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR),
 
206
                   FunctionConsts::FN_FOLD_LEFT_3);
 
207
    
 
208
    args.clear();
 
209
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_ONE);
 
210
    args.push_back(GENV_TYPESYSTEM.ITEM_TYPE_STAR);
 
211
    hofParamType = GENV_TYPESYSTEM.create_function_type(
 
212
                   args,
 
213
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
214
                   TypeConstants::QUANT_ONE);
 
215
 
 
216
    DECL_WITH_KIND(sctx,
 
217
                   fn_fold_right_3_0,
 
218
                   (createQName(static_context::W3C_FN_NS, "", "fold-right"),
 
219
                   hofParamType,
 
220
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
221
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR,
 
222
                   GENV_TYPESYSTEM.ITEM_TYPE_STAR),
 
223
                   FunctionConsts::FN_FOLD_RIGHT_3);
 
224
  }
 
225
 
 
226
}
 
227
 
 
228
}
 
229
 
 
230
/* vim:set et sw=2 ts=2: */