~zorba-coders/zorba/xqueryx_fulltext

« back to all changes in this revision

Viewing changes to src/functions/func_accessors_impl.cpp

  • Committer: Tarmac
  • Author(s): Markos Zaharioudakis, Carlos Lopez
  • Date: 2011-12-20 10:30:38 UTC
  • mfrom: (10564.3.3 fn-type-inference)
  • Revision ID: tarmac-20111220103038-7w8qy4e7o2sfoh6r
Changed functions to use getReturnType(const fo_expr*) const instead of the old one recieving a TypeManager* and std::vector<xqtref_t>.
 Approved: Markos Zaharioudakis

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "runtime/accessors/accessors.h"
21
21
 
22
22
#include "compiler/expression/expr_base.h"
 
23
#include "compiler/expression/fo_expr.h"
23
24
 
24
25
#include "functions/func_accessors_impl.h"
25
26
#include "functions/func_accessors.h"
31
32
#include "zorbamisc/ns_consts.h"
32
33
 
33
34
 
34
 
namespace zorba 
 
35
namespace zorba
35
36
{
36
37
 
37
38
/*******************************************************************************
38
 
  
 
39
 
39
40
********************************************************************************/
40
41
BoolAnnotationValue fn_data::ignoresSortedNodes(expr* fo, ulong input) const
41
42
{
49
50
}
50
51
 
51
52
 
52
 
xqtref_t fn_data::getReturnType(
53
 
    const TypeManager* tm,
54
 
    const std::vector<xqtref_t>& arg_types) const
 
53
xqtref_t fn_data::getReturnType(const fo_expr* caller) const
55
54
{
 
55
  const QueryLoc& loc = caller->get_loc();
 
56
 
 
57
  TypeManager* tm = caller->get_type_manager();
56
58
  RootTypeManager& RTM = GENV_TYPESYSTEM;
57
59
 
58
 
  if (TypeOps::is_subtype(tm, *arg_types[0], *RTM.ANY_ATOMIC_TYPE_STAR, QueryLoc::null))
59
 
    return arg_types[0];  // includes () case
60
 
 
61
 
  const XQType& argType = *arg_types[0];
62
 
  TypeConstants::quantifier_t q = TypeOps::quantifier(argType);
63
 
 
64
 
  if (argType.type_kind() == XQType::NODE_TYPE_KIND)
 
60
  xqtref_t argType = caller->get_arg(0)->get_return_type();
 
61
 
 
62
  if (TypeOps::is_subtype(tm, *argType, *RTM.ANY_ATOMIC_TYPE_STAR, loc))
 
63
    return argType; // includes () case
 
64
 
 
65
  TypeConstants::quantifier_t q = TypeOps::quantifier(*argType);
 
66
 
 
67
  if (argType->type_kind() == XQType::NODE_TYPE_KIND)
65
68
  {
66
 
    const NodeXQType& nType = static_cast<const NodeXQType&>(argType);
 
69
    const NodeXQType& nType = static_cast<const NodeXQType&>(*argType);
67
70
 
68
71
    store::StoreConsts::NodeKind nodeKind = nType.get_node_kind();
69
72
 
78
81
    {
79
82
      return tm->create_builtin_atomic_type(TypeConstants::XS_UNTYPED_ATOMIC, q);
80
83
    }
81
 
    
 
84
 
82
85
    xqtref_t cType = nType.get_content_type();
83
86
    if (cType != NULL)
84
87
    {
92
95
      {
93
96
        return tm->create_builtin_atomic_type(TypeConstants::XS_UNTYPED_ATOMIC, q);
94
97
      }
95
 
      else if (TypeOps::is_subtype(tm, *cType, *RTM.ANY_ATOMIC_TYPE_STAR, QueryLoc::null))
 
98
      else if (TypeOps::is_subtype(tm, *cType, *RTM.ANY_ATOMIC_TYPE_STAR, loc))
96
99
      {
97
100
        return tm->create_type(*cType, q);
98
101
      }
99
102
    }
100
103
  }
101
104
 
102
 
  return tm->create_builtin_atomic_type(TypeConstants::XS_ANY_ATOMIC,
103
 
                                        TypeConstants::QUANT_STAR);
 
105
  return RTM.ANY_ATOMIC_TYPE_STAR;
104
106
}
105
107
 
 
108
 
106
109
/*******************************************************************************
107
 
  
 
110
  fn_data_3_0 is converted to fn_data during translation
108
111
********************************************************************************/
109
 
BoolAnnotationValue fn_data_3_0::ignoresSortedNodes(expr* fo, ulong input) const
110
 
{
111
 
  return fo->getIgnoresSortedNodes();
112
 
}
113
 
 
114
 
 
115
 
BoolAnnotationValue fn_data_3_0::ignoresDuplicateNodes(expr* fo, ulong input) const
116
 
{
117
 
  return fo->getIgnoresDuplicateNodes();
118
 
}
119
 
 
120
 
 
121
 
xqtref_t fn_data_3_0::getReturnType(
122
 
    const TypeManager* tm,
123
 
    const std::vector<xqtref_t>& arg_types) const
124
 
{
125
 
  return tm->create_builtin_atomic_type(TypeConstants::XS_ANY_ATOMIC,
126
 
                                        TypeConstants::QUANT_STAR);
 
112
class fn_data_3_0 : public function
 
113
{
 
114
public:
 
115
  fn_data_3_0(const signature& sig, FunctionConsts::FunctionKind kind)
 
116
    :
 
117
    function(sig, kind) 
 
118
  {
 
119
    theXQueryVersion = StaticContextConsts::xquery_version_3_0;
 
120
  }
 
121
 
 
122
  CODEGEN_DECL();
 
123
};
 
124
 
 
125
 
 
126
PlanIter_t fn_data_3_0::codegen(
 
127
  CompilerCB*,
 
128
  static_context* sctx,
 
129
  const QueryLoc& loc,
 
130
  std::vector<PlanIter_t>& argv,
 
131
  AnnotationHolder& ann) const
 
132
{
 
133
  ZORBA_ASSERT(false);
127
134
}
128
135
 
129
136
 
130
137
/*******************************************************************************
131
 
  
 
138
 
132
139
********************************************************************************/
133
140
PlanIter_t fn_name_func::codegen(
134
141
    CompilerCB* /*cb*/,
145
152
 
146
153
 
147
154
/*******************************************************************************
148
 
  
 
155
 
149
156
********************************************************************************/
150
157
PlanIter_t fn_string::codegen(
151
158
      CompilerCB* /*cb*/,
159
166
 
160
167
 
161
168
/*******************************************************************************
162
 
  
 
169
 
163
170
********************************************************************************/
164
171
void populate_context_accessors_impl(static_context* sctx)
165
172
{
166
173
  DECL(sctx, fn_name_func,
167
174
       (createQName(static_context::W3C_FN_NS.c_str(), "", "name"),
168
 
      GENV_TYPESYSTEM.STRING_TYPE_ONE));
 
175
        GENV_TYPESYSTEM.STRING_TYPE_ONE));
169
176
 
170
177
  DECL(sctx, fn_name_func,
171
178
       (createQName(static_context::W3C_FN_NS.c_str(), "", "name"),
172
179
        GENV_TYPESYSTEM.ANY_NODE_TYPE_QUESTION,
173
180
        GENV_TYPESYSTEM.STRING_TYPE_ONE));
 
181
 
 
182
  DECL_WITH_KIND(sctx, fn_data_3_0,
 
183
                 (createQName("http://www.w3.org/2005/xpath-functions","","data"), 
 
184
                  GENV_TYPESYSTEM.ANY_ATOMIC_TYPE_STAR),
 
185
                  FunctionConsts::FN_DATA_0);
174
186
}
175
187
 
176
188