1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 1999-2000 Harri Porten ([email protected])
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Library General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Library General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Library General Public License
|
---|
17 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
---|
19 | * Boston, MA 02111-1307, USA.
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef _KJS_FUNCTION_H_
|
---|
24 | #define _KJS_FUNCTION_H_
|
---|
25 |
|
---|
26 | #include "internal.h"
|
---|
27 |
|
---|
28 | namespace KJS {
|
---|
29 |
|
---|
30 | class Parameter;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * @short Implementation class for internal Functions.
|
---|
34 | */
|
---|
35 | class FunctionImp : public InternalFunctionImp {
|
---|
36 | friend class Function;
|
---|
37 | friend class ActivationImp;
|
---|
38 | public:
|
---|
39 | FunctionImp(ExecState *exec, const UString &n = UString::null);
|
---|
40 | virtual ~FunctionImp();
|
---|
41 |
|
---|
42 | virtual void mark();
|
---|
43 |
|
---|
44 | virtual bool implementsCall() const;
|
---|
45 | virtual Value call(ExecState *exec, Object &thisObj, const List &args);
|
---|
46 |
|
---|
47 | void addParameter(const UString &n);
|
---|
48 | // parameters in string representation, e.g. (a, b, c)
|
---|
49 | UString parameterString() const;
|
---|
50 | virtual CodeType codeType() const = 0;
|
---|
51 |
|
---|
52 | virtual Completion execute(ExecState *exec) = 0;
|
---|
53 | UString name() const { return ident; }
|
---|
54 |
|
---|
55 | virtual const ClassInfo *classInfo() const { return &info; }
|
---|
56 | static const ClassInfo info;
|
---|
57 | protected:
|
---|
58 | Parameter *param;
|
---|
59 | UString ident;
|
---|
60 |
|
---|
61 | private:
|
---|
62 | void processParameters(ExecState *exec, const List &);
|
---|
63 | virtual void processVarDecls(ExecState *exec);
|
---|
64 | };
|
---|
65 |
|
---|
66 | class DeclaredFunctionImp : public FunctionImp {
|
---|
67 | public:
|
---|
68 | DeclaredFunctionImp(ExecState *exec, const UString &n,
|
---|
69 | FunctionBodyNode *b, const List &sc);
|
---|
70 | ~DeclaredFunctionImp();
|
---|
71 |
|
---|
72 | bool implementsConstruct() const;
|
---|
73 | Object construct(ExecState *exec, const List &args);
|
---|
74 |
|
---|
75 | virtual Completion execute(ExecState *exec);
|
---|
76 | CodeType codeType() const { return FunctionCode; }
|
---|
77 | FunctionBodyNode *body;
|
---|
78 |
|
---|
79 | virtual const ClassInfo *classInfo() const { return &info; }
|
---|
80 | static const ClassInfo info;
|
---|
81 | private:
|
---|
82 | virtual void processVarDecls(ExecState *exec);
|
---|
83 | };
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | class ArgumentsImp : public ObjectImp {
|
---|
89 | public:
|
---|
90 | ArgumentsImp(ExecState *exec, FunctionImp *func, const List &args);
|
---|
91 |
|
---|
92 | virtual const ClassInfo *classInfo() const { return &info; }
|
---|
93 | static const ClassInfo info;
|
---|
94 | };
|
---|
95 |
|
---|
96 | class ActivationImp : public ObjectImp {
|
---|
97 | public:
|
---|
98 | ActivationImp(ExecState *exec, FunctionImp *f, const List &args);
|
---|
99 | ~ActivationImp();
|
---|
100 |
|
---|
101 | Object argumentsObject() { return Object(arguments); }
|
---|
102 |
|
---|
103 | virtual const ClassInfo *classInfo() const { return &info; }
|
---|
104 | static const ClassInfo info;
|
---|
105 | private:
|
---|
106 | ObjectImp* arguments;
|
---|
107 | };
|
---|
108 |
|
---|
109 | class GlobalFuncImp : public InternalFunctionImp {
|
---|
110 | public:
|
---|
111 | GlobalFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len);
|
---|
112 | virtual bool implementsCall() const;
|
---|
113 | virtual Value call(ExecState *exec, Object &thisObj, const List &args);
|
---|
114 | virtual CodeType codeType() const;
|
---|
115 | enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, Escape, UnEscape };
|
---|
116 | private:
|
---|
117 | int id;
|
---|
118 | };
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 | }; // namespace
|
---|
123 |
|
---|
124 | #endif
|
---|