zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #11381
[Merge] lp:~zorba-coders/zorba/expr-memman into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/expr-memman into lp:zorba.
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/expr-memman/+merge/112184
New memory management for compiler expressions
--
https://code.launchpad.net/~zorba-coders/zorba/expr-memman/+merge/112184
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/compiler/api/compilercb.cpp'
--- src/compiler/api/compilercb.cpp 2012-06-18 10:06:47 +0000
+++ src/compiler/api/compilercb.cpp 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +30,7 @@
#include "zorbaserialization/serialize_zorba_types.h"
-namespace zorba
+namespace zorba
{
SERIALIZABLE_CLASS_VERSIONS(CompilerCB)
@@ -80,7 +80,7 @@
/*******************************************************************************
********************************************************************************/
-CompilerCB::config::config(::zorba::serialization::Archiver& ar)
+CompilerCB::config::config(::zorba::serialization::Archiver& ar)
:
parse_cb(NULL),
translate_cb(NULL),
@@ -119,7 +119,8 @@
theIsSequential(false),
theHaveTimeout(false),
theTimeout(timeout),
- theTempIndexCounter(0)
+ theTempIndexCounter(0),
+ theExprManager()
{
if (timeout >= 0)
theHaveTimeout = true;
@@ -128,7 +129,7 @@
/*******************************************************************************
Used by the eval iterator to create a new ccb as a copy of the ccb of the
- enclosing query.
+ enclosing query.
*******************************************************************************/
CompilerCB::CompilerCB(const CompilerCB& cb)
:
@@ -146,7 +147,8 @@
theHaveTimeout(cb.theHaveTimeout),
theTimeout(cb.theTimeout),
theTempIndexCounter(0),
- theConfig(cb.theConfig)
+ theConfig(cb.theConfig),
+ theExprManager()
{
}
@@ -162,8 +164,13 @@
#ifdef ZORBA_WITH_DEBUGGER
theDebuggerCommons(NULL),
#endif
+<<<<<<< TREE
theHasEval(false),
theIsEval(false)
+=======
+ theIsEval(false),
+ theExprManager()
+>>>>>>> MERGE-SOURCE
{
}
@@ -171,7 +178,7 @@
/*******************************************************************************
********************************************************************************/
-CompilerCB::~CompilerCB()
+CompilerCB::~CompilerCB()
{
}
@@ -190,7 +197,7 @@
#ifdef ZORBA_WITH_DEBUGGER
ar & theDebuggerCommons;
#endif
- if (!ar.is_serializing_out())
+ if (!ar.is_serializing_out())
{
//don't serialize this
theXQueryDiagnostics = NULL;
=== modified file 'src/compiler/api/compilercb.h'
--- src/compiler/api/compilercb.h 2012-06-18 10:06:47 +0000
+++ src/compiler/api/compilercb.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,6 +32,9 @@
#include "zorbaserialization/class_serializer.h"
+#include "compiler/expression/mem_manager.h"
+#include "compiler/expression/expr_manager.h"
+
namespace zorba {
#ifdef ZORBA_WITH_DEBUGGER
@@ -57,7 +60,7 @@
A query-level (or eval-level) map that stores the sctx objs that need to be
kept around for the whole duration of a query (including runtime). In non-
DEBUGGER mode, the map stores only for root sctx of each module. In DEBUGGER
- mode, it stores all the sctxs created by each module. Each sctx stored in
+ mode, it stores all the sctxs created by each module. Each sctx stored in
this map has an associated numeric id, and theSctxMap actually maps these
numeric ids to their associated sctx objs. The map is modified by the methods
TranslatorImpl::end_visit(ModuleImport) and TranslatorImpl::push_scope().
@@ -87,9 +90,14 @@
Whether this is a load-prolog query or not (load-prolog queries are created
internally by the StaticContextImpl::loadProlog() method).
+<<<<<<< TREE
theIsUpdating :
---------------
Set to true if the root expr of the query or eval expr is an updating expr.
+=======
+ - theIsUpdating :
+ Set to true if the root expr of the query or eval expr is an updating expr.
+>>>>>>> MERGE-SOURCE
theTimeout :
------------
@@ -124,13 +132,13 @@
public:
struct config : public zorba::serialization::SerializeBaseClass
{
- typedef enum
+ typedef enum
{
O0,
O1,
O2
} opt_level_t;
-
+
typedef void (* expr_callback) (const expr *, const std::string& name);
typedef void (* ast_callback) (const parsenode *, const std::string& name);
@@ -157,7 +165,7 @@
typedef std::map<csize, static_context_t> SctxMap;
-public:
+public:
XQueryDiagnostics * theXQueryDiagnostics;
SctxMap theSctxMap;
@@ -186,6 +194,13 @@
config theConfig;
+<<<<<<< TREE
+=======
+ rchandle<rclist<user_function*> > theLocalUdfs;//for plan serializer
+
+ ExprManager theExprManager;
+
+>>>>>>> MERGE-SOURCE
public:
SERIALIZABLE_CLASS(CompilerCB);
CompilerCB(::zorba::serialization::Archiver& ar);
@@ -211,6 +226,11 @@
bool isSequential() const { return theIsSequential;}
static_context* getStaticContext(int id);
+
+ ExprManager& getExprManager() {return theExprManager;}
+
+ MemoryManager& getMemoryManager() {return theExprManager.getMemory();}
+
};
=== modified file 'src/compiler/expression/CMakeLists.txt'
--- src/compiler/expression/CMakeLists.txt 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/CMakeLists.txt 2012-06-26 18:33:24 +0000
@@ -26,7 +26,9 @@
fo_expr.cpp
script_exprs.cpp
update_exprs.cpp
- function_item_expr.cpp)
+ function_item_expr.cpp
+ mem_manager.cpp
+ expr_manager.cpp)
IF (NOT ZORBA_NO_FULL_TEXT)
LIST(APPEND EXPRESSION_SRCS
=== modified file 'src/compiler/expression/expr.h'
--- src/compiler/expression/expr.h 2012-06-21 09:42:44 +0000
+++ src/compiler/expression/expr.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -37,9 +37,13 @@
#include "store/api/item.h"
+<<<<<<< TREE
#include "runtime/core/sequencetypes.h"
namespace zorba
+=======
+namespace zorba
+>>>>>>> MERGE-SOURCE
{
class expr_visitor;
@@ -51,7 +55,7 @@
/*******************************************************************************
[68] IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
********************************************************************************/
-class if_expr : public expr
+class if_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -88,13 +92,13 @@
/***************************************************************************//**
********************************************************************************/
-class order_expr : public expr
+class order_expr : public expr
{
friend class ExprIterator;
friend class expr;
public:
- enum order_type_t
+ enum order_type_t
{
ordered,
unordered
@@ -124,7 +128,7 @@
/***************************************************************************//**
********************************************************************************/
-class validate_expr : public expr
+class validate_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -187,7 +191,7 @@
/***************************************************************************//**
Base for cast, treat, promote, castable, instanceof
********************************************************************************/
-class cast_or_castable_base_expr : public expr
+class cast_or_castable_base_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -201,9 +205,15 @@
static_context* sctx,
const QueryLoc& loc,
expr_kind_t kind,
+<<<<<<< TREE
const expr_t& input,
const xqtref_t& type);
+=======
+ expr_t input,
+ xqtref_t type);
+
+>>>>>>> MERGE-SOURCE
public:
expr* get_input() const { return theInputExpr.getp(); }
@@ -224,11 +234,19 @@
public:
cast_base_expr(
+<<<<<<< TREE
static_context* sctx,
const QueryLoc& loc,
expr_kind_t kind,
const expr_t& input,
const xqtref_t& type);
+=======
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_kind_t kind,
+ expr_t input,
+ xqtref_t type);
+>>>>>>> MERGE-SOURCE
};
@@ -265,10 +283,10 @@
static type of theInputExpr is a subtype of the prime type of
theTargetType.
- theFnQName : Stores the QName of the function, if the treat expr is used
+ theFnQName : Stores the QName of the function, if the treat expr is used
to cast the function's body to its result type
********************************************************************************/
-class treat_expr : public cast_base_expr
+class treat_expr : public cast_base_expr
{
friend class ExprIterator;
friend class expr;
@@ -280,11 +298,19 @@
public:
treat_expr(
+<<<<<<< TREE
static_context* sctx,
const QueryLoc& loc,
const expr_t& input,
const xqtref_t& type,
TreatIterator::ErrorKind err,
+=======
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ xqtref_t,
+ Error const&,
+>>>>>>> MERGE-SOURCE
bool check_prime = true,
store::Item* qname = NULL);
@@ -323,7 +349,7 @@
- If the target type is the NONE type, F(I) = error, else
- If the actual type is a subtype of the target type, F(I) = I, else
- If the target type is not an atomic type, F(I) = error, else
- - If the actual type is untypedAtomic and the target type is not QName,
+ - If the actual type is untypedAtomic and the target type is not QName,
F(I) = cast(I, target type), else
- If the actual type is (subtype of) decimal and the target type is float,
F(I) = cast(I, target type), else
@@ -347,17 +373,31 @@
friend class expr;
protected:
+<<<<<<< TREE
PromoteIterator::ErrorKind theErrorKind;
store::Item_t theQName;
+=======
+ store::Item_t theFnQName; // Stores the QName of the function, if the promote expr
+ // is used to cast the function's body to its result type
+
+>>>>>>> MERGE-SOURCE
public:
promote_expr(
+<<<<<<< TREE
static_context* sctx,
const QueryLoc& loc,
const expr_t& input,
const xqtref_t& type,
PromoteIterator::ErrorKind err,
store::Item* qname);
+=======
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t input,
+ xqtref_t type,
+ store::Item_t fnQname = NULL);
+>>>>>>> MERGE-SOURCE
expr_t clone(substitution_t& s) const;
@@ -376,7 +416,7 @@
/***************************************************************************//**
Base for castable, instanceof
********************************************************************************/
-class castable_base_expr : public cast_or_castable_base_expr
+class castable_base_expr : public cast_or_castable_base_expr
{
friend class ExprIterator;
@@ -395,14 +435,24 @@
SingleType ::= AtomicType "?"?
********************************************************************************/
-class castable_expr : public castable_base_expr
+class castable_expr : public castable_base_expr
{
friend class ExprIterator;
friend class expr;
public:
+<<<<<<< TREE
castable_expr(static_context* sctx, const QueryLoc&, const expr_t&, const xqtref_t&);
+=======
+ SERIALIZABLE_CLASS(castable_expr)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(castable_expr, castable_base_expr)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ castable_expr(static_context* sctx, const QueryLoc&, expr_t, xqtref_t);
+
+>>>>>>> MERGE-SOURCE
bool is_optional() const;
expr_t clone(substitution_t& s) const;
@@ -416,13 +466,13 @@
/***************************************************************************//**
InstanceofExpr ::= TreatExpr ( "instance" "of" SequenceType )?
- theCheckPrimeOnly :
+ theCheckPrimeOnly :
Normally, this is false. It is set to true only if this is an instanceof expr
that is created during the translation of a PredicateList (see translator.cpp).
This flag is used during the PartialEval rule.
********************************************************************************/
-class instanceof_expr : public castable_base_expr
+class instanceof_expr : public castable_base_expr
{
friend class ExprIterator;
friend class expr;
@@ -433,9 +483,15 @@
public:
instanceof_expr(
static_context* sctx,
+<<<<<<< TREE
const QueryLoc&,
const expr_t&,
const xqtref_t&,
+=======
+ const QueryLoc&,
+ expr_t,
+ xqtref_t,
+>>>>>>> MERGE-SOURCE
bool checkPrimeOnly = false);
bool getCheckPrimeOnly() const { return theCheckPrimeOnly; }
@@ -492,7 +548,7 @@
/***************************************************************************//**
CompDocConstructor ::= "document" "{" Expr "}"
********************************************************************************/
-class doc_expr : public expr
+class doc_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -566,7 +622,7 @@
expr* content,
const namespace_context* nsCtx,
bool copyNodes);
-
+
elem_expr(
static_context* sctx,
const QueryLoc&,
@@ -574,7 +630,7 @@
expr* content,
const namespace_context* nsCtx,
bool copyNodes);
-
+
expr* getQNameExpr() const { return theQNameExpr.getp(); }
expr* getContent() const { return theContent.getp(); }
@@ -586,8 +642,8 @@
void setCopyInputNodes() { theCopyInputNodes = true; }
void compute_scripting_kind();
-
- expr_t clone(substitution_t& s) const;
+
+ expr_t clone(substitution_t& s) const;
void accept(expr_visitor&);
@@ -619,7 +675,7 @@
CommonContent ::= PredefinedEntityRef | CharRef | "{{" | "}}" | EnclosedExpr
********************************************************************************/
-class attr_expr : public expr
+class attr_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -654,13 +710,13 @@
/***************************************************************************//**
********************************************************************************/
-class text_expr : public expr
+class text_expr : public expr
{
friend class ExprIterator;
friend class expr;
public:
- typedef enum
+ typedef enum
{
text_constructor,
comment_constructor
@@ -683,7 +739,7 @@
void compute_scripting_kind();
- expr_t clone(substitution_t& s) const;
+ expr_t clone(substitution_t& s) const;
void accept(expr_visitor&);
@@ -694,7 +750,7 @@
/***************************************************************************//**
********************************************************************************/
-class pi_expr : public expr
+class pi_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -705,14 +761,14 @@
public:
pi_expr(static_context* sctx, const QueryLoc&, expr_t, expr_t);
-
+
expr* get_target_expr() const { return theTargetExpr.getp(); }
expr* get_content_expr() const { return theContentExpr.getp(); }
void compute_scripting_kind();
-
- expr_t clone(substitution_t& s) const;
+
+ expr_t clone(substitution_t& s) const;
void accept(expr_visitor&);
@@ -723,7 +779,7 @@
/***************************************************************************//**
********************************************************************************/
-class const_expr : public expr
+class const_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -746,7 +802,7 @@
const_expr(static_context* sctx, const QueryLoc&, xs_boolean);
- const_expr(static_context* sctx, const QueryLoc&, store::Item_t);
+ const_expr(static_context* sctx, const QueryLoc&, store::Item_t);
const_expr(static_context* sctx, const QueryLoc&, const char* ns, const char* pre, const char* local);
@@ -781,7 +837,7 @@
/***************************************************************************//**
********************************************************************************/
-class extension_expr : public expr
+class extension_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -836,7 +892,7 @@
typedef rchandle<catch_clause> catch_clause_t;
-class catch_clause : public SimpleRCObject
+class catch_clause : public SimpleRCObject
{
friend class expr;
friend class trycatch_expr;
@@ -861,27 +917,27 @@
protected:
nt_list_t theNameTests;
var_map_t theVarMap;
-
+
public:
catch_clause();
-
+
void set_nametests(nt_list_t& a) { theNameTests = a; }
nt_list_t& get_nametests() { return theNameTests; }
-
+
void add_nametest_h(nt_t n) { theNameTests.push_back(n); }
void set_vars(var_map_t& a) { theVarMap = a; }
var_map_t& get_vars() { return theVarMap; }
-
+
void add_var(var_type v, var_expr_t n) { theVarMap[v] = n; }
-
+
catch_clause_t clone(expr::substitution_t& subst) const;
};
-class trycatch_expr : public expr
+class trycatch_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -903,9 +959,9 @@
void add_catch_expr(expr_t e);
void add_clause(catch_clause_t cc);
-
+
csize clause_count() const { return theCatchClauses.size(); }
-
+
const catch_clause_t& operator[](csize i) const { return theCatchClauses[i]; }
void compute_scripting_kind();
@@ -929,7 +985,7 @@
Normally, it is used to wrap a var_expr in order to represent a var reference
(see var_expr.h). But it may wrap any other kind of expr as well.
********************************************************************************/
-class wrapper_expr : public expr
+class wrapper_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -1018,7 +1074,7 @@
{
return theFunctionCallLocation;
}
-
+
void setFunctionArity(unsigned int arity)
{
theFunctionArity = arity;
@@ -1075,7 +1131,7 @@
eval_expr(
CompilerCB* ccb,
static_context* sctx,
- const QueryLoc& loc,
+ const QueryLoc& loc,
const expr_t& e,
expr_script_kind_t scriptingKind,
namespace_context* nsCtx);
@@ -1088,7 +1144,7 @@
const var_expr* get_var(csize i) const { return theVars[i]; }
- void add_var(const var_expr_t& var, const expr_t& arg)
+ void add_var(const var_expr_t& var, const expr_t& arg)
{
theVars.push_back(var);
theArgs.push_back(arg);
@@ -1158,7 +1214,7 @@
const var_expr* get_var(csize i) const { return theVars[i]; }
- void add_var(const var_expr_t& var, const expr_t& arg)
+ void add_var(const var_expr_t& var, const expr_t& arg)
{
theVars.push_back(var);
theArgs.push_back(arg);
=== modified file 'src/compiler/expression/expr_base.h'
--- src/compiler/expression/expr_base.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/expr_base.h 2012-06-26 18:33:24 +0000
@@ -197,6 +197,12 @@
public:
expr() : theSctx(NULL), theFlags1(0) {}
+<<<<<<< TREE
+=======
+ virtual void free() {}
+
+public:
+>>>>>>> MERGE-SOURCE
expr(static_context*, const QueryLoc&, expr_kind_t);
virtual ~expr();
=== modified file 'src/compiler/expression/expr_classes.h'
--- src/compiler/expression/expr_classes.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/expr_classes.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,38 +17,38 @@
#include <zorba/config.h>
#include "common/shared_types.h"
-namespace zorba
+namespace zorba
{
- class order_modifier;
- class flwor_expr;
- class case_clause;
- class if_expr;
+ class order_modifier;
+ class flwor_expr;
+ class case_clause;
+ class if_expr;
class fo_expr;
#ifndef ZORBA_NO_FULL_TEXT
class ftcontains_expr;
#endif /* ZORBA_NO_FULL_TEXT */
class promote_expr;
- class instanceof_expr;
- class treat_expr;
- class castable_expr;
- class cast_expr;
+ class instanceof_expr;
+ class treat_expr;
+ class castable_expr;
+ class cast_expr;
class name_cast_expr;
- class validate_expr;
- class extension_expr;
+ class validate_expr;
+ class extension_expr;
class relpath_expr;
- class axis_step_expr;
- class match_expr;
+ class axis_step_expr;
+ class match_expr;
class const_expr;
- class order_expr;
+ class order_expr;
- class elem_expr;
+ class elem_expr;
class doc_expr;
class attr_expr;
class text_expr;
class pi_expr;
class trycatch_expr;
- class function_item_expr;
+ class function_item_expr;
class dynamic_function_invocation_expr;
class insert_expr;
@@ -57,16 +57,16 @@
class rename_expr;
class transform_expr;
- class block_expr;
+ class block_expr;
class apply_expr;
class var_decl_expr;
class var_set_expr;
class exit_expr;
- class exit_catcher_expr;
- class while_expr;
+ class exit_catcher_expr;
+ class while_expr;
class flowctl_expr;
- class eval_expr;
+ class eval_expr;
class debugger_expr;
class function_trace_expr;
class wrapper_expr;
=== modified file 'src/compiler/expression/expr_consts.h'
--- src/compiler/expression/expr_consts.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/expr_consts.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,7 @@
#ifndef ZORBA_COMPILER_EXPR_CONSTS_H
#define ZORBA_COMPILER_EXPR_CONSTS_H
-namespace zorba
+namespace zorba
{
@@ -77,16 +77,16 @@
// expr may return non-empty XDM as well.
VAR_SETTING_EXPR = 8, // An expr E during the evaluation of which a
- // var may be set and that var is declared
+ // var may be set and that var is declared
// outside the innermost block that contains E.
- APPLYING_EXPR = 16, // An expr during the evaluation of which a
+ APPLYING_EXPR = 16, // An expr during the evaluation of which a
// PUL may get applied.
EXITING_EXPR = 32, // An expr during the evaluation of which an
// exit expression may be executed.
- BREAKING_EXPR = 64, // An expr E during the evaluation of which
+ BREAKING_EXPR = 64, // An expr E during the evaluation of which
// a break or continue expr may be executed
// and the the while or flwor expr being
// broken or continued contains E.
@@ -105,7 +105,7 @@
};
-class CompareConsts
+class CompareConsts
{
public:
enum CompareType
@@ -121,7 +121,7 @@
};
-class ArithmeticConsts
+class ArithmeticConsts
{
public:
enum OperationKind
=== added file 'src/compiler/expression/expr_manager.cpp'
--- src/compiler/expression/expr_manager.cpp 1970-01-01 00:00:00 +0000
+++ src/compiler/expression/expr_manager.cpp 2012-06-26 18:33:24 +0000
@@ -0,0 +1,681 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "expr_manager.h"
+
+#include "mem_manager.h"
+
+#include "expr.h"
+#include "ftnode.h"
+#include "var_expr.h"
+#include "flwor_expr.h"
+#include "fo_expr.h"
+#include "ft_expr.h"
+#include "function_item_expr.h"
+#include "path_expr.h"
+#include "script_exprs.h"
+#include "update_exprs.h"
+
+namespace zorba {
+
+ExprManager::ExprManager()
+: memory()
+{}
+
+//calls on the destructors and also keeps tracks of certain numbers
+ExprManager::~ExprManager()
+{
+ unsigned long total_expr = theExprs.size();
+ unsigned long zero_ref_expr = 0;
+
+ unsigned long total_bytes = 0;
+ unsigned long zero_ref_bytes = 0;
+
+ for(std::list<expr*>::iterator iter = theExprs.begin();
+ iter != theExprs.end();
+ iter++)
+ {
+ expr* exp = *iter;
+
+ unsigned long bytes = sizeof *exp;
+
+ total_bytes += bytes;
+
+ if(exp->getRefCount() == 0)
+ {
+ ++zero_ref_expr;
+ zero_ref_bytes += bytes;
+ }
+
+ exp->~expr();
+ }
+}
+
+expr* ExprManager::reg(expr* exp)
+{
+ theExprs.push_back(exp);
+ return exp;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+#define CREATE_AND_RETURN_EXPR(EXPRTYPE, ...) \
+ EXPRTYPE *EXPPTR = new (memory) EXPRTYPE(__VA_ARGS__); \
+ reg(EXPPTR); \
+ return EXPPTR
+
+#define CREATE_AND_RETURN(TYPE, ...) \
+ TYPE *EXPPTR = new (memory) TYPE(__VA_ARGS__); \
+ return EXPPTR
+////////////////////////////////////////////////////////////////////////////////
+
+if_expr* ExprManager::create_if_expr(static_context* sctx, const QueryLoc& loc,
+ expr_t cond_expr, expr_t then_expr, expr_t else_expr)
+{
+ CREATE_AND_RETURN_EXPR(if_expr, sctx, loc, cond_expr, then_expr, else_expr);
+}
+
+order_expr* ExprManager::create_order_expr(static_context* sctx,
+ const QueryLoc& loc,
+ order_expr::order_type_t order,
+ expr_t exp)
+{
+ CREATE_AND_RETURN_EXPR(order_expr, sctx, loc, order, exp);
+}
+
+validate_expr* ExprManager::create_validate_expr(static_context* sctx,
+ const QueryLoc& loc,
+ ParseConstants::validation_mode_t mode,
+ const store::Item_t& aTypeName,
+ expr_t validated,
+ rchandle<TypeManager> tm)
+{
+ CREATE_AND_RETURN_EXPR(validate_expr,
+ sctx, loc, mode, aTypeName, validated, tm);
+}
+
+
+cast_expr* ExprManager::create_cast_expr(static_context* sctx,
+ const QueryLoc& loc,
+ expr_t casted, xqtref_t type)
+{
+ CREATE_AND_RETURN_EXPR(cast_expr, sctx, loc, casted, type);
+}
+
+
+treat_expr* ExprManager::create_treat_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t treated,
+ xqtref_t type,
+ Error const& err,
+ bool check_prime,
+ store::Item_t fnQname)
+{
+ CREATE_AND_RETURN_EXPR(treat_expr,
+ sctx, loc, treated, type, err, check_prime, fnQname);
+}
+
+
+promote_expr* ExprManager::create_promote_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t promoted,
+ xqtref_t type,
+ store::Item_t fnQname)
+{
+ CREATE_AND_RETURN_EXPR(promote_expr, sctx, loc, promoted, type, fnQname);
+}
+
+castable_expr* ExprManager::create_castable_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t castable,
+ xqtref_t type)
+{
+ CREATE_AND_RETURN_EXPR(castable_expr, sctx, loc, castable, type);
+}
+
+instanceof_expr* ExprManager::create_instanceof_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t instanced,
+ xqtref_t type,
+ bool checkPrimeOnly)
+{
+ CREATE_AND_RETURN_EXPR(instanceof_expr,
+ sctx, loc, instanced, type, checkPrimeOnly);
+}
+
+name_cast_expr* ExprManager::create_name_cast_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t casted,
+ const namespace_context* ns,
+ bool isAttr)
+{
+ CREATE_AND_RETURN_EXPR(name_cast_expr, sctx, loc, casted, ns, isAttr);
+}
+
+doc_expr* ExprManager::create_doc_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr* content,
+ bool copyNodes)
+{
+ CREATE_AND_RETURN_EXPR(doc_expr, sctx, loc, content, copyNodes);
+}
+
+elem_expr* ExprManager::create_elem_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr* qnameExpr,
+ expr* attrs,
+ expr* content,
+ const namespace_context* nsCtx,
+ bool copyNodes)
+{
+ CREATE_AND_RETURN_EXPR(elem_expr,
+ sctx, loc, qnameExpr, attrs, content, nsCtx, copyNodes);
+}
+
+elem_expr* ExprManager::create_elem_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr* qnameExpr,
+ expr* content,
+ const namespace_context* nsCtx,
+ bool copyNodes)
+{
+ CREATE_AND_RETURN_EXPR(elem_expr,
+ sctx, loc, qnameExpr, content, nsCtx, copyNodes);
+}
+
+attr_expr* ExprManager::create_attr_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t aQNameExpr,
+ expr_t aValueExpr)
+{
+ CREATE_AND_RETURN_EXPR(attr_expr, sctx, loc, aQNameExpr, aValueExpr);
+}
+
+text_expr* ExprManager::create_text_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ text_expr::text_constructor_type textType,
+ expr_t text)
+{
+ CREATE_AND_RETURN_EXPR(text_expr, sctx, loc, textType, text);
+}
+
+pi_expr* ExprManager::create_pi_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t targetExpr,
+ expr_t contentExpr)
+{
+ CREATE_AND_RETURN_EXPR(pi_expr, sctx, loc, targetExpr, contentExpr);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, zstring& sval)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, const std::string& sval)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, const char* sval)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, sval);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, xs_integer val)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, xs_decimal val)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, xs_double val)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, xs_boolean val)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx, const QueryLoc& loc, store::Item_t val)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, val);
+}
+
+const_expr* ExprManager::create_const_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const char* ns,
+ const char* pre,
+ const char* local)
+{
+ CREATE_AND_RETURN_EXPR(const_expr, sctx, loc, ns, pre, local);
+}
+
+extension_expr* ExprManager::create_extension_expr(static_context* sctx,
+ const QueryLoc& loc)
+{
+ CREATE_AND_RETURN_EXPR(extension_expr, sctx, loc);
+}
+
+extension_expr* ExprManager::create_extension_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t extended)
+{
+ CREATE_AND_RETURN_EXPR(extension_expr, sctx, loc, extended);
+}
+
+catch_clause* ExprManager::create_catch_clause()
+{
+ CREATE_AND_RETURN(catch_clause);
+}
+
+trycatch_expr* ExprManager::create_trycatch_expr(
+ static_context* sctx, const QueryLoc& loc, expr_t tryExpr)
+{
+ CREATE_AND_RETURN_EXPR(trycatch_expr, sctx, loc, tryExpr);
+}
+
+wrapper_expr* ExprManager::create_wrapper_expr(
+ static_context* sctx, const QueryLoc& loc, expr_t wrapped)
+{
+ CREATE_AND_RETURN_EXPR(wrapper_expr, sctx, loc, wrapped);
+}
+
+function_trace_expr* ExprManager::create_function_trace_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t aChild)
+{
+ CREATE_AND_RETURN_EXPR(function_trace_expr, sctx, loc, aChild);
+}
+
+function_trace_expr* ExprManager::create_function_trace_expr(expr_t aExpr)
+{
+ CREATE_AND_RETURN_EXPR(function_trace_expr, aExpr);
+}
+
+eval_expr* ExprManager::create_eval_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& e,
+ expr_script_kind_t scriptingKind,
+ namespace_context* nsCtx)
+{
+ CREATE_AND_RETURN_EXPR(eval_expr, sctx, loc, e, scriptingKind, nsCtx);
+}
+
+#ifdef ZORBA_WITH_DEBUGGER
+
+debugger_expr* ExprManager::create_debugger_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& aChild,
+ namespace_context* nsCtx,
+ bool aIsVarDeclaration)
+{
+ CREATE_AND_RETURN_EXPR(debugger_expr,
+ sctx, loc, aChild, nsCtx, aIsVarDeclaration);
+}
+
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+var_expr* ExprManager::create_var_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr::var_kind k,
+ store::Item* name)
+{
+ CREATE_AND_RETURN_EXPR(var_expr, sctx, loc, k, name);
+}
+
+var_expr* ExprManager::create_var_expr(const var_expr& source)
+{
+ CREATE_AND_RETURN_EXPR(var_expr, source);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+insert_expr* ExprManager::create_insert_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ store::UpdateConsts::InsertType insertType,
+ const expr_t& aSourceExpr,
+ const expr_t& aTargetExpr)
+{
+ CREATE_AND_RETURN_EXPR(insert_expr,
+ sctx, loc, insertType, aSourceExpr, aTargetExpr);
+}
+
+delete_expr* ExprManager::create_delete_expr(
+ static_context* sctx, const QueryLoc& loc, const expr_t& aTargetExpr)
+{
+ CREATE_AND_RETURN_EXPR(delete_expr, sctx, loc, aTargetExpr);
+}
+
+replace_expr* ExprManager::create_replace_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ store::UpdateConsts::ReplaceType aType,
+ const expr_t& aSourceExpr,
+ const expr_t& aTargetExpr)
+{
+ CREATE_AND_RETURN_EXPR(replace_expr, sctx, loc, aType, aSourceExpr, aTargetExpr);
+}
+
+rename_expr* ExprManager::create_rename_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& aSourceExpr,
+ const expr_t& aTargetExpr)
+{
+ CREATE_AND_RETURN_EXPR(rename_expr, sctx, loc, aSourceExpr, aTargetExpr);
+}
+
+copy_clause* ExprManager::create_copy_clause(var_expr_t aVar, expr_t aExpr)
+{
+ CREATE_AND_RETURN(copy_clause, aVar, aExpr);
+}
+
+transform_expr* ExprManager::create_transform_expr(
+ static_context* sctx, const QueryLoc& loc)
+{
+ CREATE_AND_RETURN_EXPR(transform_expr, sctx, loc);
+}
+
+block_expr* ExprManager::create_block_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ bool allowLastUpdating,
+ std::vector<expr_t>& seq,
+ std::vector<var_expr*>* assignedVars)
+{
+ CREATE_AND_RETURN_EXPR(block_expr,
+ sctx, loc, allowLastUpdating, seq, assignedVars);
+}
+
+apply_expr* ExprManager::create_apply_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& inExpr,
+ bool discardXDM)
+{
+ CREATE_AND_RETURN_EXPR(apply_expr, sctx, loc, inExpr, discardXDM);
+}
+
+var_decl_expr* ExprManager::create_var_decl_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const var_expr_t& varExpr,
+ const expr_t& initExpr)
+{
+ CREATE_AND_RETURN_EXPR(var_decl_expr, sctx, loc, varExpr, initExpr);
+}
+
+var_set_expr* ExprManager::create_var_set_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const var_expr_t& varExpr,
+ const expr_t& setExpr)
+{
+ CREATE_AND_RETURN_EXPR(var_set_expr, sctx, loc, varExpr, setExpr);
+}
+
+exit_expr* ExprManager::create_exit_expr(
+ static_context* sctx, const QueryLoc& loc, const expr_t& inExpr)
+{
+ CREATE_AND_RETURN_EXPR(exit_expr, sctx, loc, inExpr);
+}
+
+exit_catcher_expr* ExprManager::create_exit_catcher_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& inExpr,
+ std::vector<expr*>& exitExprs)
+{
+ CREATE_AND_RETURN_EXPR(exit_catcher_expr, sctx, loc, inExpr, exitExprs);
+}
+
+flowctl_expr* ExprManager::create_flowctl_expr(
+ static_context* sctx, const QueryLoc& loc,
+ flowctl_expr::action action)
+{
+ CREATE_AND_RETURN_EXPR(flowctl_expr, sctx, loc, action);
+}
+
+while_expr* ExprManager::create_while_expr(
+ static_context* sctx, const QueryLoc& loc, expr_t body)
+{
+ CREATE_AND_RETURN_EXPR(while_expr, sctx, loc, body);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+relpath_expr* ExprManager::create_relpath_expr(
+ static_context* sctx, const QueryLoc& loc)
+{
+ CREATE_AND_RETURN_EXPR(relpath_expr, sctx, loc);
+}
+
+axis_step_expr* ExprManager::create_axis_step_expr(
+ static_context* sctx, const QueryLoc& loc)
+{
+ CREATE_AND_RETURN_EXPR(axis_step_expr, sctx, loc);
+}
+
+match_expr* ExprManager::create_match_expr(
+ static_context* sctx, const QueryLoc& loc)
+{
+ CREATE_AND_RETURN_EXPR(match_expr, sctx, loc);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+dynamic_function_invocation_expr*
+ExprManager::create_dynamic_function_invocation_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& anExpr,
+ const std::vector<expr_t>& args)
+{
+ CREATE_AND_RETURN_EXPR(dynamic_function_invocation_expr, sctx, loc, anExpr, args);
+}
+
+function_item_expr* ExprManager::create_function_item_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const store::Item* aQName,
+ function* f,
+ uint32_t aArity)
+{
+ CREATE_AND_RETURN_EXPR(function_item_expr, sctx, loc, aQName, f, aArity);
+}
+
+function_item_expr* ExprManager::create_function_item_expr(
+ static_context* sctx,
+ const QueryLoc& loc)
+{
+ CREATE_AND_RETURN_EXPR(function_item_expr, sctx, loc);
+}
+
+ftcontains_expr* ExprManager::create_ftcontains_expr(
+ static_context* sctx,
+ QueryLoc const& loc,
+ expr_t range,
+ ftnode *ftselection,
+ expr_t ftignore)
+{
+ CREATE_AND_RETURN_EXPR(ftcontains_expr, sctx, loc, range, ftselection, ftignore);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//this calls the static create_seq within fo_expr
+fo_expr* ExprManager::create_seq(static_context* sctx, const QueryLoc& loc)
+{
+ //TODO make fo_expr use this factory to generate everything
+ return fo_expr::create_seq(sctx, loc);
+}
+
+fo_expr* ExprManager::create_fo_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const function* f,
+ const expr* arg)
+{
+ CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, arg);
+}
+
+fo_expr* ExprManager::create_fo_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const function* f,
+ const expr* arg1,
+ const expr* arg2)
+{
+ CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, arg1, arg2);
+}
+
+fo_expr* ExprManager::create_fo_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const function* f,
+ const std::vector<expr_t>& args)
+{
+ CREATE_AND_RETURN_EXPR(fo_expr, sctx, loc, f, args);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+for_clause* ExprManager::create_for_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr_t varExpr,
+ expr_t domainExpr,
+ var_expr_t posVarExpr,
+ var_expr_t scoreVarExpr,
+ bool isOuter)
+{
+ CREATE_AND_RETURN(for_clause,
+ sctx, loc, varExpr, domainExpr, posVarExpr, scoreVarExpr, isOuter);
+}
+
+let_clause* ExprManager::create_let_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr_t varExpr,
+ expr_t domainExpr,
+ bool lazy)
+{
+ CREATE_AND_RETURN(let_clause, sctx, loc, varExpr, domainExpr, lazy);
+}
+
+window_clause* ExprManager::create_window_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ window_clause::window_t winKind,
+ var_expr_t varExpr,
+ expr_t domainExpr,
+ flwor_wincond_t winStart,
+ flwor_wincond_t winStop,
+ bool lazy)
+{
+ CREATE_AND_RETURN(window_clause,
+ sctx, loc, winKind, varExpr, domainExpr, winStart, winStop, lazy);
+}
+
+flwor_wincond* ExprManager::create_flwor_wincond(
+ static_context* sctx,
+ bool isOnly,
+ const flwor_wincond::vars& in_vars,
+ const flwor_wincond::vars& out_vars,
+ expr_t cond)
+{
+ CREATE_AND_RETURN(flwor_wincond, sctx, isOnly, in_vars, out_vars, cond);
+}
+
+group_clause* ExprManager::create_group_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const flwor_clause::rebind_list_t& gvars,
+ flwor_clause::rebind_list_t ngvars,
+ const std::vector<std::string>& collations)
+{
+ CREATE_AND_RETURN(group_clause, sctx, loc, gvars, ngvars, collations);
+}
+
+orderby_clause* ExprManager::create_orderby_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ bool stable,
+ const std::vector<OrderModifier>& modifiers,
+ const std::vector<expr_t>& orderingExprs)
+{
+ CREATE_AND_RETURN(orderby_clause, sctx, loc, stable, modifiers, orderingExprs);
+}
+
+materialize_clause* ExprManager::create_materialize_clause(
+ static_context* sctx, const QueryLoc& loc)
+{
+ CREATE_AND_RETURN(materialize_clause, sctx, loc);
+}
+
+count_clause* ExprManager::create_count_clause(
+ static_context* sctx, const QueryLoc& loc, var_expr_t var)
+{
+ CREATE_AND_RETURN(count_clause, sctx, loc, var);
+}
+
+where_clause* ExprManager::create_where_clause(
+ static_context* sctx, const QueryLoc& loc, expr_t where)
+{
+ CREATE_AND_RETURN(where_clause, sctx, loc, where);
+}
+
+flwor_expr* ExprManager::create_flwor_expr(
+ static_context* sctx, const QueryLoc& loc, bool general)
+{
+ CREATE_AND_RETURN_EXPR(flwor_expr, sctx, loc, general);
+}
+
+} // namespace zorba
=== added file 'src/compiler/expression/expr_manager.h'
--- src/compiler/expression/expr_manager.h 1970-01-01 00:00:00 +0000
+++ src/compiler/expression/expr_manager.h 2012-06-26 18:33:24 +0000
@@ -0,0 +1,474 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#ifndef ZORBA_COMPILER_EXPRMANAGER_H
+#define ZORBA_COMPILER_EXPRMANAGER_H
+
+#include "ftnode.h"
+#include "expr.h"
+#include "var_expr.h"
+#include "flwor_expr.h"
+#include "fo_expr.h"
+#include "ft_expr.h"
+#include "function_item_expr.h"
+#include "path_expr.h"
+#include "script_exprs.h"
+#include "update_exprs.h"
+
+#include "mem_manager.h"
+
+namespace zorba
+{
+
+class ExprManager
+{
+public:
+ ExprManager();
+ ~ExprManager();
+
+ expr* reg(expr*);
+
+private:
+ std::list<expr*> theExprs;
+ MemoryManager memory;
+
+private:
+ //An ExprManager is the only objecto to handle a collection of Exprs and
+ //the memory in which they recide. It makes no sense to copy it.
+ ExprManager(const ExprManager&);
+ ExprManager& operator= (const ExprManager&);
+
+public:
+ MemoryManager& getMemory() {return memory;}
+
+public:
+ if_expr* create_if_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t cond_expr,
+ expr_t then_expr,
+ expr_t else_expr);
+
+ order_expr* create_order_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ order_expr::order_type_t,
+ expr_t);
+
+ validate_expr* create_validate_expr(
+ static_context*,
+ const QueryLoc&,
+ ParseConstants::validation_mode_t,
+ const store::Item_t& aTypeName,
+ expr_t validated,
+ rchandle<TypeManager>);
+
+ cast_expr* create_cast_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ xqtref_t);
+
+ treat_expr* create_treat_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ xqtref_t,
+ Error const&,
+ bool check_prime = true,
+ store::Item_t fnQname = NULL);
+
+
+ promote_expr* create_promote_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t input,
+ xqtref_t type,
+ store::Item_t fnQname = NULL);
+
+ castable_expr* create_castable_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ xqtref_t);
+
+ instanceof_expr* create_instanceof_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ xqtref_t,
+ bool checkPrimeOnly = false);
+
+ name_cast_expr* create_name_cast_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ const namespace_context*,
+ bool isAttr);
+
+ doc_expr* create_doc_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr* content,
+ bool copyNodes);
+
+ elem_expr* create_elem_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr* qnameExpr,
+ expr* attrs,
+ expr* content,
+ const namespace_context* nsCtx,
+ bool copyNodes);
+
+ elem_expr* create_elem_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr* qnameExpr,
+ expr* content,
+ const namespace_context* nsCtx,
+ bool copyNodes);
+
+ attr_expr* create_attr_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t aQNameExpr,
+ expr_t aValueExpr);
+
+ text_expr* create_text_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ text_expr::text_constructor_type,
+ expr_t);
+
+ pi_expr* create_pi_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t,
+ expr_t);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ zstring& sval);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ const std::string& sval);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ const char* sval);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ xs_integer);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ xs_decimal);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ xs_double);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ xs_boolean);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ store::Item_t);
+
+ const_expr* create_const_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ const char* ns,
+ const char* pre,
+ const char* local);
+
+ extension_expr* create_extension_expr(
+ static_context* sctx,
+ const QueryLoc&);
+
+ extension_expr* create_extension_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t);
+
+ catch_clause* create_catch_clause();
+
+ trycatch_expr* create_trycatch_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ expr_t tryExpr);
+
+ wrapper_expr* create_wrapper_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t wrapped);
+
+ function_trace_expr* create_function_trace_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t aChild);
+
+ function_trace_expr* create_function_trace_expr(expr_t aExpr);
+
+ eval_expr* create_eval_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& e,
+ expr_script_kind_t scriptingKind,
+ namespace_context* nsCtx);
+
+#ifdef ZORBA_WITH_DEBUGGER
+ debugger_expr* create_debugger_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& aChild,
+ namespace_context* nsCtx,
+ bool aIsVarDeclaration);
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+ var_expr* create_var_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr::var_kind k,
+ store::Item* name);
+
+ var_expr* create_var_expr(const var_expr& source);
+
+////////////////////////////////////////////////////////////////////////////////
+
+ insert_expr* create_insert_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ store::UpdateConsts::InsertType,
+ const expr_t& aSourceExpr,
+ const expr_t& aTargetExpr);
+
+ delete_expr* create_delete_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ const expr_t&);
+
+ replace_expr* create_replace_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ store::UpdateConsts::ReplaceType aType,
+ const expr_t&,
+ const expr_t&);
+
+ rename_expr* create_rename_expr(
+ static_context* sctx,
+ const QueryLoc&,
+ const expr_t&,
+ const expr_t&);
+
+ copy_clause* create_copy_clause(var_expr_t aVar, expr_t aExpr);
+
+ transform_expr* create_transform_expr(
+ static_context* sctx,
+ const QueryLoc& loc);
+
+ block_expr* create_block_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ bool allowLastUpdating,
+ std::vector<expr_t>& seq,
+ std::vector<var_expr*>* assignedVars);
+
+ apply_expr* create_apply_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& inExpr,
+ bool discardXDM);
+
+ var_decl_expr* create_var_decl_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const var_expr_t& varExpr,
+ const expr_t& initExpr);
+
+ var_set_expr* create_var_set_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const var_expr_t& varExpr,
+ const expr_t& setExpr);
+
+ exit_expr* create_exit_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& inExpr);
+
+ exit_catcher_expr* create_exit_catcher_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& inExpr,
+ std::vector<expr*>& exitExprs);
+
+ flowctl_expr* create_flowctl_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ flowctl_expr::action action);
+
+ while_expr* create_while_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t body);
+
+////////////////////////////////////////////////////////////////////////////////
+
+ relpath_expr* create_relpath_expr(static_context* sctx, const QueryLoc& loc);
+
+ axis_step_expr* create_axis_step_expr(static_context* sctx, const QueryLoc&);
+
+ match_expr* create_match_expr(static_context* sctx, const QueryLoc&);
+
+////////////////////////////////////////////////////////////////////////////////
+
+ dynamic_function_invocation_expr* create_dynamic_function_invocation_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const expr_t& anExpr,
+ const std::vector<expr_t>& args);
+
+ function_item_expr* create_function_item_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const store::Item* aQName,
+ function* f,
+ uint32_t aArity);
+
+ function_item_expr* create_function_item_expr(
+ static_context* sctx,
+ const QueryLoc& loc);
+
+ ftcontains_expr* create_ftcontains_expr(
+ static_context*,
+ QueryLoc const&,
+ expr_t range,
+ ftnode *ftselection,
+ expr_t ftignore);
+
+////////////////////////////////////////////////////////////////////////////////
+
+ //this calls the static create_seq within fo_expr
+ fo_expr* create_seq(static_context* sctx, const QueryLoc &);
+
+ fo_expr* create_fo_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const function* f,
+ const expr* arg);
+
+ fo_expr* create_fo_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const function* f,
+ const expr* arg1,
+ const expr* arg2);
+
+ fo_expr* create_fo_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const function* f,
+ const std::vector<expr_t>& args);
+
+////////////////////////////////////////////////////////////////////////////////
+
+ for_clause* create_for_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr_t varExpr,
+ expr_t domainExpr,
+ var_expr_t posVarExpr = NULL,
+ var_expr_t scoreVarExpr = NULL,
+ bool isOuter = false);
+
+ let_clause* create_let_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr_t varExpr,
+ expr_t domainExpr,
+ bool lazy = false);
+
+ window_clause* create_window_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ window_clause::window_t winKind,
+ var_expr_t varExpr,
+ expr_t domainExpr,
+ flwor_wincond_t winStart,
+ flwor_wincond_t winStop,
+ bool lazy = false);
+
+ flwor_wincond* create_flwor_wincond(
+ static_context* sctx,
+ bool isOnly,
+ const flwor_wincond::vars& in_vars,
+ const flwor_wincond::vars& out_vars,
+ expr_t cond);
+
+ group_clause* create_group_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ const flwor_clause::rebind_list_t& gvars,
+ flwor_clause::rebind_list_t ngvars,
+ const std::vector<std::string>& collations);
+
+ orderby_clause * create_orderby_clause (
+ static_context* sctx,
+ const QueryLoc& loc,
+ bool stable,
+ const std::vector<OrderModifier>& modifiers,
+ const std::vector<expr_t>& orderingExprs);
+
+ materialize_clause* create_materialize_clause(
+ static_context* sctx,
+ const QueryLoc& loc);
+
+ count_clause* create_count_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ var_expr_t var);
+
+ where_clause* create_where_clause(
+ static_context* sctx,
+ const QueryLoc& loc,
+ expr_t where);
+
+ flwor_expr* create_flwor_expr(
+ static_context* sctx,
+ const QueryLoc& loc,
+ bool general);
+};
+
+
+} // namespace zorba
+
+#endif // ZORBA_COMPILER_EXPRMANAGER_H
=== modified file 'src/compiler/expression/fo_expr.cpp'
--- src/compiler/expression/fo_expr.cpp 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/fo_expr.cpp 2012-06-26 18:33:24 +0000
@@ -38,7 +38,7 @@
{
if (v.begin_visit(*this))
{
- accept_children(v);
+ accept_children(v);
}
v.end_visit(*this);
@@ -172,7 +172,7 @@
RAISE_ERROR(err::XUST0001, theArgs[i]->get_loc(),
ERROR_PARAMS(ZED(XUST0001_CONCAT)));
}
-
+
if (i > 0 && !is_updating() && !is_vacuous() && (argKind & UPDATING_EXPR))
{
RAISE_ERROR(err::XUST0001, theArgs[i]->get_loc(),
@@ -248,7 +248,12 @@
expr_t fo_expr::clone(substitution_t& subst) const
{
+<<<<<<< TREE
if (get_func()->getKind() == FunctionConsts::STATIC_COLLECTIONS_DML_COLLECTION_1)
+=======
+ if (get_func()->getKind() ==
+ FunctionConsts::ZORBA_STORE_COLLECTIONS_STATIC_DML_COLLECTION_1)
+>>>>>>> MERGE-SOURCE
{
expr::subst_iter_t i = subst.find(this);
=== modified file 'src/compiler/expression/ft_expr.h'
--- src/compiler/expression/ft_expr.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/ft_expr.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,7 +27,7 @@
/**
* An ftcontains_expr is-an expr for the FTContainsExpr.
*/
-class ftcontains_expr : public expr
+class ftcontains_expr : public expr
{
friend class ExprIterator;
=== modified file 'src/compiler/expression/function_item_expr.h'
--- src/compiler/expression/function_item_expr.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/function_item_expr.h 2012-06-26 18:33:24 +0000
@@ -50,17 +50,17 @@
const expr_t& anExpr,
const std::vector<expr_t>& args);
- const expr_t get_function() const { return theExpr; }
+ const expr_t get_function() const { return theExpr; }
const std::vector<expr_t>& get_args() const { return theArgs; }
- void compute_scripting_kind();
+ void compute_scripting_kind();
expr_t clone(substitution_t& s) const;
- void accept(expr_visitor&);
+ void accept(expr_visitor&);
- std::ostream& put(std::ostream& os) const;
+ std::ostream& put(std::ostream& os) const;
};
@@ -102,12 +102,21 @@
private:
store::Item_t theQName;
- function_t theFunction;
+ function_t theFunction;
uint32_t theArity;
std::vector<expr_t> theScopedVariables;
public:
+<<<<<<< TREE
function_item_expr(
+=======
+ SERIALIZABLE_CLASS(function_item_expr)
+ function_item_expr(::zorba::serialization::Archiver& ar);
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ function_item_expr(
+>>>>>>> MERGE-SOURCE
static_context* sctx,
const QueryLoc& loc,
const store::Item* aQName,
@@ -124,7 +133,7 @@
void set_function(user_function_t& udf);
- function* get_function() const { return theFunction.getp(); }
+ function* get_function() const { return theFunction.getp(); }
const store::Item_t& get_qname() const { return theQName; }
@@ -132,13 +141,13 @@
const std::vector<expr_t>& get_vars() const;
- void compute_scripting_kind();
+ void compute_scripting_kind();
expr_t clone(substitution_t& s) const;
- void accept(expr_visitor&);
+ void accept(expr_visitor&);
- std::ostream& put(std::ostream& os) const;
+ std::ostream& put(std::ostream& os) const;
};
} //end of namespace
=== added file 'src/compiler/expression/mem_manager.cpp'
--- src/compiler/expression/mem_manager.cpp 1970-01-01 00:00:00 +0000
+++ src/compiler/expression/mem_manager.cpp 2012-06-26 18:33:24 +0000
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mem_manager.h"
+
+#include <new>
+
+namespace zorba
+{
+
+MemPage::MemPage(size_t page_size,
+ void* (*allocate_func)(size_t), void (*deallocate_func)(void*)
+ )
+: thePageSize(page_size),
+ theAllocator(allocate_func),
+ theDeallocator(deallocate_func)
+{
+ thePageStart = static_cast<char*>((*theAllocator)(thePageSize));
+
+ if (thePageStart == NULL)
+ throw std::bad_alloc();
+
+ theFreeStart = thePageStart;
+}
+
+MemPage::~MemPage()
+{
+ (*theDeallocator)(thePageStart);
+}
+
+size_t MemPage::space() const
+{
+ return thePageSize + thePageStart - theFreeStart;
+}
+
+void* MemPage::allocate(size_t alloc_size)
+{
+ if (alloc_size == 0 ||
+ alloc_size + theFreeStart > thePageSize + thePageStart)
+ return NULL;
+
+ void* allocation = (void*)theFreeStart;
+
+ theFreeStart += alloc_size;
+
+ return allocation;
+}
+
+MemoryManager::MemoryManager()
+{
+ pages.push_front(new MemPage());
+}
+
+MemoryManager::~MemoryManager()
+{
+ for(std::list<MemPage*>::iterator iter = pages.begin();
+ iter != pages.end();
+ ++iter)
+ delete *iter;
+}
+
+void* MemoryManager::allocate(size_t size)
+{
+ if(size > MemPage::DEFAULT_PAGE_SIZE)
+ {
+ pages.push_back(new MemPage(size));
+ return pages.back()->allocate(size);
+ }
+
+ if(pages.front()->space() < size)
+ pages.push_front(new MemPage());
+
+ return pages.front()->allocate(size);
+}
+
+} // namespace zorba
=== added file 'src/compiler/expression/mem_manager.h'
--- src/compiler/expression/mem_manager.h 1970-01-01 00:00:00 +0000
+++ src/compiler/expression/mem_manager.h 2012-06-26 18:33:24 +0000
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+#ifndef ZORBA_COMPILER_MEMMANAGER_H
+#define ZORBA_COMPILER_MEMMANAGER_H
+
+#include <stdlib.h>
+
+#include <list>
+
+namespace zorba
+{
+
+/*******************************************************************************
+ * Memory Page *
+ ******************************************************************************/
+
+/*
+ * A memory page handles a piece of memory of a certain size. It will also
+ * manage allocation of memory.
+ */
+
+class MemPage {
+public:
+ static const size_t DEFAULT_PAGE_SIZE = 128;
+
+ MemPage(size_t page_size = DEFAULT_PAGE_SIZE,
+ void* (*allocate_func)(size_t) = &malloc,
+ void (*deallocate_func)(void*) = &free);
+ ~MemPage();
+
+ size_t space() const;
+
+ /*
+ * Reserves a space of memory within the page.
+ * @param alloc_size the amount of memory to reserve in bytes.
+ * @returns if there is alloc_size space and alloc_size is not 0 returns a
+ * pointer to a space of memory of the size of allocate. Otherwise
+ * NULL.
+ */
+ void* allocate(size_t alloc_size);
+
+private:
+ const size_t thePageSize;
+ void* (*theAllocator)(size_t);
+ void (*theDeallocator)(void*);
+
+ char* thePageStart;
+ char* theFreeStart;
+
+private:
+ // Pages are unique, there is no sense in copying them
+ MemPage (const MemPage&);
+ MemPage& operator= (const MemPage&);
+};
+
+/*******************************************************************************
+ * Memory Manager *
+ ******************************************************************************/
+class MemoryManager
+{
+public:
+ MemoryManager();
+ ~MemoryManager();
+
+ void* allocate(size_t size);
+
+private:
+ std::list<MemPage*> pages;
+
+private:
+ // A memory manager is the only existing object handling memory
+ // Since it's all data that it contains, there is no sense in copying it.
+ MemoryManager(const MemoryManager&);
+ MemoryManager& operator=(const MemoryManager&);
+};
+
+} // namespace zorba
+
+//This handles the creation of data within the memory pool using the format
+//new (MemPool) constructor
+//for more information see
+//http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14
+inline void* operator new(size_t size, zorba::MemoryManager& mem)
+{
+ return mem.allocate(size);
+}
+
+inline void operator delete(void* p, zorba::MemoryManager& mem)
+{ /*Memory is freed when MemoryManager is destroyed */ }
+
+#endif /*ZORBA_COMPILER_MEMMANAGER_H*/
=== modified file 'src/compiler/expression/path_expr.h'
--- src/compiler/expression/path_expr.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/path_expr.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,7 +23,7 @@
#include "zorbatypes/zstring.h"
-namespace zorba
+namespace zorba
{
class match_expr;
@@ -31,7 +31,7 @@
/*******************************************************************************
- PathExpr ::= ("/" RelativePathExpr?) |
+ PathExpr ::= ("/" RelativePathExpr?) |
("//" RelativePathExpr) |
RelativePathExpr
@@ -49,7 +49,7 @@
RelativPathExpr ::= "/" | ("/" | "//")? StepExpr (("/" | "//") StepExpr)*
********************************************************************************/
-class relpath_expr : public expr
+class relpath_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -60,9 +60,9 @@
public:
relpath_expr(static_context* sctx, const QueryLoc& loc);
- size_t size() const { return theSteps.size(); }
+ size_t size() const { return theSteps.size(); }
- void add_back(expr_t step);
+ void add_back(expr_t step);
void erase(csize i) { theSteps.erase(theSteps.begin() + i); }
@@ -96,7 +96,7 @@
AxisStep ::= Axis NodeTest Predicate*
********************************************************************************/
-class axis_step_expr : public expr
+class axis_step_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -122,7 +122,7 @@
bool is_reverse_axis() const { return is_reverse_axis(getAxis()); }
- match_expr* getTest() const
+ match_expr* getTest() const
{
return reinterpret_cast<match_expr*>(theNodeTest.getp());
}
@@ -155,7 +155,7 @@
and theNilledAllowed data members are not used.
********************************************************************************/
-class match_expr : public expr
+class match_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -189,7 +189,7 @@
const zstring& getWildName() const { return theWildName; }
template<class StringType>
- void setWildName(const StringType& v) { theWildName = v; }
+ void setWildName(const StringType& v) { theWildName = v; }
store::Item* getQName() const { return theQName.getp(); }
=== modified file 'src/compiler/expression/script_exprs.h'
--- src/compiler/expression/script_exprs.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/script_exprs.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,7 +22,7 @@
#include "compiler/expression/expr_base.h"
-namespace zorba
+namespace zorba
{
class expr_visitor;
@@ -94,7 +94,7 @@
contrast, the grammar allows only the last operand to be simple; all the other
operands must be sequential or vacuous.
- EXCEPTION: At the top level, a Program consists of 0 or more statements
+ EXCEPTION: At the top level, a Program consists of 0 or more statements
followed by an expr, which may be updating. In the case of a "normal" program,
we can wrap this expr with an apply_expr and model the Program as a block
expr. However, this does not work in the case of eval-updating. The solution
@@ -136,7 +136,7 @@
private:
void compute_scripting_kind();
- void compute_scripting_kind2(
+ void compute_scripting_kind2(
std::vector<var_expr*>* assignedVars,
bool allowLastUpdating) ;
};
@@ -145,7 +145,7 @@
/*******************************************************************************
ApplyStatement ::= ExprSimple ";"
********************************************************************************/
-class apply_expr : public expr
+class apply_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -171,7 +171,7 @@
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
@@ -184,7 +184,7 @@
Annotation ::= "%" EQName ("(" Literal ("," Literal)* ")")?
- VarDecl ::= "variable" "$" VarName TypeDeclaration?
+ VarDecl ::= "variable" "$" VarName TypeDeclaration?
((":=" VarValue) | ("external" (":=" VarDefaultValue)?))
For Local Var:
@@ -193,9 +193,9 @@
VarDeclExpr ::= ("local" Annotation*)? "variable" "$" VarName TypeDeclaration?
(":=" ExprSingle)?
- var_decl_expr is used to declare block-local and prolog variables (including
+ var_decl_expr is used to declare block-local and prolog variables (including
the context item, if it is declared in the prolog). During runtime, the
- associated iterator creates in the local dynamic context a binding between
+ associated iterator creates in the local dynamic context a binding between
the variable id and the variable value. If the declaration includes an
initializing expr, the iterator computes the initExpr and stores the resulting
value inside this binding.
@@ -203,7 +203,7 @@
Note: the init expr must be non-updating. For global vars, it must also be
non-sequential.
********************************************************************************/
-class var_decl_expr : public expr
+class var_decl_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -242,11 +242,11 @@
The RHS of the assignment must be a non-updating expr.
var_set_expr is used to assign a value to a prolog or block-local var. During
- runtime, the function computes theExpr and stores the resulting value inside
+ runtime, the function computes theExpr and stores the resulting value inside
the appropriate dynamic ctx (global or local), at the location that is identified
by the variable id.
********************************************************************************/
-class var_set_expr : public expr
+class var_set_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -281,7 +281,7 @@
/*******************************************************************************
ExitExpr ::= "exit" "with" ExprSingle
********************************************************************************/
-class exit_expr : public expr
+class exit_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -306,7 +306,7 @@
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
@@ -323,7 +323,7 @@
-------------
All the exit_exprs that appear in the body of the udf.
********************************************************************************/
-class exit_catcher_expr : public expr
+class exit_catcher_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -344,14 +344,14 @@
expr* get_expr() const { return theExpr.getp(); }
- std::vector<expr*>::const_iterator exitExprsBegin() const
+ std::vector<expr*>::const_iterator exitExprsBegin() const
{
- return theExitExprs.begin();
+ return theExitExprs.begin();
}
- std::vector<expr*>::const_iterator exitExprsEnd() const
+ std::vector<expr*>::const_iterator exitExprsEnd() const
{
- return theExitExprs.end();
+ return theExitExprs.end();
}
void removeExitExpr(const expr* exitExpr);
@@ -362,14 +362,14 @@
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
/*******************************************************************************
********************************************************************************/
-class flowctl_expr : public expr
+class flowctl_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -391,18 +391,18 @@
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
/*******************************************************************************
- WhileExpr ::= "while" "(" Expr ")" Statement
+ WhileExpr ::= "while" "(" Expr ")" Statement
theBody : It is a block_expr, whose 1st child is the following expr:
if (cond_expr) then () else break
The subsequent children are what it generated by the Statement.
********************************************************************************/
-class while_expr : public expr
+class while_expr : public expr
{
friend class ExprIterator;
friend class expr;
@@ -421,7 +421,7 @@
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
=== modified file 'src/compiler/expression/update_exprs.h'
--- src/compiler/expression/update_exprs.h 2012-06-18 10:06:47 +0000
+++ src/compiler/expression/update_exprs.h 2012-06-26 18:33:24 +0000
@@ -1,12 +1,12 @@
/*
* Copyright 2006-2008 The FLWOR Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,7 +22,7 @@
#include "compiler/expression/expr_base.h"
-namespace zorba
+namespace zorba
{
@@ -44,16 +44,25 @@
expr_t theSourceExpr;
public:
+<<<<<<< TREE
update_expr_base(
+=======
+ SERIALIZABLE_ABSTRACT_CLASS(update_expr_base)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(update_expr_base, expr)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ update_expr_base(
+>>>>>>> MERGE-SOURCE
static_context* sctx,
- const QueryLoc&,
+ const QueryLoc&,
expr_kind_t kind,
- const expr_t& targetExpr,
+ const expr_t& targetExpr,
const expr_t& sourceExpr);
- expr* getTargetExpr() const { return theTargetExpr.getp(); }
+ expr* getTargetExpr() const { return theTargetExpr.getp(); }
- expr* getSourceExpr() const { return theSourceExpr.getp(); }
+ expr* getSourceExpr() const { return theSourceExpr.getp(); }
void compute_scripting_kind();
};
@@ -71,20 +80,29 @@
store::UpdateConsts::InsertType theType;
public:
+<<<<<<< TREE
insert_expr(
+=======
+ SERIALIZABLE_CLASS(insert_expr)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(insert_expr, update_expr_base)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ insert_expr(
+>>>>>>> MERGE-SOURCE
static_context* sctx,
- const QueryLoc&,
+ const QueryLoc&,
store::UpdateConsts::InsertType,
- const expr_t& aSourceExpr,
- const expr_t& aTargetExpr);
+ const expr_t& aSourceExpr,
+ const expr_t& aTargetExpr);
store::UpdateConsts::InsertType getType() const { return theType; }
-
+
expr_t clone(substitution_t& s) const;
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
@@ -97,7 +115,16 @@
friend class expr;
public:
+<<<<<<< TREE
delete_expr(static_context* sctx, const QueryLoc&, const expr_t&);
+=======
+ SERIALIZABLE_CLASS(delete_expr)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(delete_expr, update_expr_base)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ delete_expr(static_context* sctx, const QueryLoc&, const expr_t&);
+>>>>>>> MERGE-SOURCE
expr_t clone(substitution_t& s) const;
@@ -119,22 +146,31 @@
store::UpdateConsts::ReplaceType theType;
public:
+<<<<<<< TREE
replace_expr(
+=======
+ SERIALIZABLE_CLASS(replace_expr)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(replace_expr, update_expr_base)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ replace_expr(
+>>>>>>> MERGE-SOURCE
static_context* sctx,
- const QueryLoc&,
+ const QueryLoc&,
store::UpdateConsts::ReplaceType aType,
- const expr_t&,
- const expr_t&);
+ const expr_t&,
+ const expr_t&);
store::UpdateConsts::ReplaceType getType() const { return theType; }
- expr* getReplaceExpr() const { return theSourceExpr.getp(); }
+ expr* getReplaceExpr() const { return theSourceExpr.getp(); }
expr_t clone(substitution_t& s) const;
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
@@ -147,19 +183,28 @@
friend class expr;
public:
+<<<<<<< TREE
rename_expr(
+=======
+ SERIALIZABLE_CLASS(rename_expr)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(rename_expr, update_expr_base)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ rename_expr(
+>>>>>>> MERGE-SOURCE
static_context* sctx,
const QueryLoc&,
const expr_t&,
const expr_t&);
- expr* getNameExpr() const { return theSourceExpr.getp(); }
+ expr* getNameExpr() const { return theSourceExpr.getp(); }
expr_t clone(substitution_t& s) const;
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
@@ -202,32 +247,45 @@
friend class expr;
protected:
- std::vector<copy_clause_t> theCopyClauses;
- expr_t theModifyExpr;
- expr_t theReturnExpr;
+ std::vector<copy_clause_t> theCopyClauses;
+ expr_t theModifyExpr;
+ expr_t theReturnExpr;
public:
+<<<<<<< TREE
transform_expr(static_context* sctx, const QueryLoc& loc);
expr_t getModifyExpr() const { return theModifyExpr; }
expr_t getReturnExpr() const { return theReturnExpr; }
+=======
+ SERIALIZABLE_CLASS(transform_expr)
+ SERIALIZABLE_CLASS_CONSTRUCTOR2(transform_expr, expr)
+ void serialize(::zorba::serialization::Archiver& ar);
+
+public:
+ transform_expr(static_context* sctx, const QueryLoc& loc);
+
+ expr_t getModifyExpr() const { return theModifyExpr; }
+
+ expr_t getReturnExpr() const { return theReturnExpr; }
+>>>>>>> MERGE-SOURCE
void setModifyExpr(expr* e);
void setReturnExpr(expr* e);
- void add_back(copy_clause_t c);
-
- copy_clause_t const& operator[](int i) const { return theCopyClauses[i]; }
-
- std::vector<copy_clause_t>::const_iterator begin() const
+ void add_back(copy_clause_t c);
+
+ copy_clause_t const& operator[](int i) const { return theCopyClauses[i]; }
+
+ std::vector<copy_clause_t>::const_iterator begin() const
{ return theCopyClauses.begin(); }
- std::vector<copy_clause_t>::const_iterator end() const
+ std::vector<copy_clause_t>::const_iterator end() const
{ return theCopyClauses.end(); }
- csize size() const { return theCopyClauses.size(); }
+ csize size() const { return theCopyClauses.size(); }
void compute_scripting_kind();
@@ -235,7 +293,7 @@
void accept(expr_visitor&);
- std::ostream& put(std::ostream&) const;
+ std::ostream& put(std::ostream&) const;
};
=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp 2012-06-18 10:06:47 +0000
+++ src/compiler/translator/translator.cpp 2012-06-26 18:33:24 +0000
@@ -191,7 +191,7 @@
#define LAST_IDX_VARNAME getLastIdxVarName()
#define DOT_REF \
- new wrapper_expr(theRootSctx, \
+ theExprManager->create_wrapper_expr(theRootSctx, \
loc, \
lookup_ctx_var(DOT_VARNAME, loc).getp())
@@ -552,6 +552,8 @@
CompilerCB * theCCB;
+ ExprManager * theExprManager;
+
ModulesInfo * theModulesInfo;
std::map<zstring, zstring> theModulesStack;
bool theHaveModuleImportCycle;
@@ -655,6 +657,7 @@
theRootTranslator(rootTranslator),
theRTM(GENV_TYPESYSTEM),
theCCB(minfo->theCCB),
+ theExprManager(&(theCCB->getExprManager())),
theModulesInfo(minfo),
theModulesStack(modulesStack),
theHaveModuleImportCycle(false),
@@ -1072,7 +1075,7 @@
var_expr::var_kind kind,
xqtref_t type = NULL)
{
- var_expr_t e = new var_expr(theRootSctx, loc, kind, qname);
+ var_expr_t e = theExprManager->create_var_expr(theRootSctx, loc, kind, qname);
if (kind == var_expr::pos_var ||
kind == var_expr::count_var ||
@@ -1400,7 +1403,7 @@
********************************************************************************/
expr_t wrap_in_atomization(expr* e)
{
- return new fo_expr(theRootSctx,
+ return theExprManager->create_fo_expr(theRootSctx,
e->get_loc(),
GET_BUILTIN_FUNCTION(FN_DATA_1),
e);
@@ -1416,7 +1419,11 @@
PromoteIterator::ErrorKind errorKind,
store::Item* qname = NULL)
{
+<<<<<<< TREE
return new promote_expr(theRootSctx, e->get_loc(), e, type, errorKind, qname);
+=======
+ return theExprManager->create_promote_expr(theRootSctx, e->get_loc(), e, type, fnQName);
+>>>>>>> MERGE-SOURCE
}
@@ -1436,6 +1443,7 @@
// "type" will be item()* anyway
return (TypeOps::is_subtype(tm, *theRTM.ITEM_TYPE_STAR, *type, loc) ?
e :
+<<<<<<< TREE
new treat_expr(theRootSctx, e->get_loc(), e, type, errorKind, true, qname));
}
@@ -1450,6 +1458,11 @@
GET_BUILTIN_FUNCTION(OP_ENCLOSED_1),
contentExpr);
}
+=======
+ theExprManager->create_treat_expr(theRootSctx, e->get_loc(), e, type, errorCode, true, fnQName));
+}
+
+>>>>>>> MERGE-SOURCE
/*******************************************************************************
@@ -1457,7 +1470,7 @@
********************************************************************************/
expr_t wrap_in_bev(expr_t e)
{
- fo_expr* fo = new fo_expr(theRootSctx,
+ fo_expr* fo = theExprManager->create_fo_expr(theRootSctx,
e->get_loc(),
GET_BUILTIN_FUNCTION(FN_BOOLEAN_1),
e);
@@ -1493,7 +1506,7 @@
fkind = FunctionConsts::OP_SORT_DISTINCT_NODES_ASC_1;
}
- rchandle<fo_expr> dos = new fo_expr(theRootSctx,
+ rchandle<fo_expr> dos = theExprManager->create_fo_expr(theRootSctx,
expr->get_loc(),
BuiltinFunctionLibrary::getFunction(fkind),
expr);
@@ -1511,7 +1524,7 @@
{
assert (lv->get_kind () == var_expr::let_var);
- return new let_clause(theRootSctx, e->get_loc(), lv, e.getp());
+ return theExprManager->create_let_clause(theRootSctx, e->get_loc(), lv, e.getp());
}
@@ -1604,7 +1617,7 @@
var_expr_t lv,
expr_t retExpr)
{
- rchandle<flwor_expr> fe = new flwor_expr(theRootSctx, lv->get_loc(), false);
+ rchandle<flwor_expr> fe = theExprManager->create_flwor_expr(theRootSctx, lv->get_loc(), false);
fe->add_clause(wrap_in_letclause(domExpr, lv));
@@ -1636,7 +1649,7 @@
push_scope();
- rchandle<flwor_expr> flworExpr = new flwor_expr(theRootSctx, loc, false);
+ rchandle<flwor_expr> flworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
if (withContextSize)
{
@@ -1644,7 +1657,7 @@
let_clause_t lcInputSeq = wrap_in_letclause(inputExpr);
// compute the size of the input seq
- rchandle<fo_expr> countExpr = new fo_expr(theRootSctx,
+ rchandle<fo_expr> countExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_COUNT_1),
lcInputSeq->get_var());
@@ -1702,7 +1715,7 @@
#ifdef ZORBA_WITH_DEBUGGER
if (theCCB->theDebuggerCommons != NULL)
{
- std::auto_ptr<debugger_expr> lExpr(new debugger_expr(theSctx,
+ std::auto_ptr<debugger_expr> lExpr(theExprManager->create_debugger_expr(theSctx,
aLoc,
aExpr,
theNSCtx,
@@ -1738,7 +1751,7 @@
var_expr::eval_var,
NULL);
- expr_t argExpr = new wrapper_expr(theRootSctx,
+ expr_t argExpr = theExprManager->create_wrapper_expr(theRootSctx,
lBreakable.getLocation(),
rchandle<expr>(argVar));
lExpr->add_var(evalVar, argExpr);
@@ -1923,20 +1936,24 @@
varType = GENV_TYPESYSTEM.ITEM_TYPE_ONE;
}
- expr_t declExpr = new var_decl_expr(theRootSctx, loc, varExpr, initExpr);
+ expr_t declExpr = theExprManager->create_var_decl_expr(theRootSctx, loc, varExpr, initExpr);
stmts.push_back(declExpr);
// check type for vars that are external or have an init expr
if (varType != NULL && (b.is_extern() || b.theExpr != NULL))
{
- expr_t getExpr = new fo_expr(theRootSctx, loc, varGet, varExpr);
+ expr_t getExpr = theExprManager->create_fo_expr(theRootSctx, loc, varGet, varExpr);
+<<<<<<< TREE
stmts.push_back(new treat_expr(theRootSctx,
loc,
getExpr,
varType,
TreatIterator::TYPE_MATCH));
+=======
+ stmts.push_back(theExprManager->create_treat_expr(theRootSctx, loc, getExpr, varType, err::XPTY0004));
+>>>>>>> MERGE-SOURCE
}
}
@@ -1983,7 +2000,7 @@
args.push_back(program);
}
- block_expr* res = new block_expr(theRootSctx,
+ block_expr* res = theExprManager->create_block_expr(theRootSctx,
program->get_loc(),
theCCB->theIsEval,
args,
@@ -2182,7 +2199,7 @@
import_schema_auto_prefix(lLoc, aSchemaURI.c_str(), NULL);
store::Item_t qname;
- return new validate_expr(theRootSctx,
+ return theExprManager->create_validate_expr(theRootSctx,
lLoc,
ParseConstants::val_strict,
qname,
@@ -3562,7 +3579,7 @@
if (udf->isExiting())
{
- body = new exit_catcher_expr(theRootSctx, loc, body, theExitExprs);
+ body = theExprManager->create_exit_catcher_expr(theRootSctx, loc, body, theExitExprs);
}
// Wrap the UDF body to the type-related expr that enforce the declared
@@ -3619,7 +3636,7 @@
if (v.size() > 0)
{
- rchandle<flwor_expr> flwor = new flwor_expr(theRootSctx, loc, false);
+ rchandle<flwor_expr> flwor = theExprManager->create_flwor_expr(theRootSctx, loc, false);
push_nodestack(flwor.getp());
}
return no_state;
@@ -4382,7 +4399,7 @@
// and not allow the domain expr to return duplicate nodes.
if (index->isGeneral())
{
- domainExpr = new fo_expr(theRootSctx,
+ domainExpr = theExprManager->create_fo_expr(theRootSctx,
domainExpr->get_loc(),
GET_BUILTIN_FUNCTION(OP_CHECK_DISTINCT_NODES_1),
domainExpr);
@@ -4516,7 +4533,7 @@
{
// Eliminate duplicate key values, as they don't play any role in a
// general comparison predicate.
- keyExpr = new fo_expr(theRootSctx,
+ keyExpr = theExprManager->create_fo_expr(theRootSctx,
keyExpr->get_loc(),
GET_BUILTIN_FUNCTION(FN_DISTINCT_VALUES_1),
keyExpr);
@@ -4647,17 +4664,17 @@
**********************/
// "example:coll1"
- expr_t qnameStrExpr = new const_expr(theRootSctx, loc,
+ expr_t qnameStrExpr = theExprManager->create_const_expr(theRootSctx, loc,
ic.getCollName()->get_qname().str());
zstring prefixStr = ic.getCollName()->get_prefix();
zstring uriStr;
theSctx->lookup_ns(uriStr, prefixStr, loc);
- expr_t uriStrExpr = new const_expr(theRootSctx, loc, uriStr);
+ expr_t uriStrExpr = theExprManager->create_const_expr(theRootSctx, loc, uriStr);
// fn:QName("uri", "example:coll1")
- fo_expr_t qnameExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t qnameExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_QNAME_2),
uriStrExpr, qnameStrExpr);
@@ -4666,7 +4683,7 @@
ZORBA_ASSERT(fn_collection != NULL);
std::vector<expr_t> argColl;
argColl.push_back(qnameExpr.getp());
- fo_expr_t collExpr = new fo_expr(theRootSctx, loc, fn_collection, argColl);
+ fo_expr_t collExpr = theExprManager->create_fo_expr(theRootSctx, loc, fn_collection, argColl);
// $x
const QName* varQName = ic.getCollVarName();
@@ -4678,7 +4695,7 @@
varExpr,
collExpr.getp());
- flwor_expr_t flworExpr = new flwor_expr(theRootSctx, loc, false);
+ flwor_expr_t flworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
flworExpr->add_clause(lc);
// flworExpr-> return clause to be set in end_visitor
@@ -4719,7 +4736,7 @@
dynamic_cast<const ICCollUniqueKeyCheck&>(v);
// "org:employees"
- expr_t qnameStrExpr = new const_expr(theRootSctx,
+ expr_t qnameStrExpr = theExprManager->create_const_expr(theRootSctx,
loc,
ic.getCollName()->get_qname().str());
@@ -4727,10 +4744,10 @@
zstring uriStr;
theSctx->lookup_ns(uriStr, prefixStr, loc);
- expr_t uriStrExpr = new const_expr(theRootSctx, loc, uriStr);
+ expr_t uriStrExpr = theExprManager->create_const_expr(theRootSctx, loc, uriStr);
// fn:QName("org-uri", "org:employees")
- fo_expr_t qnameExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t qnameExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_QNAME_2),
uriStrExpr, qnameStrExpr);
@@ -4739,7 +4756,7 @@
ZORBA_ASSERT(fn_collection != NULL);
std::vector<expr_t> argColl;
argColl.push_back(qnameExpr.getp());
- fo_expr_t collExpr = new fo_expr(theRootSctx, loc, fn_collection, argColl);
+ fo_expr_t collExpr = theExprManager->create_fo_expr(theRootSctx, loc, fn_collection, argColl);
// $x
const QName* varQName = ic.getNodeVarName();
@@ -4749,8 +4766,8 @@
// every $x_ in $x satisfies exists ...
// every is implemented as a flowr expr
push_scope();
- flwor_expr_t evFlworExpr = new flwor_expr(theRootSctx, loc, false);
- evFlworExpr->set_return_expr(new const_expr(theRootSctx, loc, true));
+ flwor_expr_t evFlworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
+ evFlworExpr->set_return_expr(theExprManager->create_const_expr(theRootSctx, loc, true));
// $x_ in dc:collection( xs:QName("org:employees") )
var_expr_t evVarExpr = bind_var(loc,
@@ -4775,7 +4792,7 @@
loc,
varExpr,
collExpr.getp());
- flwor_expr_t flworExpr = new flwor_expr(theRootSctx, loc, false);
+ flwor_expr_t flworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
@@ -4810,17 +4827,17 @@
dynamic_cast<const ICCollForeachNode&>(v);
// "org:transactions"
- expr_t qnameStrExpr = new const_expr(theRootSctx, loc,
+ expr_t qnameStrExpr = theExprManager->create_const_expr(theRootSctx, loc,
ic.getCollName()->get_qname().str());
zstring prefixStr = ic.getCollName()->get_prefix();
zstring uriStr;
theSctx->lookup_ns(uriStr, prefixStr, loc);
- expr_t uriStrExpr = new const_expr(theRootSctx, loc, uriStr);
+ expr_t uriStrExpr = theExprManager->create_const_expr(theRootSctx, loc, uriStr);
// fn:QName("org-uri", "org:transactions")
- fo_expr_t qnameExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t qnameExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_QNAME_2),
uriStrExpr, qnameStrExpr);
@@ -4829,13 +4846,13 @@
ZORBA_ASSERT(fn_collection != NULL);
std::vector<expr_t> argColl;
argColl.push_back(qnameExpr.getp());
- fo_expr_t collExpr = new fo_expr(theRootSctx, loc, fn_collection, argColl);
+ fo_expr_t collExpr = theExprManager->create_fo_expr(theRootSctx, loc, fn_collection, argColl);
// every $x_ in $x satisfies exists ...
// every is implemented as a flowr expr
//push_scope();
- flwor_expr_t evFlworExpr = new flwor_expr(theRootSctx, loc, false);
- evFlworExpr->set_return_expr(new const_expr(theRootSctx, loc, true));
+ flwor_expr_t evFlworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
+ evFlworExpr->set_return_expr(theExprManager->create_const_expr(theRootSctx, loc, true));
// $x
const QName* varQName = ic.getCollVarName();
@@ -4882,16 +4899,16 @@
// TO part
// "org:employees"
- expr_t toQnameStrExpr = new const_expr(theRootSctx, loc,
+ expr_t toQnameStrExpr = theExprManager->create_const_expr(theRootSctx, loc,
ic.getToCollName()->get_qname().str());
zstring toPrefixStr = ic.getToCollName()->get_prefix();
zstring toUriStr;
theSctx->lookup_ns(toUriStr, toPrefixStr, loc);
- expr_t toUriStrExpr = new const_expr(theRootSctx, loc, toUriStr);
+ expr_t toUriStrExpr = theExprManager->create_const_expr(theRootSctx, loc, toUriStr);
// xs:QName("org:employees")
- fo_expr_t toQnameExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t toQnameExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_QNAME_2),
toUriStrExpr, toQnameStrExpr);
@@ -4900,14 +4917,14 @@
ZORBA_ASSERT(toFnCollection != NULL);
std::vector<expr_t> toArgColl;
toArgColl.push_back(toQnameExpr.getp());
- fo_expr_t toCollExpr = new fo_expr(theRootSctx, loc, toFnCollection,
+ fo_expr_t toCollExpr = theExprManager->create_fo_expr(theRootSctx, loc, toFnCollection,
toArgColl);
// some $y in dc:collection( xs:QName("org:employees") )
// satisfies ... eq ...
// implemented using flowr
- flwor_expr_t someFlworExpr = new flwor_expr(theRootSctx, loc, false);
- someFlworExpr->set_return_expr(new const_expr(theRootSctx, loc, true));
+ flwor_expr_t someFlworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
+ someFlworExpr->set_return_expr(theExprManager->create_const_expr(theRootSctx, loc, true));
// $y
const QName* toVarQName = ic.getToNodeVarName();
@@ -4921,17 +4938,17 @@
// FROM part
// "org:transactions"
- expr_t fromQnameStrExpr = new const_expr(theRootSctx, loc,
+ expr_t fromQnameStrExpr = theExprManager->create_const_expr(theRootSctx, loc,
ic.getFromCollName()->get_qname().str());
zstring fromPrefixStr = ic.getFromCollName()->get_prefix();
zstring fromUriStr;
theSctx->lookup_ns(fromUriStr, fromPrefixStr, loc);
- expr_t fromUriStrExpr = new const_expr(theRootSctx, loc, fromUriStr);
+ expr_t fromUriStrExpr = theExprManager->create_const_expr(theRootSctx, loc, fromUriStr);
// fn:QName("org-uri", "org:transactions")
- fo_expr_t fromQnameExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t fromQnameExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_QNAME_2),
fromUriStrExpr, fromQnameStrExpr);
@@ -4940,7 +4957,7 @@
ZORBA_ASSERT(fromFnCollection != NULL);
std::vector<expr_t> fromArgColl;
fromArgColl.push_back(fromQnameExpr.getp());
- fo_expr_t fromCollExpr = new fo_expr(theRootSctx,
+ fo_expr_t fromCollExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
fromFnCollection,
fromArgColl);
@@ -4948,8 +4965,8 @@
// every $x in dc:collection( xs:QName("org:transactions") )
// satisfies ...
// implemented using flowr
- flwor_expr_t evFlworExpr = new flwor_expr(theRootSctx, loc, false);
- evFlworExpr->set_return_expr(new const_expr(theRootSctx, loc, true));
+ flwor_expr_t evFlworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
+ evFlworExpr->set_return_expr(theExprManager->create_const_expr(theRootSctx, loc, true));
// $x
const QName* fromVarQName = ic.getFromNodeVarName();
@@ -5050,14 +5067,14 @@
expr_t atomizedUniKeyExpr = wrap_in_atomization(uniKeyExpr.getp());
// exists( $x/@id )
- expr_t existsExpr = new fo_expr(theRootSctx, loc,
+ expr_t existsExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_EXISTS_1),
uniKeyExpr.getp());
#if 0
zstring commentStr("#trace fnExists");
- expr_t comentExpr = new const_expr(theRootSctx, loc, commentStr);
- fo_expr_t fnTraceExpr = new fo_expr(theRootSctx,
+ expr_t comentExpr = theExprManager->create_const_expr(theRootSctx, loc, commentStr);
+ fo_expr_t fnTraceExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_TRACE_2),
existsExpr.getp(), comentExpr.getp());
@@ -5065,14 +5082,14 @@
// every ... satisfies evTestExpr
- fo_expr_t fnNotExpr = new fo_expr(theRootSctx,
+ fo_expr_t fnNotExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_NOT_1),
existsExpr);
evFlworExpr->add_where(fnNotExpr.getp());
- fo_expr_t everyExpr = new fo_expr(theRootSctx,
+ fo_expr_t everyExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_EMPTY_1),
evFlworExpr.getp());
@@ -5080,25 +5097,25 @@
// functx:are-distinct-values( $x/@id )
// implemented as count(distinct-values($seq)) = count($seq)
//distinct-values($seq)
- fo_expr_t distinctValuesExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t distinctValuesExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_DISTINCT_VALUES_1),
atomizedUniKeyExpr.getp());
// count($sec)
- fo_expr_t countSecExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t countSecExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_COUNT_1),
atomizedUniKeyExpr.getp());
// count(distinct-values($sec))
- fo_expr_t countDVExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t countDVExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_COUNT_1),
distinctValuesExpr.getp());
// countDV = countSec
- fo_expr_t equalExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t equalExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(OP_EQUAL_2),
countDVExpr.getp(), countSecExpr.getp());
// (...) and (...)
- fo_expr_t andExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t andExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(OP_AND_N),
everyExpr.getp(), equalExpr.getp());
@@ -5134,7 +5151,7 @@
dynamic_cast<flwor_expr*>(pop_nodestack().getp());
// fn:not
- fo_expr_t fnNotExpr = new fo_expr(theRootSctx,
+ fo_expr_t fnNotExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_NOT_1),
evTestExpr.getp());
@@ -5143,7 +5160,7 @@
evFlworExpr->add_where(fnNotExpr.getp());
// fn:empty
- fo_expr_t emptyExpr = new fo_expr(theRootSctx,
+ fo_expr_t emptyExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_EMPTY_1),
evFlworExpr.getp());
@@ -5170,7 +5187,7 @@
// maybe add fn:data ?
// $y/id eq $x//sale/empid
- fo_expr_t eqExpr = new fo_expr(theRootSctx,
+ fo_expr_t eqExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(OP_VALUE_EQUAL_2),
toKeyExpr.getp(),
@@ -5182,11 +5199,11 @@
someFlworExpr->add_where(someTestExpr.getp());
// fn:exists
- fo_expr_t fnExistsExpr = new fo_expr(theRootSctx, loc,
+ fo_expr_t fnExistsExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(FN_EXISTS_1),
someFlworExpr.getp());
// fn:not()
- fo_expr_t evFnNotExpr = new fo_expr(theRootSctx,
+ fo_expr_t evFnNotExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_NOT_1),
fnExistsExpr.getp());
@@ -5194,7 +5211,7 @@
evFlworExpr->add_where(evFnNotExpr.getp());
// fn:empty
- fo_expr_t fnEmptyExpr = new fo_expr(theRootSctx,
+ fo_expr_t fnEmptyExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_EMPTY_1),
evFlworExpr.getp());
@@ -5316,7 +5333,7 @@
if (program->is_updating() && !theCCB->theIsEval)
{
- program = new apply_expr(theRootSctx,
+ program = theExprManager->create_apply_expr(theRootSctx,
program->get_loc(),
program,
false); // don't discard XDM
@@ -5410,7 +5427,7 @@
// push a dummy block_expr in the node stack so that local var decls can
// assert that their parent is a block expr.
- expr_t dummyBlock = new block_expr(theRootSctx, loc, false, stmts, NULL);
+ expr_t dummyBlock = theExprManager->create_block_expr(theRootSctx, loc, false, stmts, NULL);
push_nodestack(dummyBlock);
push_scope();
@@ -5450,7 +5467,7 @@
}
else
{
- childExpr = new apply_expr(theRootSctx, loc, childExpr, false);
+ childExpr = theExprManager->create_apply_expr(theRootSctx, loc, childExpr, false);
}
}
@@ -5481,7 +5498,7 @@
std::vector<var_expr*>& prevAssignedVars = theAssignedVars[numScopes-1];
std::vector<var_expr*>& lastAssignedVars = theAssignedVars[numScopes];
- expr_t blockExpr = new block_expr(theRootSctx,
+ expr_t blockExpr = theExprManager->create_block_expr(theRootSctx,
loc,
allowLastUpdating,
stmts,
@@ -5559,13 +5576,17 @@
expr_t valueExpr = pop_nodestack();
if (varType != NULL)
+<<<<<<< TREE
valueExpr = new treat_expr(theRootSctx,
loc,
valueExpr,
varType,
TreatIterator::TYPE_MATCH);
+=======
+ valueExpr = theExprManager->create_treat_expr(theRootSctx, loc, valueExpr, varType, err::XPTY0004);
+>>>>>>> MERGE-SOURCE
- push_nodestack(new var_set_expr(theRootSctx, loc, ve, valueExpr));
+ push_nodestack(theExprManager->create_var_set_expr(theRootSctx, loc, ve, valueExpr));
theAssignedVars.back().push_back(ve.getp());
}
@@ -5585,7 +5606,7 @@
{
expr_t param = pop_nodestack();
- push_nodestack(new apply_expr(theRootSctx,
+ push_nodestack(theExprManager->create_apply_expr(theRootSctx,
param->get_loc(),
param,
true)); // discard XDM
@@ -5617,7 +5638,7 @@
if (!inUDFBody() && !theCCB->theIsEval)
{
- childExpr = new apply_expr(theRootSctx, loc, childExpr, false);
+ childExpr = theExprManager->create_apply_expr(theRootSctx, loc, childExpr, false);
}
}
else if (childExpr->is_sequential())
@@ -5625,7 +5646,7 @@
theHaveSequentialExitExprs = true;
}
- expr_t exitExpr = new exit_expr(theRootSctx, loc, childExpr);
+ expr_t exitExpr = theExprManager->create_exit_expr(theRootSctx, loc, childExpr);
if (inUDFBody())
{
@@ -5661,11 +5682,11 @@
expr_t bodyExpr = pop_nodestack();
expr_t condExpr = pop_nodestack();
- condExpr = new if_expr(theRootSctx,
+ condExpr = theExprManager->create_if_expr(theRootSctx,
loc,
condExpr,
create_empty_seq(loc),
- new flowctl_expr(theRootSctx, loc, flowctl_expr::BREAK));
+ theExprManager->create_flowctl_expr(theRootSctx, loc, flowctl_expr::BREAK));
block_expr* seqBody = NULL;
@@ -5674,9 +5695,9 @@
stmts.push_back(condExpr);
stmts.push_back(bodyExpr);
- seqBody = new block_expr(bodyExpr->get_sctx(), loc, false, stmts, NULL);
+ seqBody = theExprManager->create_block_expr(bodyExpr->get_sctx(), loc, false, stmts, NULL);
- push_nodestack(new while_expr(theRootSctx, loc, seqBody));
+ push_nodestack(theExprManager->create_while_expr(theRootSctx, loc, seqBody));
theInWhileStack.pop();
}
@@ -5722,7 +5743,7 @@
ZORBA_FATAL(false, "");
}
- push_nodestack(new flowctl_expr(theRootSctx, loc, a));
+ push_nodestack(theExprManager->create_flowctl_expr(theRootSctx, loc, a));
}
@@ -5753,10 +5774,17 @@
args.push_back(e);
}
+<<<<<<< TREE
fo_expr_t concatExpr = new fo_expr(theRootSctx,
loc,
op_concatenate,
args);
+=======
+ fo_expr_t concatExpr = theExprManager->create_fo_expr(theRootSctx,
+ loc,
+ op_concatenate,
+ args);
+>>>>>>> MERGE-SOURCE
normalize_fo(concatExpr.getp());
push_nodestack(concatExpr.getp());
@@ -5840,7 +5868,7 @@
ERROR_PARAMS(ZED(XPST0003_XQueryVersionAtLeast30_2), theSctx->xquery_version()));
}
- rchandle<flwor_expr> flwor = new flwor_expr(theRootSctx, loc, v.is_general());
+ rchandle<flwor_expr> flwor = theExprManager->create_flwor_expr(theRootSctx, loc, v.is_general());
expr_t retExpr = pop_nodestack();
@@ -6501,6 +6529,7 @@
{
const GroupSpec& groupSpec = *groupSpecs[i];
+<<<<<<< TREE
csize j;
for (j = 0; j < i; ++j)
{
@@ -6561,6 +6590,23 @@
collations.push_back ("");
}
}
+=======
+ output_var = pop_nodestack_var();
+ input_var = pop_nodestack_var();
+
+ if (groupSpec.group_coll_spec() != NULL)
+ collations.push_back(groupSpec.group_coll_spec()->get_uri().str());
+ else
+ collations.push_back ("");
+
+ wrapper_expr_t input_wrapper;
+ input_wrapper = theExprManager->create_wrapper_expr(theRootSctx,
+ loc,
+ static_cast<expr*>(input_var.getp()));
+
+ grouping_rebind.push_back(std::pair<wrapper_expr_t, var_expr_t>(input_wrapper,
+ output_var));
+>>>>>>> MERGE-SOURCE
}
push_scope();
@@ -6569,6 +6615,7 @@
while (NULL != (ngvar = pop_nodestack_var()))
{
+<<<<<<< TREE
var_expr_t inputVar = pop_nodestack_var();
bind_var(ngvar, theSctx);
@@ -6576,6 +6623,17 @@
expr_t inputExpr = new wrapper_expr(theRootSctx, loc, inputVar.getp());
nongrouping_rebind.push_back(std::pair<expr_t, var_expr_t>(inputExpr, ngvar));
+=======
+ input_var = pop_nodestack_var();
+
+ wrapper_expr_t input_wrapper;
+ input_wrapper = theExprManager->create_wrapper_expr(theRootSctx,
+ loc,
+ static_cast<expr*>(input_var.getp()));
+
+ nongrouping_rebind.push_back(std::pair<wrapper_expr_t, var_expr_t>(input_wrapper,
+ output_var));
+>>>>>>> MERGE-SOURCE
}
group_clause* clause = new group_clause(theRootSctx,
@@ -6922,13 +6980,13 @@
// else $atomv
// return NULL]
static_cast<flwor_expr*>(atomizedFlwor.getp())->set_return_expr(
- new if_expr(theRootSctx,
+ theExprManager->create_if_expr(theRootSctx,
loc,
- new instanceof_expr(theRootSctx,
+ theExprManager->create_instanceof_expr(theRootSctx,
loc,
atomv.getp(),
theRTM.UNTYPED_ATOMIC_TYPE_ONE),
- new cast_expr(theRootSctx,
+ theExprManager->create_cast_expr(theRootSctx,
loc,
atomv.getp(),
theRTM.STRING_TYPE_ONE),
@@ -6965,7 +7023,7 @@
expr_t operandExpr = pop_nodestack();
operandExpr = wrap_in_atomization(operandExpr);
- operandExpr = new fo_expr(theRootSctx, loc,
+ operandExpr = theExprManager->create_fo_expr(theRootSctx, loc,
GET_BUILTIN_FUNCTION(OP_ATOMIC_VALUES_EQUIVALENT_2),
sv,
operandExpr);
@@ -6979,7 +7037,7 @@
}
else if (condOperands.size() > 1)
{
- condExpr = new fo_expr(theRootSctx,
+ condExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(OP_OR_N),
condOperands);
@@ -6989,7 +7047,7 @@
expr_t caseReturnExpr = pop_nodestack();
// retExpr = [if (condExpr) then caseReturnExpr else retExpr]
- retExpr = new if_expr(theRootSctx, loc, condExpr, caseReturnExpr, retExpr);
+ retExpr = theExprManager->create_if_expr(theRootSctx, loc, condExpr, caseReturnExpr, retExpr);
} // for
@@ -7154,7 +7212,7 @@
caseVar = bind_var(loc, varname, var_expr::let_var);
- expr_t treatExpr = new treat_expr(theRootSctx,
+ expr_t treatExpr = theExprManager->create_treat_expr(theRootSctx,
loc,
sv.getp(),
type,
@@ -7181,9 +7239,9 @@
}
// retExpr = [if (instance_of($sv, type)) then clauseExpr else retExpr]
- retExpr = new if_expr(theRootSctx,
+ retExpr = theExprManager->create_if_expr(theRootSctx,
loc,
- new instanceof_expr(theRootSctx, loc, &*sv, type),
+ theExprManager->create_instanceof_expr(theRootSctx, loc, &*sv, type),
clauseExpr,
retExpr);
}
@@ -7270,7 +7328,7 @@
wrap_in_debugger_expr(t_h, t_h->get_loc());
wrap_in_debugger_expr(c_h, c_h->get_loc());
- if_expr* ifExpr = new if_expr(theRootSctx, loc, c_h, t_h, e_h);
+ if_expr* ifExpr = theExprManager->create_if_expr(theRootSctx, loc, c_h, t_h, e_h);
push_nodestack(ifExpr);
}
@@ -7321,7 +7379,7 @@
expr_t tryExpr = pop_nodestack();
- trycatch_expr* tce = new trycatch_expr(theRootSctx, loc, tryExpr);
+ trycatch_expr* tce = theExprManager->create_trycatch_expr(theRootSctx, loc, tryExpr);
push_nodestack(tce);
@@ -7432,9 +7490,9 @@
{
TRACE_VISIT();
- rchandle<flwor_expr> flwor(new flwor_expr(theRootSctx, loc, false));
+ rchandle<flwor_expr> flwor(theExprManager->create_flwor_expr(theRootSctx, loc, false));
- flwor->set_return_expr(new const_expr(theRootSctx, loc, true));
+ flwor->set_return_expr(theExprManager->create_const_expr(theRootSctx, loc, true));
push_nodestack(flwor.getp());
@@ -7450,7 +7508,7 @@
if (v.get_qmode() == ParseConstants::quant_every)
{
- rchandle<fo_expr> uw = new fo_expr(theRootSctx,
+ rchandle<fo_expr> uw = theExprManager->create_fo_expr(theRootSctx,
v.get_expr()->get_location(),
GET_BUILTIN_FUNCTION(FN_NOT_1),
testExpr);
@@ -7471,7 +7529,7 @@
flworExpr->add_where(testExpr);
- rchandle<fo_expr> quant = new fo_expr(theRootSctx,
+ rchandle<fo_expr> quant = theExprManager->create_fo_expr(theRootSctx,
loc,
v.get_qmode() == ParseConstants::quant_every ?
GET_BUILTIN_FUNCTION(FN_EMPTY_1) :
@@ -7590,7 +7648,7 @@
args.push_back(e1);
}
- fo_expr* fo = new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_OR_N), args);
+ fo_expr* fo = theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_OR_N), args);
push_nodestack(fo);
}
@@ -7655,7 +7713,7 @@
args.push_back(e1);
}
- fo_expr* fo = new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_AND_N), args);
+ fo_expr* fo = theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_AND_N), args);
push_nodestack(fo);
}
@@ -7749,7 +7807,7 @@
rchandle<expr> e1 = pop_nodestack();
rchandle<expr> e2 = pop_nodestack();
- fo_expr* fo = new fo_expr(theRootSctx, loc, f, e2, e1);
+ fo_expr* fo = theExprManager->create_fo_expr(theRootSctx, loc, f, e2, e1);
normalize_fo(fo);
@@ -7820,7 +7878,7 @@
rchandle<expr> e1 = pop_nodestack();
rchandle<expr> e2 = pop_nodestack();
- fo_expr* e = new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_TO_2), e2, e1);
+ fo_expr* e = theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_TO_2), e2, e1);
normalize_fo(e);
@@ -7856,7 +7914,7 @@
break;
}
- fo_expr* foExpr = new fo_expr(theRootSctx, loc, func, e2, e1);
+ fo_expr* foExpr = theExprManager->create_fo_expr(theRootSctx, loc, func, e2, e1);
normalize_fo(foExpr);
@@ -7897,7 +7955,7 @@
break;
}
- fo_expr* foExpr = new fo_expr(theRootSctx, loc, f, e2, e1);
+ fo_expr* foExpr = theExprManager->create_fo_expr(theRootSctx, loc, f, e2, e1);
normalize_fo(foExpr);
@@ -7921,7 +7979,7 @@
rchandle<expr> e1 = pop_nodestack();
rchandle<expr> e2 = pop_nodestack();
- fo_expr* foExpr = new fo_expr(theRootSctx,
+ fo_expr* foExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(OP_UNION_2),
e2,
@@ -7931,7 +7989,7 @@
// Union is implemented by a concat iterator, so we have to do node sorting
// and duplicate elimi
- push_nodestack(new fo_expr(theRootSctx,
+ push_nodestack(theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(OP_SORT_DISTINCT_NODES_ASC_1),
foExpr));
@@ -7966,11 +8024,11 @@
break;
}
- fo_expr* foExpr = new fo_expr(theRootSctx, loc, f, e2, e1);
+ fo_expr* foExpr = theExprManager->create_fo_expr(theRootSctx, loc, f, e2, e1);
normalize_fo(foExpr);
- push_nodestack(new fo_expr(theRootSctx,
+ push_nodestack(theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(OP_SORT_DISTINCT_NODES_ASC_1),
foExpr));
@@ -7990,7 +8048,7 @@
{
TRACE_VISIT_OUT();
- push_nodestack(new instanceof_expr(theRootSctx,
+ push_nodestack(theExprManager->create_instanceof_expr(theRootSctx,
loc,
pop_nodestack(),
pop_tstack()));
@@ -8010,7 +8068,7 @@
{
TRACE_VISIT_OUT();
- push_nodestack(new treat_expr(theRootSctx,
+ push_nodestack(theExprManager->create_treat_expr(theRootSctx,
loc,
pop_nodestack(),
pop_tstack(),
@@ -8086,9 +8144,9 @@
assert(castLiteral != NULL || ! isCast);
if (isCast)
- return new const_expr(theRootSctx, loc, castLiteral);
+ return theExprManager->create_const_expr(theRootSctx, loc, castLiteral);
else
- return new const_expr(theRootSctx, loc, castLiteral != NULL);
+ return theExprManager->create_const_expr(theRootSctx, loc, castLiteral != NULL);
}
else
{
@@ -8099,21 +8157,25 @@
// when casting to type T, where T is QName or subtype of, and the input
// is not a const expr, then the input MUST be of type T or subtype of.
if (isCast)
+<<<<<<< TREE
return new treat_expr(theRootSctx,
loc,
node,
qnameType,
TreatIterator::TYPE_MATCH);
+=======
+ return theExprManager->create_treat_expr(theRootSctx, loc, node, qnameType, err::XPTY0004);
+>>>>>>> MERGE-SOURCE
else
- return new instanceof_expr(theRootSctx, loc, node, qnameType);
+ return theExprManager->create_instanceof_expr(theRootSctx, loc, node, qnameType);
}
}
else
{
if (isCast)
- return new cast_expr(theRootSctx, loc, wrap_in_atomization(node), type);
+ return theExprManager->create_cast_expr(theRootSctx, loc, wrap_in_atomization(node), type);
else
- return new castable_expr(theRootSctx, loc, wrap_in_atomization(node), type);
+ return theExprManager->create_castable_expr(theRootSctx, loc, wrap_in_atomization(node), type);
}
}
@@ -8150,7 +8212,7 @@
rchandle<expr> e1 = pop_nodestack();
- fo_expr* foExpr = new fo_expr(theRootSctx,
+ fo_expr* foExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
(v.get_signlist()->get_sign() ?
GET_BUILTIN_FUNCTION(OP_UNARY_PLUS_1) :
@@ -8206,7 +8268,7 @@
v.get_type_name()->get_localname().c_str());
}
- push_nodestack(new validate_expr(theRootSctx,
+ push_nodestack(theExprManager->create_validate_expr(theRootSctx,
loc,
v.get_valmode(),
qname,
@@ -8498,7 +8560,7 @@
// In cases 2, 3, and 4 create a new empty relpath_expr
if (pe_type != ParseConstants::path_leading_lone_slash)
{
- pathExpr = new relpath_expr(theRootSctx, loc);
+ pathExpr = theExprManager->create_relpath_expr(theRootSctx, loc);
}
// If path expr starts with / or // (cases 1, 2, or 3), create an expr
@@ -8512,9 +8574,9 @@
if (pe_type != ParseConstants::path_relative)
{
- rchandle<relpath_expr> ctx_path_expr = new relpath_expr(theRootSctx, loc);
+ rchandle<relpath_expr> ctx_path_expr = theExprManager->create_relpath_expr(theRootSctx, loc);
- expr_t sourceExpr = new treat_expr(theRootSctx,
+ expr_t sourceExpr = theExprManager->create_treat_expr(theRootSctx,
loc,
DOT_REF,
GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
@@ -8522,15 +8584,15 @@
ctx_path_expr->add_back(sourceExpr);
- rchandle<match_expr> me = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> me = theExprManager->create_match_expr(theRootSctx, loc);
me->setTestKind(match_anykind_test);
- rchandle<axis_step_expr> ase = new axis_step_expr(theRootSctx, loc);
+ rchandle<axis_step_expr> ase = theExprManager->create_axis_step_expr(theRootSctx, loc);
ase->setAxis(axis_kind_self);
ase->setTest(me);
ctx_path_expr->add_back(&*ase);
- fo_expr_t fnroot = new fo_expr(theRootSctx,
+ fo_expr_t fnroot = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_ROOT_1),
ctx_path_expr.getp());
@@ -8547,7 +8609,7 @@
else
{
// case 1
- expr_t result = new treat_expr(theRootSctx,
+ expr_t result = theExprManager->create_treat_expr(theRootSctx,
loc,
fnroot.getp(),
GENV_TYPESYSTEM.DOCUMENT_TYPE_ONE,
@@ -8587,7 +8649,7 @@
else
{
rchandle<fo_expr> checkExpr =
- new fo_expr(theRootSctx,
+ theExprManager->create_fo_expr(theRootSctx,
arg2->get_loc(),
GET_BUILTIN_FUNCTION(OP_EITHER_NODES_OR_ATOMICS_1),
arg2);
@@ -8638,7 +8700,7 @@
// then the input expr to the this path expr is "treat . as node()"
if (axisStep != NULL)
{
- expr_t sourceExpr = new treat_expr(theRootSctx,
+ expr_t sourceExpr = theExprManager->create_treat_expr(theRootSctx,
loc,
DOT_REF,
GENV_TYPESYSTEM.ANY_NODE_TYPE_ONE,
@@ -8725,7 +8787,7 @@
errKind = TreatIterator::PATH_DOT;
}
- expr_t sourceExpr = new treat_expr(theRootSctx,
+ expr_t sourceExpr = theExprManager->create_treat_expr(theRootSctx,
stepExpr->get_loc(),
stepExpr,
GENV_TYPESYSTEM.ANY_NODE_TYPE_STAR,
@@ -8756,7 +8818,7 @@
flworExpr->set_return_expr(stepExpr);
pop_scope();
- pathExpr = new relpath_expr(theRootSctx, loc);
+ pathExpr = theExprManager->create_relpath_expr(theRootSctx, loc);
expr_t sourceExpr = flworExpr;
@@ -8778,8 +8840,8 @@
// Convert // to /descendant-or-self::node()/
if (rpe.get_step_type() == ParseConstants::st_slashslash)
{
- rchandle<axis_step_expr> ase = new axis_step_expr(theRootSctx, loc);
- rchandle<match_expr> me = new match_expr(theRootSctx, loc);
+ rchandle<axis_step_expr> ase = theExprManager->create_axis_step_expr(theRootSctx, loc);
+ rchandle<match_expr> me = theExprManager->create_match_expr(theRootSctx, loc);
me->setTestKind(match_anykind_test);
ase->setAxis(axis_kind_descendant_or_self);
ase->setTest(me);
@@ -8872,7 +8934,7 @@
{
TRACE_VISIT();
- rchandle<axis_step_expr> ase = new axis_step_expr(theRootSctx, loc);
+ rchandle<axis_step_expr> ase = theExprManager->create_axis_step_expr(theRootSctx, loc);
push_nodestack(ase.getp());
theNodeSortStack.top().theNumSteps++;
@@ -8928,8 +8990,8 @@
//
// The flworExpr as well as the $$predInput varExpr are pushed to the nodestack.
const for_clause* fcOuterDot = static_cast<const for_clause*>(flworExpr->get_clause(0));
- rchandle<relpath_expr> predPathExpr = new relpath_expr(theRootSctx, loc);
- predPathExpr->add_back(new wrapper_expr(theRootSctx, loc, fcOuterDot->get_var()));
+ rchandle<relpath_expr> predPathExpr = theExprManager->create_relpath_expr(theRootSctx, loc);
+ predPathExpr->add_back(theExprManager->create_wrapper_expr(theRootSctx, loc, fcOuterDot->get_var()));
predPathExpr->add_back(axisExpr.getp());
expr_t predInputExpr = predPathExpr;
@@ -9160,7 +9222,7 @@
if ((axisExpr = dynamic_cast<axis_step_expr *>(top)) != NULL)
{
// Construct name-test match expr
- rchandle<match_expr> matchExpr = new match_expr(theRootSctx, loc);;
+ rchandle<match_expr> matchExpr = theExprManager->create_match_expr(theRootSctx, loc);;
matchExpr->setTestKind(match_name_test);
if (v.getQName() != NULL)
@@ -9436,26 +9498,26 @@
std::vector<expr_t> condOperands(3);
condOperands[0] =
- new instanceof_expr(theRootSctx, loc, predvar, rtm.DECIMAL_TYPE_QUESTION, true);
+ theExprManager->create_instanceof_expr(theRootSctx, loc, predvar, rtm.DECIMAL_TYPE_QUESTION, true);
condOperands[1] =
- new instanceof_expr(theRootSctx, loc, predvar, rtm.DOUBLE_TYPE_QUESTION, true);
+ theExprManager->create_instanceof_expr(theRootSctx, loc, predvar, rtm.DOUBLE_TYPE_QUESTION, true);
condOperands[2] =
- new instanceof_expr(theRootSctx, loc, predvar, rtm.FLOAT_TYPE_QUESTION, true);
+ theExprManager->create_instanceof_expr(theRootSctx, loc, predvar, rtm.FLOAT_TYPE_QUESTION, true);
- condExpr = new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_OR_N), condOperands);
+ condExpr = theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(OP_OR_N), condOperands);
// If so: return $dot if the value of the pred expr is equal to the value
// of $dot_pos var, otherwise return the empty seq.
- fo_expr_t eqExpr = new fo_expr(theRootSctx,
+ fo_expr_t eqExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(OP_VALUE_EQUAL_2),
lookup_ctx_var(DOT_POS_VARNAME, loc),
predvar);
normalize_fo(eqExpr);
- expr_t thenExpr = new if_expr(theRootSctx,
+ expr_t thenExpr = theExprManager->create_if_expr(theRootSctx,
loc,
eqExpr.getp(),
DOT_REF,
@@ -9463,14 +9525,14 @@
// Else, return $dot if the the value of the pred expr is true, otherwise
// return the empty seq.
- expr_t elseExpr = new if_expr(theRootSctx,
+ expr_t elseExpr = theExprManager->create_if_expr(theRootSctx,
loc,
predvar,
DOT_REF,
create_empty_seq(loc));
// The outer if
- expr_t ifExpr = new if_expr(theRootSctx, loc, condExpr.getp(), thenExpr, elseExpr);
+ expr_t ifExpr = theExprManager->create_if_expr(theRootSctx, loc, condExpr.getp(), thenExpr, elseExpr);
flworExpr->set_return_expr(ifExpr);
@@ -9538,17 +9600,17 @@
{
case ParseConstants::num_integer:
{
- push_nodestack(new const_expr(theRootSctx, loc, v.get<xs_integer>()));
+ push_nodestack(theExprManager->create_const_expr(theRootSctx, loc, v.get<xs_integer>()));
break;
}
case ParseConstants::num_decimal:
{
- push_nodestack(new const_expr(theRootSctx, loc, v.get<xs_decimal>()));
+ push_nodestack(theExprManager->create_const_expr(theRootSctx, loc, v.get<xs_decimal>()));
break;
}
case ParseConstants::num_double:
{
- push_nodestack(new const_expr(theRootSctx, loc, v.get<xs_double>()));
+ push_nodestack(theExprManager->create_const_expr(theRootSctx, loc, v.get<xs_double>()));
break;
}
}
@@ -9585,7 +9647,7 @@
{
TRACE_VISIT_OUT();
- push_nodestack(new const_expr(theRootSctx, loc,v.get_strval().str()));
+ push_nodestack(theExprManager->create_const_expr(theRootSctx, loc,v.get_strval().str()));
}
/*******************************************************************************
@@ -9627,7 +9689,11 @@
concat_args.push_back(right);
}
+<<<<<<< TREE
rchandle<expr> concat = new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_CONCAT_N), concat_args);
+=======
+ rchandle<expr> concat = theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_CONCAT_N), concat_args);
+>>>>>>> MERGE-SOURCE
push_nodestack(concat);
}
@@ -9722,7 +9788,7 @@
}
}
- push_nodestack(new wrapper_expr(theRootSctx, loc, rchandle<expr>(ve)));
+ push_nodestack(theExprManager->create_wrapper_expr(theRootSctx, loc, rchandle<expr>(ve)));
}
@@ -9787,7 +9853,7 @@
{
TRACE_VISIT_OUT();
- push_nodestack(new order_expr(theRootSctx,
+ push_nodestack(theExprManager->create_order_expr(theRootSctx,
loc,
order_expr::ordered,
pop_nodestack()));
@@ -9808,7 +9874,7 @@
{
TRACE_VISIT_OUT();
- push_nodestack(new order_expr(theRootSctx,
+ push_nodestack(theExprManager->create_order_expr(theRootSctx,
loc,
order_expr::unordered,
pop_nodestack()));
@@ -9961,19 +10027,19 @@
{
case FunctionConsts::FN_HEAD_1:
{
- arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one()));
- arguments.push_back(new const_expr(theRootSctx, loc, xs_integer::one()));
+ arguments.push_back(theExprManager->create_const_expr(theRootSctx, loc, xs_integer::one()));
+ arguments.push_back(theExprManager->create_const_expr(theRootSctx, loc, xs_integer::one()));
function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_3);
- fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
+ fo_expr_t foExpr = theExprManager->create_fo_expr(theRootSctx, loc, f, arguments);
normalize_fo(foExpr);
push_nodestack(foExpr.getp());
return;
}
case FunctionConsts::FN_TAIL_1:
{
- arguments.push_back(new const_expr(theRootSctx, loc, xs_integer(2)));
+ arguments.push_back(theExprManager->create_const_expr(theRootSctx, loc, xs_integer(2)));
function* f = GET_BUILTIN_FUNCTION(OP_ZORBA_SUBSEQUENCE_INT_2);
- fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
+ fo_expr_t foExpr = theExprManager->create_fo_expr(theRootSctx, loc, f, arguments);
normalize_fo(foExpr);
push_nodestack(foExpr.getp());
return;
@@ -10011,7 +10077,7 @@
}
}
- fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
+ fo_expr_t foExpr = theExprManager->create_fo_expr(theRootSctx, loc, f, arguments);
normalize_fo(foExpr);
push_nodestack(foExpr.getp());
return;
@@ -10046,17 +10112,17 @@
var_expr_t tv = create_temp_var(loc, var_expr::let_var);
- expr_t nanExpr = new const_expr(theRootSctx, loc, xs_double::nan());
+ expr_t nanExpr = theExprManager->create_const_expr(theRootSctx, loc, xs_double::nan());
- expr_t condExpr = new castable_expr(theRootSctx, loc, &*tv, theRTM.DOUBLE_TYPE_ONE);
+ expr_t condExpr = theExprManager->create_castable_expr(theRootSctx, loc, &*tv, theRTM.DOUBLE_TYPE_ONE);
expr_t castExpr = create_cast_expr(loc, tv.getp(), theRTM.DOUBLE_TYPE_ONE, true);
- expr_t ret = new if_expr(theRootSctx, loc, condExpr, castExpr, nanExpr);
+ expr_t ret = theExprManager->create_if_expr(theRootSctx, loc, condExpr, castExpr, nanExpr);
expr_t data_expr = wrap_in_atomization(arguments[0]);
- push_nodestack(&*wrap_in_let_flwor(new treat_expr(theRootSctx,
+ push_nodestack(&*wrap_in_let_flwor(theExprManager->create_treat_expr(theRootSctx,
loc,
data_expr,
theRTM.ANY_ATOMIC_TYPE_QUESTION,
@@ -10077,9 +10143,9 @@
if (baseuri.empty())
push_nodestack(create_empty_seq(loc));
else
- push_nodestack(new cast_expr(theRootSctx,
+ push_nodestack(theExprManager->create_cast_expr(theRootSctx,
loc,
- new const_expr(theRootSctx, loc, baseuri),
+ theExprManager->create_const_expr(theRootSctx, loc, baseuri),
GENV_TYPESYSTEM.ANY_URI_TYPE_ONE));
return;
}
@@ -10104,15 +10170,15 @@
fo_expr_t normExpr;
fo_expr_t tokenExpr;
zstring space(" ");
- rchandle<const_expr> constExpr = new const_expr(theRootSctx, loc, space);
+ rchandle<const_expr> constExpr = theExprManager->create_const_expr(theRootSctx, loc, space);
- normExpr = new fo_expr(theRootSctx,
+ normExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_NORMALIZE_SPACE_1),
flworVarExpr);
normalize_fo(normExpr);
- tokenExpr = new fo_expr(theRootSctx,
+ tokenExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_TOKENIZE_2),
normExpr.getp(),
@@ -10141,7 +10207,7 @@
case FunctionConsts::FN_RESOLVE_URI_1:
{
zstring baseUri = theSctx->get_base_uri();
- arguments.insert(arguments.begin(), new const_expr(theRootSctx, loc, baseUri));
+ arguments.insert(arguments.begin(), theExprManager->create_const_expr(theRootSctx, loc, baseUri));
f = GET_BUILTIN_FUNCTION(FN_RESOLVE_URI_2);
break;
}
@@ -10187,7 +10253,7 @@
if (f != NULL && f->getKind() == FunctionConsts::FN_APPLY_1)
{
- expr_t applyExpr = new apply_expr(theRootSctx, loc, arguments[0], false);
+ expr_t applyExpr = theExprManager->create_apply_expr(theRootSctx, loc, arguments[0], false);
push_nodestack(applyExpr);
return;
}
@@ -10279,7 +10345,7 @@
// Create and normalize the fo expr
std::reverse(arguments.begin(), arguments.end());
- fo_expr_t foExpr = new fo_expr(theRootSctx, loc, f, arguments);
+ fo_expr_t foExpr = theExprManager->create_fo_expr(theRootSctx, loc, f, arguments);
normalize_fo(foExpr);
@@ -10305,7 +10371,7 @@
{
FunctionConsts::FunctionKind fkind = FunctionConsts::OP_SORT_NODES_ASC_1;
- resultExpr = new fo_expr(theRootSctx,
+ resultExpr = theExprManager->create_fo_expr(theRootSctx,
foExpr->get_loc(),
BuiltinFunctionLibrary::getFunction(fkind),
foExpr);
@@ -10316,7 +10382,7 @@
{
FunctionConsts::FunctionKind fkind = FunctionConsts::OP_SORT_DISTINCT_NODES_ASC_1;
- resultExpr = new fo_expr(theRootSctx,
+ resultExpr = theExprManager->create_fo_expr(theRootSctx,
foExpr->get_loc(),
BuiltinFunctionLibrary::getFunction(fkind),
foExpr);
@@ -10362,8 +10428,12 @@
scriptingKind = SEQUENTIAL_FUNC_EXPR;
}
+<<<<<<< TREE
rchandle<eval_expr> evalExpr = new eval_expr(theCCB,
theRootSctx,
+=======
+ rchandle<eval_expr> evalExpr = theExprManager->create_eval_expr(theRootSctx,
+>>>>>>> MERGE-SOURCE
loc,
foExpr->get_arg(0),
scriptingKind,
@@ -10441,7 +10511,7 @@
}
// create a flwor with LETs to hold the parameters
- flwor_expr_t flworExpr = new flwor_expr(theRootSctx, loc, false);
+ flwor_expr_t flworExpr = theExprManager->create_flwor_expr(theRootSctx, loc, false);
// wrap function's QName
expr_t qnameExpr = wrap_in_atomization(arguments[0]);
@@ -10484,42 +10554,46 @@
// Expanded QName's namespace URI
expr_t namespaceExpr =
- new fo_expr(theRootSctx,
+ theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_NAMESPACE_URI_FROM_QNAME_1),
temp_vars[0]);
namespaceExpr =
- new fo_expr(theRootSctx,
+ theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_STRING_1),
namespaceExpr);
// Expanded QName's local name
expr_t localExpr =
- new fo_expr(theRootSctx,
+ theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_LOCAL_NAME_FROM_QNAME_1),
temp_vars[0]);
localExpr =
- new fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_STRING_1), localExpr);
+ theExprManager->create_fo_expr(theRootSctx, loc, GET_BUILTIN_FUNCTION(FN_STRING_1), localExpr);
// qnameExpr := concat("\"", namespaceExpr, "\":", localExpr, "$temp_invoke_var2,$temp_invoke_var3,...)")
std::vector<expr_t> concat_args;
- concat_args.push_back(new const_expr(theRootSctx, loc, "\""));
+ concat_args.push_back(theExprManager->create_const_expr(theRootSctx, loc, "\""));
concat_args.push_back(namespaceExpr);
- concat_args.push_back(new const_expr(theRootSctx, loc, "\":"));
+ concat_args.push_back(theExprManager->create_const_expr(theRootSctx, loc, "\":"));
concat_args.push_back(localExpr);
- concat_args.push_back(new const_expr(theRootSctx, loc, query_params));
+ concat_args.push_back(theExprManager->create_const_expr(theRootSctx, loc, query_params));
- qnameExpr = new fo_expr(theRootSctx,
+ qnameExpr = theExprManager->create_fo_expr(theRootSctx,
loc,
GET_BUILTIN_FUNCTION(FN_CONCAT_N),
concat_args);
+<<<<<<< TREE
rchandle<eval_expr> evalExpr = new eval_expr(theCCB,
theRootSctx,
+=======
+ rchandle<eval_expr> evalExpr = theExprManager->create_eval_expr(theRootSctx,
+>>>>>>> MERGE-SOURCE
loc,
qnameExpr,
scriptingKind,
@@ -10620,6 +10694,7 @@
}
// Get the function item expr
+<<<<<<< TREE
expr_t sourceExpr = pop_nodestack();
ZORBA_ASSERT(sourceExpr != 0);
@@ -10678,6 +10753,12 @@
}
expr_t dynFuncInvocation = new dynamic_function_invocation_expr(
+=======
+ expr_t lItem = pop_nodestack();
+ ZORBA_ASSERT(lItem != 0);
+
+ expr_t lDynFuncInvocation = theExprManager->create_dynamic_function_invocation_expr(
+>>>>>>> MERGE-SOURCE
theRootSctx,
loc,
sourceExpr,
@@ -10753,7 +10834,7 @@
foArgs[i] = argVar.getp();
}
- expr_t body = new fo_expr(theRootSctx, loc, fn, foArgs);
+ expr_t body = theExprManager->create_fo_expr(theRootSctx, loc, fn, foArgs);
udf->setArgVars(udfArgs);
udf->setBody(body);
@@ -10761,7 +10842,7 @@
fn = udf;
}
- expr_t fiExpr = new function_item_expr(theRootSctx, loc, fn->getName(), fn, arity);
+ expr_t fiExpr = theExprManager->create_function_item_expr(theRootSctx, loc, fn->getName(), fn, arity);
push_nodestack(fiExpr.getp());
}
@@ -10791,7 +10872,7 @@
push_scope();
- function_item_expr* fiExpr = new function_item_expr(theRootSctx, loc);
+ function_item_expr* fiExpr = theExprManager->create_function_item_expr(theRootSctx, loc);
push_nodestack(fiExpr);
@@ -10814,7 +10895,7 @@
}
else
{
- flwor = new flwor_expr(theRootSctx, loc, false);
+ flwor = theExprManager->create_flwor_expr(theRootSctx, loc, false);
}
// Handle inscope variables. For each inscope var, a let binding is added to
@@ -11182,7 +11263,11 @@
expr_t contentExpr = pop_nodestack();
+<<<<<<< TREE
fo_expr* foExpr = wrap_in_enclosed_expr(contentExpr, loc);
+=======
+ fo_expr* foExpr = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, lContent);
+>>>>>>> MERGE-SOURCE
push_nodestack(foExpr);
}
@@ -11229,12 +11314,12 @@
store::Item_t qnameItem;
expand_elem_qname(qnameItem, v.get_elem_name(), loc);
- nameExpr = new const_expr(theRootSctx, loc, qnameItem);
+ nameExpr = theExprManager->create_const_expr(theRootSctx, loc, qnameItem);
bool copyNodes = (theCCB->theConfig.opt_level < CompilerCB::config::O1 ||
!Properties::instance()->noCopyOptim());
- push_nodestack(new elem_expr(theRootSctx,
+ push_nodestack(theExprManager->create_elem_expr(theRootSctx,
loc,
nameExpr,
attrExpr,
@@ -11305,7 +11390,14 @@
args.push_back((*it).getp());
}
+<<<<<<< TREE
fo_expr* expr_list = new fo_expr(theRootSctx, loc, op_concatenate, args);
+=======
+ fo_expr* expr_list = theExprManager->create_fo_expr(theRootSctx,
+ loc,
+ op_concatenate,
+ args);
+>>>>>>> MERGE-SOURCE
normalize_fo(expr_list);
@@ -11446,7 +11538,7 @@
store::Item_t qnameItem;
expand_no_default_qname(qnameItem, qname, qname->get_location());
- expr_t nameExpr = new const_expr(theRootSctx, loc, qnameItem);
+ expr_t nameExpr = theExprManager->create_const_expr(theRootSctx, loc, qnameItem);
fo_expr* foExpr;
if ((foExpr = dynamic_cast<fo_expr*>(valueExpr.getp())) != NULL &&
@@ -11459,7 +11551,7 @@
valueExpr = wrap_in_atomization(valueExpr);
}
- expr_t attrExpr = new attr_expr(theRootSctx, loc, nameExpr, valueExpr);
+ expr_t attrExpr = theExprManager->create_attr_expr(theRootSctx, loc, nameExpr, valueExpr);
push_nodestack(attrExpr);
}
@@ -11497,7 +11589,7 @@
}
else
{
- fo_expr_t expr_list = new fo_expr(theRootSctx,
+ fo_expr_t expr_list = theExprManager->create_fo_expr(theRootSctx,
loc,
op_concatenate,
args);
@@ -11534,9 +11626,9 @@
{
if (!v.isStripped())
{
- expr_t content = new const_expr(theRootSctx, loc, v.get_elem_content().str());
+ expr_t content = theExprManager->create_const_expr(theRootSctx, loc, v.get_elem_content().str());
- push_nodestack(new text_expr(theRootSctx, loc,
+ push_nodestack(theExprManager->create_text_expr(theRootSctx, loc,
text_expr::text_constructor,
content));
}
@@ -11640,8 +11732,8 @@
// Skip empty CDATA sections
if(!lCDATA_content.empty())
{
- expr_t content = new const_expr(theRootSctx, loc, lCDATA_content);
- push_nodestack(new text_expr(theRootSctx, loc, text_expr::text_constructor, content));
+ expr_t content = theExprManager->create_const_expr(theRootSctx, loc, lCDATA_content);
+ push_nodestack(theExprManager->create_text_expr(theRootSctx, loc, text_expr::text_constructor, content));
}
}
@@ -11676,7 +11768,7 @@
}
else if (args.size() > 1)
{
- fo_expr_t expr_list = new fo_expr(theRootSctx,
+ fo_expr_t expr_list = theExprManager->create_fo_expr(theRootSctx,
loc,
op_concatenate,
args);
@@ -11721,7 +11813,7 @@
{
if (cc == NULL)
{
- push_nodestack(new const_expr (theRootSctx, loc, content));
+ push_nodestack(theExprManager->create_const_expr (theRootSctx, loc, content));
}
else
{
@@ -11800,7 +11892,7 @@
curRef++;
}
- expr_t lConstExpr = new const_expr(theRootSctx, loc, content);
+ expr_t lConstExpr = theExprManager->create_const_expr(theRootSctx, loc, content);
push_nodestack(lConstExpr);
break;
}
@@ -11809,7 +11901,7 @@
// we always create a text node here because if we are in an attribute, we atomice
// the text node into its string value
zstring content("{");
- expr_t lConstExpr = new const_expr(theRootSctx, loc, content);
+ expr_t lConstExpr = theExprManager->create_const_expr(theRootSctx, loc, content);
push_nodestack ( lConstExpr );
break;
}
@@ -11818,7 +11910,7 @@
// we always create a text node here because if we are in an attribute, we atomice
// the text node into its string value
zstring content("}");
- expr_t lConstExpr = new const_expr(theRootSctx, loc, content);
+ expr_t lConstExpr = theExprManager->create_const_expr(theRootSctx, loc, content);
push_nodestack ( lConstExpr );
break;
}
@@ -11841,8 +11933,8 @@
TRACE_VISIT_OUT();
zstring str = v.get_comment().str();
- expr_t content = new const_expr (theRootSctx, loc, str);
- push_nodestack (new text_expr(theRootSctx, loc,
+ expr_t content = theExprManager->create_const_expr (theRootSctx, loc, str);
+ push_nodestack (theExprManager->create_text_expr(theRootSctx, loc,
text_expr::comment_constructor,
content));
}
@@ -11865,10 +11957,10 @@
if (target_upper == "XML")
RAISE_ERROR(err::XPST0003, loc, ERROR_PARAMS(ZED(XPST0003_PiTarget)));
- expr_t target = new const_expr(theRootSctx, loc, target_str);
- expr_t content = new const_expr(theRootSctx, loc, v.get_pi_content().str());
+ expr_t target = theExprManager->create_const_expr(theRootSctx, loc, target_str);
+ expr_t content = theExprManager->create_const_expr(theRootSctx, loc, v.get_pi_content().str());
- push_nodestack(new pi_expr(theRootSctx, loc, target, content));
+ push_nodestack(theExprManager->create_pi_expr(theRootSctx, loc, target, content));
}
@@ -11884,12 +11976,16 @@
expr_t lContent = pop_nodestack();
+<<<<<<< TREE
fo_expr* lEnclosed = wrap_in_enclosed_expr(lContent, loc);
+=======
+ fo_expr* lEnclosed = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, lContent);
+>>>>>>> MERGE-SOURCE
bool copyNodes = (theCCB->theConfig.opt_level < CompilerCB::config::O1 ||
!Properties::instance()->noCopyOptim());
- push_nodestack(new doc_expr(theRootSctx, loc, lEnclosed, copyNodes));
+ push_nodestack(theExprManager->create_doc_expr(theRootSctx, loc, lEnclosed, copyNodes));
}
@@ -11910,7 +12006,11 @@
{
contentExpr = pop_nodestack();
+<<<<<<< TREE
fo_expr* lEnclosed = wrap_in_enclosed_expr(contentExpr, loc);
+=======
+ fo_expr* lEnclosed = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, contentExpr);
+>>>>>>> MERGE-SOURCE
contentExpr = lEnclosed;
}
@@ -11921,20 +12021,20 @@
store::Item_t qnameItem;
expand_elem_qname(qnameItem, constQName, loc);
- nameExpr = new const_expr(theRootSctx, loc, qnameItem);
+ nameExpr = theExprManager->create_const_expr(theRootSctx, loc, qnameItem);
}
else
{
nameExpr = pop_nodestack();
expr_t atomExpr = wrap_in_atomization(nameExpr);
- nameExpr = new name_cast_expr(theRootSctx, loc, atomExpr.getp(), theNSCtx, false);
+ nameExpr = theExprManager->create_name_cast_expr(theRootSctx, loc, atomExpr.getp(), theNSCtx, false);
}
bool copyNodes = (theCCB->theConfig.opt_level < CompilerCB::config::O1 ||
!Properties::instance()->noCopyOptim());
- push_nodestack(new elem_expr(theRootSctx,
+ push_nodestack(theExprManager->create_elem_expr(theRootSctx,
loc,
nameExpr,
contentExpr,
@@ -11961,7 +12061,12 @@
{
valueExpr = pop_nodestack();
+<<<<<<< TREE
valueExpr = wrap_in_enclosed_expr(valueExpr, loc);
+=======
+ fo_expr* enclosedExpr = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, valueExpr);
+ valueExpr = enclosedExpr;
+>>>>>>> MERGE-SOURCE
}
QName* constQName = v.get_qname_expr().dyn_cast<QName>().getp();
@@ -11971,16 +12076,16 @@
store::Item_t qnameItem;
expand_no_default_qname(qnameItem, constQName, constQName->get_location());
- nameExpr = new const_expr(theRootSctx, loc, qnameItem);
+ nameExpr = theExprManager->create_const_expr(theRootSctx, loc, qnameItem);
}
else
{
nameExpr = pop_nodestack();
expr_t atomExpr = wrap_in_atomization(nameExpr);
- nameExpr = new name_cast_expr(theRootSctx, loc, atomExpr.getp(), theNSCtx, true);
+ nameExpr = theExprManager->create_name_cast_expr(theRootSctx, loc, atomExpr.getp(), theNSCtx, true);
}
- attrExpr = new attr_expr(theRootSctx, loc, nameExpr, valueExpr);
+ attrExpr = theExprManager->create_attr_expr(theRootSctx, loc, nameExpr, valueExpr);
push_nodestack(attrExpr);
}
@@ -11998,9 +12103,13 @@
expr_t inputExpr = pop_nodestack();
+<<<<<<< TREE
fo_expr_t enclosedExpr = wrap_in_enclosed_expr(inputExpr, loc);
+=======
+ fo_expr_t enclosedExpr = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, inputExpr);
+>>>>>>> MERGE-SOURCE
- expr_t textExpr = new text_expr(theRootSctx, loc,
+ expr_t textExpr = theExprManager->create_text_expr(theRootSctx, loc,
text_expr::comment_constructor,
enclosedExpr.getp());
@@ -12029,7 +12138,12 @@
{
content = pop_nodestack();
+<<<<<<< TREE
content = wrap_in_enclosed_expr(content, loc);
+=======
+ fo_expr_t enclosedExpr = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, content);
+ content = enclosedExpr;
+>>>>>>> MERGE-SOURCE
}
if (v.get_target_expr() != NULL)
@@ -12038,12 +12152,17 @@
expr_t castExpr = create_cast_expr(loc, target.getp(), theRTM.NCNAME_TYPE_ONE, true);
+<<<<<<< TREE
target = wrap_in_enclosed_expr(castExpr.getp(), loc);
+=======
+ fo_expr_t enclosedExpr = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, castExpr.getp());
+ target = enclosedExpr;
+>>>>>>> MERGE-SOURCE
}
expr_t e = (v.get_target_expr () != NULL ?
- new pi_expr(theRootSctx, loc, target, content) :
- new pi_expr(theRootSctx, loc, new const_expr(theRootSctx, loc, v.get_target().str()), content));
+ theExprManager->create_pi_expr(theRootSctx, loc, target, content) :
+ theExprManager->create_pi_expr(theRootSctx, loc, theExprManager->create_const_expr(theRootSctx, loc, v.get_target().str()), content));
push_nodestack (e);
}
@@ -12061,9 +12180,13 @@
expr_t inputExpr = pop_nodestack();
+<<<<<<< TREE
fo_expr_t enclosedExpr = wrap_in_enclosed_expr(inputExpr, loc);
+=======
+ fo_expr_t enclosedExpr = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, inputExpr);
+>>>>>>> MERGE-SOURCE
- expr_t textExpr = new text_expr(theRootSctx, loc,
+ expr_t textExpr = theExprManager->create_text_expr(theRootSctx, loc,
text_expr::text_constructor,
enclosedExpr.getp());
@@ -12318,7 +12441,7 @@
axis_step_expr* axisExpr = peek_nodestk_or_null().dyn_cast<axis_step_expr>();
if (axisExpr != NULL)
{
- rchandle<match_expr> me = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> me = theExprManager->create_match_expr(theRootSctx, loc);
me->setTestKind(match_anykind_test);
axisExpr->setTest(me);
}
@@ -12354,7 +12477,7 @@
{
if (axisExpr != NULL)
{
- match = new match_expr(theRootSctx, loc);
+ match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_doc_test);
axisExpr->setTest(match);
@@ -12437,7 +12560,7 @@
if (axisExpr != NULL)
{
- rchandle<match_expr> me = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> me = theExprManager->create_match_expr(theRootSctx, loc);
me->setTestKind(match_elem_test);
me->setQName(elemNameItem);
me->setTypeName(typeNameItem);
@@ -12484,7 +12607,7 @@
store::Item_t typeQNameItem;
CTX_TM->get_schema_element_typename(elemQNameItem, typeQNameItem, loc);
- rchandle<match_expr> match = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_xs_elem_test);
match->setQName(elemQNameItem);
match->setTypeName(typeQNameItem);
@@ -12557,7 +12680,7 @@
axis_step_expr* axisExpr = peek_nodestk_or_null().dyn_cast<axis_step_expr> ();
if (axisExpr != NULL)
{
- rchandle<match_expr> match = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_attr_test);
if (attrName != NULL)
@@ -12599,7 +12722,7 @@
store::Item_t typeQNameItem;
CTX_TM->get_schema_attribute_typename(attrQNameItem, typeQNameItem, loc);
- rchandle<match_expr> match = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_xs_attr_test);
match->setQName(attrQNameItem);
match->setTypeName(typeQNameItem);
@@ -12647,7 +12770,7 @@
axis_step_expr* axisExpr = peek_nodestk_or_null ().dyn_cast<axis_step_expr> ();
if (axisExpr != NULL)
{
- rchandle<match_expr> match = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_text_test);
axisExpr->setTest(match);
}
@@ -12673,7 +12796,7 @@
axis_step_expr* axisExpr = peek_nodestk_or_null ().dyn_cast<axis_step_expr> ();
if (axisExpr != NULL)
{
- rchandle<match_expr> match = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_comment_test);
axisExpr->setTest(match);
}
@@ -12726,7 +12849,7 @@
if (axisExpr != NULL)
{
- rchandle<match_expr> match = new match_expr(theRootSctx, loc);
+ rchandle<match_expr> match = theExprManager->create_match_expr(theRootSctx, loc);
match->setTestKind(match_pi_test);
if (target != "")
match->setQName(qname);
@@ -13068,7 +13191,7 @@
expr_t lTarget = pop_nodestack();
- expr_t aDelete = new delete_expr(theRootSctx, loc, lTarget);
+ expr_t aDelete = theExprManager->create_delete_expr(theRootSctx, loc, lTarget);
push_nodestack(aDelete);
}
@@ -13085,9 +13208,14 @@
expr_t lTarget = pop_nodestack();
expr_t lSource = pop_nodestack();
+<<<<<<< TREE
lSource = wrap_in_enclosed_expr(lSource, loc);
+=======
+ fo_expr_t lEnclosed = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, lSource);
+ lSource = lEnclosed;
+>>>>>>> MERGE-SOURCE
- expr_t lInsert = new insert_expr(theRootSctx, loc, v.getType(), lSource, lTarget);
+ expr_t lInsert = theExprManager->create_insert_expr(theRootSctx, loc, v.getType(), lSource, lTarget);
push_nodestack(lInsert);
}
@@ -13110,9 +13238,9 @@
// We use a name_cast_expr here for static typing reasons. However, during codegen,
// we are not going to generate a NameCastIterator, because we don't always know at
// compile time whether the target will an element or an attribute node.
- nameExpr = new name_cast_expr(theRootSctx, loc, nameExpr.getp(), theNSCtx, false);
+ nameExpr = theExprManager->create_name_cast_expr(theRootSctx, loc, nameExpr.getp(), theNSCtx, false);
- expr_t renameExpr = new rename_expr(theRootSctx, loc, targetExpr, nameExpr);
+ expr_t renameExpr = theExprManager->create_rename_expr(theRootSctx, loc, targetExpr, nameExpr);
push_nodestack(renameExpr);
}
@@ -13133,10 +13261,15 @@
if (v.getType() == store::UpdateConsts::NODE)
{
+<<<<<<< TREE
lReplacement = wrap_in_enclosed_expr(lReplacement, loc);
+=======
+ fo_expr_t lEnclosed = theExprManager->create_fo_expr(theRootSctx, loc, op_enclosed, lReplacement);
+ lReplacement = lEnclosed;
+>>>>>>> MERGE-SOURCE
}
- expr_t lReplace = new replace_expr(theRootSctx, loc,
+ expr_t lReplace = theExprManager->create_replace_expr(theRootSctx, loc,
v.getType(),
lTarget,
lReplacement);
@@ -13148,7 +13281,7 @@
{
TRACE_VISIT();
- transform_expr* transformExpr = new transform_expr(theRootSctx, loc);
+ transform_expr* transformExpr = theExprManager->create_transform_expr(theRootSctx, loc);
push_nodestack(transformExpr);
@@ -13354,7 +13487,7 @@
ZORBA_ASSERT( range );
ftcontains_expr *const e =
- new ftcontains_expr( theRootSctx, loc, range, selection, ftignore );
+ theExprManager->create_ftcontains_expr( theRootSctx, loc, range, selection, ftignore );
push_nodestack( e );
#endif /* ZORBA_NO_FULL_TEXT */
}
=== modified file 'src/unit_tests/CMakeLists.txt'
--- src/unit_tests/CMakeLists.txt 2012-06-18 10:06:47 +0000
+++ src/unit_tests/CMakeLists.txt 2012-06-26 18:33:24 +0000
@@ -21,6 +21,7 @@
test_uri.cpp
json_parser.cpp
test_fs_iterator.cpp
+ memory_manager.cpp
)
IF (NOT ZORBA_NO_FULL_TEXT)
=== added file 'src/unit_tests/memory_manager.cpp'
--- src/unit_tests/memory_manager.cpp 1970-01-01 00:00:00 +0000
+++ src/unit_tests/memory_manager.cpp 2012-06-26 18:33:24 +0000
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "compiler/expression/mem_manager.h"
+#include <iostream>
+
+// Assertion and Testing macros and functions
+
+static int failures;
+
+static bool assert_true(char const *expr, char const *testName, bool result) {
+ if ( !result ) {
+ std::cout << "FAILED " << testName << ": " << expr << std::endl;
+ ++failures;
+ }
+ return result;
+}
+
+static void print_exception( char const *expr, char const *testName,
+ std::exception const &e ) {
+ std::cout << "FAILED " << testName << ": exception: " << e.what() <<
+ std::endl;
+ ++failures;
+}
+
+#define ASSERT_TRUE( EXPR ) assert_true( #EXPR, testName, !!(EXPR) )
+
+#define ASSERT_EXCEPTION( EXPR, EXCEPTION ) \
+ try { EXPR; assert_true( #EXPR, testName, false); } \
+ catch (EXCEPTION const& ) { } \
+ catch ( std::exception const &e ){ print_exception( #EXPR, testName, e ); } \
+ catch ( ... ) { assert_true ( #EXPR, testName, false ); }
+
+#define ASSERT_NO_EXCEPTION( EXPR ) \
+ try {EXPR; } \
+ catch ( std::exception const &e ){ print_exception( #EXPR, testName, e ); } \
+ catch ( ... ) { assert_true (#EXPR, testName, false ); }
+
+#define ASSERT_TRUE_AND_NO_EXCEPTION( EXPR ) \
+ try { ASSERT_TRUE ( EXPR ); } \
+ catch ( std::exception const &e ) { print_exception( #EXPR, testName, e ); } \
+ catch ( ... ) {assert_true( #EXPR, testName, false ); }
+
+#define TEST( TESTNAME ) \
+static void TESTNAME () { \
+ const char *testName = #TESTNAME ; \
+ int prev_failures = failures ;
+
+#define END_TEST \
+ if ( prev_failures == failures ) \
+ std::cout << "PASSED " << testName << std::endl ; \
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+using namespace zorba;
+
+/*
+ * Memory Page tests
+ */
+
+//Impostors for malloc and free
+static const size_t DEFSIZE = MemPage::DEFAULT_PAGE_SIZE;
+static const size_t HUGESIZE = DEFSIZE + 2;
+static char defaultPage[DEFSIZE], hugePage[HUGESIZE];
+static int defPageAlloc, hugePageAlloc;
+
+void* malloc_impostor(size_t size)
+{
+ if(size > DEFSIZE)
+ {
+ ++hugePageAlloc;
+ return (void*) hugePage;
+ }
+ ++defPageAlloc;
+ return (void*) defaultPage;
+}
+
+void free_impostor(void* ptr)
+{
+ if(ptr = (void*)defaultPage)
+ --defPageAlloc;
+ if(ptr = (void*)hugePage)
+ --hugePageAlloc;
+}
+
+void* malloc_fail_alloc(size_t size)
+{
+ return NULL;
+}
+
+TEST(PageCreationAllocatesMemoryDeletionFreesIt)
+ //block to force deletion of testPage
+ {
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ ASSERT_TRUE(defPageAlloc == 1);
+ }
+ ASSERT_TRUE(defPageAlloc == 0);
+END_TEST
+
+TEST(FailedPageCreationThrowsBadAlloc)
+ ASSERT_EXCEPTION(MemPage(DEFSIZE, &malloc_fail_alloc, &free_impostor),
+ std::bad_alloc);
+END_TEST
+
+TEST(NewPageHasFullSpace)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ ASSERT_TRUE(testPage.space() == DEFSIZE);
+END_TEST
+
+TEST(PageGivesValidAllocationAndLoosesSpace)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ char* mem = (char*)testPage.allocate(sizeof(char) * 2);
+ ASSERT_TRUE(defaultPage <= mem && defaultPage + DEFSIZE > mem);
+ ASSERT_TRUE(DEFSIZE - 2 == testPage.space());
+END_TEST
+
+TEST(AllocationSizeZeroReturnsNull)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ char* mem = (char*)testPage.allocate(0);
+ ASSERT_TRUE(NULL == mem);
+END_TEST
+
+TEST(PageGivesSeparateAllocations)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ char* mem1 = (char*)testPage.allocate(sizeof(char) * 2);
+ char* mem2 = (char*)testPage.allocate(sizeof(char) * 3);
+ ASSERT_TRUE(mem1 >= (mem2 + 3) || (mem1 + 2) <= mem2);
+ ASSERT_TRUE(NULL != mem1 && NULL != mem2);
+ ASSERT_TRUE(testPage.space() == DEFSIZE - 5);
+END_TEST
+
+TEST(PageWillNotAllocateSpaceBiggerThanSize)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ char* mem = (char*)testPage.allocate(HUGESIZE);
+ ASSERT_TRUE(NULL == mem);
+END_TEST
+
+TEST(PageWillNotAllocateSpaceBiggerThanSpaceAvailable)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ char* mem1 = (char*)testPage.allocate(sizeof(char) * 10);
+ char* mem2 = (char*)testPage.allocate(testPage.space()+2);
+ ASSERT_TRUE(mem1 != NULL);
+ ASSERT_TRUE(mem2 == NULL);
+END_TEST
+
+TEST(FailedAllocationHasNoEffectOnPage)
+ MemPage testPage(DEFSIZE, &malloc_impostor, &free_impostor);
+ char* mem1 = (char*)testPage.allocate(sizeof(char) * 5);
+ size_t orig_space = testPage.space();
+ char* mem2 = (char*)testPage.allocate(testPage.space()+2);
+ ASSERT_TRUE(testPage.space() == orig_space);
+ char* mem3 = (char*)testPage.allocate(sizeof(char) * 5);
+ ASSERT_TRUE(defaultPage <= mem3 && defaultPage + DEFSIZE >= mem3 + 5);
+ ASSERT_TRUE(testPage.space() == DEFSIZE - 10);
+END_TEST
+
+TEST(BiggerPagesAllowForBiggerSpaceAndAllocation)
+ MemPage testPage(HUGESIZE, &malloc_impostor, &free_impostor);
+ ASSERT_TRUE(testPage.space() == HUGESIZE);
+ char* mem = (char*)testPage.allocate(HUGESIZE);
+ ASSERT_TRUE(NULL != mem);
+ //this would be the only valid allocation
+ ASSERT_TRUE(hugePage == mem);
+END_TEST
+
+namespace zorba { namespace UnitTests{
+
+///////////////////////////////////////////////////////////////////////////////
+int test_mem_manager( int, char*[] )
+{
+ PageCreationAllocatesMemoryDeletionFreesIt();
+ FailedPageCreationThrowsBadAlloc();
+ NewPageHasFullSpace();
+ PageGivesValidAllocationAndLoosesSpace();
+ AllocationSizeZeroReturnsNull();
+ PageGivesSeparateAllocations();
+ PageWillNotAllocateSpaceBiggerThanSize();
+ PageWillNotAllocateSpaceBiggerThanSpaceAvailable();
+ FailedAllocationHasNoEffectOnPage();
+ BiggerPagesAllowForBiggerSpaceAndAllocation();
+
+ if(failures > 0)
+ std::cout << failures << " Memory Manager test(s) failed.\n";
+ else
+ std::cout << "All Memory Manager tests passed.\n";
+
+ return failures ? 1 : 0;
+}
+
+}} //namespace zorba::UnitTests
=== modified file 'src/unit_tests/unit_test_list.h'
--- src/unit_tests/unit_test_list.h 2012-06-18 10:06:47 +0000
+++ src/unit_tests/unit_test_list.h 2012-06-26 18:33:24 +0000
@@ -24,6 +24,7 @@
namespace zorba
{
+<<<<<<< TREE
namespace UnitTests
{
int runUriTest(int argc, char* argv[]);
@@ -31,6 +32,15 @@
int test_string( int, char*[] );
int test_unique_ptr( int, char*[] );
int test_fs_iterator( int, char*[] );
+=======
+ namespace UnitTests {
+ int runUriTest(int argc, char* argv[]);
+ int runDebuggerProtocolTest(int argc, char* argv[]);
+ int test_string( int, char*[] );
+ int test_unique_ptr( int, char*[] );
+ int test_fs_iterator( int, char*[] );
+ int test_mem_manager( int, char*[] );
+>>>>>>> MERGE-SOURCE
#ifndef ZORBA_NO_FULL_TEXT
int test_stemmer( int, char*[] );
int test_thesaurus( int, char*[] );
@@ -42,12 +52,21 @@
#ifndef ZORBA_NO_ICU
int test_icu_streambuf( int, char*[] );
#endif /* ZORBA_NO_ICU */
+<<<<<<< TREE
int json_parser( int, char*[] );
void initializeTestList();
};
+=======
+ int json_parser( int, char*[] );
+
+ void initializeTestList();
+ };
+
+
+>>>>>>> MERGE-SOURCE
} /* namespace zorba */
#endif /* ZORBA_UNIT_TEST_LIST_H */
=== modified file 'src/unit_tests/unit_tests.cpp'
--- src/unit_tests/unit_tests.cpp 2012-06-18 10:06:47 +0000
+++ src/unit_tests/unit_tests.cpp 2012-06-26 18:33:24 +0000
@@ -29,6 +29,7 @@
namespace zorba {
+<<<<<<< TREE
namespace UnitTests
{
@@ -42,6 +43,20 @@
libunittests["string"] = test_string;
libunittests["uri"] = runUriTest;
libunittests["fs_iterator"] = test_fs_iterator;
+=======
+ namespace UnitTests {
+
+ map<string,libunittestfunc> libunittests;
+
+ /**
+ * ADD NEW UNIT TESTS HERE
+ */
+ void initializeTestList() {
+ libunittests["string"] = test_string;
+ libunittests["uri"] = runUriTest;
+ libunittests["fs_iterator"] = test_fs_iterator;
+ libunittests["memory_manager"] = test_mem_manager;
+>>>>>>> MERGE-SOURCE
#ifndef ZORBA_NO_ICU
libunittests["icu_streambuf"] = test_icu_streambuf;
#endif /* ZORBA_NO_ICU */
=== modified file 'test/unit/CMakeLists.txt'
--- test/unit/CMakeLists.txt 2012-06-18 10:06:47 +0000
+++ test/unit/CMakeLists.txt 2012-06-26 18:33:24 +0000
@@ -145,6 +145,7 @@
EXPECTED_FAILURE(test/libunit/uri 3118348)
ZORBA_ADD_TEST("test/libunit/json_parser" LibUnitTest json_parser)
ZORBA_ADD_TEST("test/libunit/unique_ptr" LibUnitTest unique_ptr)
+ZORBA_ADD_TEST("test/libunit/memory_manager" LibUnitTest memory_manager)
IF (NOT ZORBA_NO_FULL_TEXT)
ZORBA_ADD_TEST("test/libunit/stemmer" LibUnitTest stemmer)
ZORBA_ADD_TEST("test/libunit/thesaurus" LibUnitTest thesaurus)
Follow ups