source: trunk/src/script/qscriptcontextfwd_p.h@ 82

Last change on this file since 82 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtScript module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QSCRIPTCONTEXTFWD_P_H
43#define QSCRIPTCONTEXTFWD_P_H
44
45//
46// W A R N I N G
47// -------------
48//
49// This file is not part of the Qt API. It exists purely as an
50// implementation detail. This header file may change from version to
51// version without notice, or even be removed.
52//
53// We mean it.
54//
55
56#include "qscriptvalueimplfwd_p.h"
57
58#ifndef QT_NO_SCRIPT
59
60#include "qscriptcontext.h"
61
62#include <QtCore/qobjectdefs.h>
63
64#if defined Q_CC_MSVC && !defined Q_CC_MSVC_NET
65#include <QtCore/qnumeric.h>
66#endif
67
68QT_BEGIN_NAMESPACE
69
70namespace QScript {
71 namespace AST {
72 class Node;
73 }
74class Code;
75}
76
77class QScriptInstruction;
78
79class QScriptContextPrivate
80{
81 Q_DECLARE_PUBLIC(QScriptContext)
82public:
83 inline QScriptContextPrivate();
84
85 static inline QScriptContextPrivate *get(QScriptContext *q);
86 static inline const QScriptContextPrivate *get(const QScriptContext *q);
87 static QScriptContext *get(QScriptContextPrivate *d);
88
89 static inline QScriptContext *create();
90
91 inline QScriptEnginePrivate *engine() const;
92 inline QScriptContextPrivate *parentContext() const;
93
94 inline void init(QScriptContextPrivate *parent);
95 inline QScriptValueImpl argument(int index) const;
96 inline int argumentCount() const;
97 inline QScriptValueImpl argumentsObject() const;
98
99 inline void throwException();
100 inline bool hasUncaughtException() const;
101 const QScriptInstruction *findExceptionHandler(const QScriptInstruction *ip) const;
102 const QScriptInstruction *findExceptionHandlerRecursive(
103 const QScriptInstruction *ip, QScriptContextPrivate **handlerContext) const;
104 QScriptContextPrivate *exceptionHandlerContext() const;
105 inline void recover();
106 QStringList backtrace() const;
107
108 static inline bool isNumerical(const QScriptValueImpl &v);
109
110 static inline bool eq_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs);
111
112 static bool eq_cmp_helper(QScriptValueImpl lhs, QScriptValueImpl rhs);
113
114#if defined(Q_CC_GNU) && __GNUC__ <= 3
115 static bool lt_cmp(QScriptValueImpl lhs, QScriptValueImpl rhs);
116#else
117 static bool lt_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs)
118 {
119 if (lhs.type() == rhs.type()) {
120 switch (lhs.type()) {
121 case QScript::UndefinedType:
122 case QScript::NullType:
123 return false;
124
125 case QScript::NumberType:
126#if defined Q_CC_MSVC && !defined Q_CC_MSVC_NET
127 if (qIsNaN(lhs.m_number_value) || qIsNaN(rhs.m_number_value))
128 return false;
129#endif
130 return lhs.m_number_value < rhs.m_number_value;
131
132 case QScript::IntegerType:
133 return lhs.m_int_value < rhs.m_int_value;
134
135 case QScript::BooleanType:
136 return lhs.m_bool_value < rhs.m_bool_value;
137
138 default:
139 break;
140 } // switch
141 }
142
143 return lt_cmp_helper(lhs, rhs);
144 }
145
146 static bool lt_cmp_helper(QScriptValueImpl lhs, QScriptValueImpl rhs);
147#endif
148
149 static bool le_cmp(const QScriptValueImpl &lhs, const QScriptValueImpl &rhs)
150 {
151 if (lhs.type() == rhs.type()) {
152 switch (lhs.type()) {
153 case QScript::UndefinedType:
154 case QScript::NullType:
155 return true;
156
157 case QScript::NumberType:
158 return lhs.m_number_value <= rhs.m_number_value;
159
160 case QScript::IntegerType:
161 return lhs.m_int_value <= rhs.m_int_value;
162