XQuilla/include/xqilla/ast/StaticAnalysis.hpp

154 lines
4.6 KiB
C++
Raw Permalink Normal View History

2020-02-17 21:05:20 +00:00
/*
2020-02-17 21:22:42 +00:00
* Copyright (c) 2001, 2008,
2020-02-17 21:05:20 +00:00
* DecisionSoft Limited. All rights reserved.
2020-02-17 21:24:47 +00:00
* Copyright (c) 2004, 2018 Oracle and/or its affiliates. All rights reserved.
2020-02-17 21:23:16 +00:00
*
2020-02-17 21:05:20 +00:00
*
2020-02-17 21:12:51 +00:00
* 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
2020-02-17 21:05:20 +00:00
*
2020-02-17 21:12:51 +00:00
* 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.
2020-02-17 21:05:20 +00:00
*/
2020-02-17 21:11:31 +00:00
#ifndef _STATICANALYSIS_HPP
#define _STATICANALYSIS_HPP
2020-02-17 21:05:20 +00:00
#include <string>
#include <xqilla/framework/XQillaExport.hpp>
#include <xqilla/ast/StaticType.hpp>
#include <vector>
class XPath2MemoryManager;
/**
* Records access to various parts of the context during static resolution.
*/
2020-02-17 21:11:31 +00:00
class XQILLA_API StaticAnalysis
2020-02-17 21:05:20 +00:00
{
public:
2020-02-17 21:22:42 +00:00
static const int HASH_SIZE = 13;
2020-02-17 21:17:06 +00:00
class XQILLA_API VarEntry
{
public:
2020-02-17 21:22:42 +00:00
VarEntry() : uri(0), name(0), hash(0), prev(0) {}
void set(const XMLCh *u, const XMLCh *n);
void set(const XMLCh *u, const XMLCh *n, size_t h);
2020-02-17 21:17:06 +00:00
const XMLCh *uri, *name;
2020-02-17 21:22:42 +00:00
size_t hash;
2020-02-17 21:17:06 +00:00
VarEntry *prev;
};
2020-02-17 21:11:31 +00:00
StaticAnalysis(XPath2MemoryManager* memMgr);
StaticAnalysis(const StaticAnalysis &o, XPath2MemoryManager* memMgr);
2020-02-17 21:05:20 +00:00
2020-02-17 21:11:31 +00:00
void copy(const StaticAnalysis &o);
2020-02-17 21:22:42 +00:00
void release();
2020-02-17 21:05:20 +00:00
2020-02-17 21:11:31 +00:00
/// Clears all the information in this StaticAnalysis
2020-02-17 21:05:20 +00:00
void clear();
2020-02-17 21:22:42 +00:00
void clearExceptType();
2020-02-17 21:05:20 +00:00
/** Overrides all the other flags, and never allows this sub-expression
to be constant folded. */
void forceNoFolding(bool value);
bool isNoFoldingForced() const;
void contextItemUsed(bool value);
void contextPositionUsed(bool value);
void contextSizeUsed(bool value);
bool isContextItemUsed() const;
bool isContextPositionUsed() const;
bool isContextSizeUsed() const;
/** Returns true if any of the context item flags have been used */
bool areContextFlagsUsed() const;
void currentTimeUsed(bool value);
void implicitTimezoneUsed(bool value);
2020-02-17 21:11:31 +00:00
2020-02-17 21:05:20 +00:00
void availableDocumentsUsed(bool value);
void availableCollectionsUsed(bool value);
bool areDocsOrCollectionsUsed() const;
void variableUsed(const XMLCh *namespaceURI, const XMLCh *name);
bool removeVariable(const XMLCh *namespaceURI, const XMLCh *name);
bool isVariableUsed(const XMLCh *namespaceURI, const XMLCh *name) const;
2020-02-17 21:22:42 +00:00
bool isVariableUsed() const;
VarEntry **variablesUsed() const;
2020-02-17 21:05:20 +00:00
2020-02-17 21:11:31 +00:00
/** Sets the members of this StaticAnalysis from the given StaticAnalysis */
void add(const StaticAnalysis &o);
void addExceptContextFlags(const StaticAnalysis &o);
2020-02-17 21:17:06 +00:00
void addExceptVariable(const XMLCh *namespaceURI, const XMLCh *name, const StaticAnalysis &o);
2020-02-17 21:05:20 +00:00
/** Returns true if flags are set, or variables have been used */
bool isUsed() const;
bool isUsedExceptContextFlags() const;
void creative(bool value);
bool isCreative() const;
2020-02-17 21:11:31 +00:00
void updating(bool value);
bool isUpdating() const;
void possiblyUpdating(bool value);
bool isPossiblyUpdating() const;
2020-02-17 21:05:20 +00:00
/**
* Properties that allow optimisation regarding sorting or not.
* The values are OR'd as flags, so they must be distinct bits
*/
enum Properties {
DOCORDER = 0x001, ///< Results are returned in document order
PEER = 0x002, ///< Results do not appear in the descendants of other results
SUBTREE = 0x004, ///< Results are members of the set of descendants of the context node
GROUPED = 0x008, ///< Results are grouped by the document they come from
SAMEDOC = 0x010, ///< Results are from the same document as the context node
ONENODE = 0x020, ///< Only ever returns one node
SELF = 0x040, ///< Only ever returns the context node
2020-02-17 21:22:42 +00:00
UNDEFINEDVAR = 0x080 ///< This is a variable that has been undefined
2020-02-17 21:05:20 +00:00
};
unsigned int getProperties() const;
void setProperties(unsigned int props);
const StaticType &getStaticType() const;
StaticType &getStaticType();
std::string toString() const;
private:
2020-02-17 21:11:31 +00:00
StaticAnalysis(const StaticAnalysis &o);
StaticAnalysis &operator=(const StaticAnalysis &o);
2020-02-17 21:05:20 +00:00
bool _contextItem;
bool _contextPosition;
bool _contextSize;
bool _currentTime;
bool _implicitTimezone;
bool _availableDocuments;
bool _availableCollections;
bool _forceNoFolding;
bool _creative;
2020-02-17 21:11:31 +00:00
bool _updating;
bool _possiblyUpdating;
2020-02-17 21:05:20 +00:00
unsigned int _properties;
StaticType _staticType;
2020-02-17 21:22:42 +00:00
VarEntry *_dynamicVariables[HASH_SIZE];
VarEntry *_recycle;
2020-02-17 21:15:56 +00:00
XPath2MemoryManager *_memMgr;
2020-02-17 21:05:20 +00:00
};
#endif