source: webkit/trunk/JavaScriptCore/kjs/identifier.h@ 9781

Last change on this file since 9781 was 9768, checked in by ggaren, 20 years ago

-rolled in patches for http://bugzilla.opendarwin.org/show_bug.cgi?id=3945
[PATCH] Safe merges of comments and other trivialities from KDE's kjs

-patch by Martijn Klingens <[email protected]>

  • kjs/array_instance.h:
  • kjs/array_object.cpp:
  • kjs/array_object.h:
  • kjs/bool_object.cpp:
  • kjs/bool_object.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/context.h:
  • kjs/date_object.cpp:
  • kjs/date_object.h:
  • kjs/debugger.cpp:
  • kjs/debugger.h:
  • kjs/dtoa.h:
  • kjs/error_object.cpp:
  • kjs/error_object.h:
  • kjs/function.cpp:
  • kjs/function.h:
  • kjs/function_object.cpp:
  • kjs/function_object.h:
  • kjs/grammar.y:
  • kjs/identifier.cpp:
  • kjs/identifier.h:
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/interpreter_map.cpp:
  • kjs/interpreter_map.h:
  • kjs/lexer.cpp:
  • kjs/lexer.h:
  • kjs/list.cpp:
  • kjs/list.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/math_object.cpp:
  • kjs/math_object.h:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/nodes2string.cpp:
  • kjs/number_object.cpp:
  • kjs/number_object.h:
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/object_object.cpp:
  • kjs/object_object.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/property_map.cpp:
  • kjs/property_map.h:
  • kjs/reference.cpp:
  • kjs/reference.h:
  • kjs/reference_list.cpp:
  • kjs/reference_list.h:
  • kjs/regexp.cpp:
  • kjs/regexp.h:
  • kjs/regexp_object.cpp:
  • kjs/regexp_object.h:
  • kjs/scope_chain.cpp:
  • kjs/scope_chain.h:
  • kjs/simple_number.h:
  • kjs/string_object.cpp:
  • kjs/string_object.h:
  • kjs/testkjs.cpp:
  • kjs/types.h:
  • kjs/ustring.cpp:
  • kjs/ustring.h:
  • kjs/value.cpp:
  • kjs/value.h:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2003 Apple Computer, Inc
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#ifndef KJS_IDENTIFIER_H
23#define KJS_IDENTIFIER_H
24
25#include "ustring.h"
26
27namespace KJS {
28
29 class Identifier {
30 friend class PropertyMap;
31 public:
32 static void init();
33
34 Identifier() { }
35 Identifier(const char *s) : _ustring(add(s)) { }
36 Identifier(const UChar *s, int length) : _ustring(add(s, length)) { }
37 explicit Identifier(const UString &s) : _ustring(add(s.rep)) { }
38
39 const UString &ustring() const { return _ustring; }
40 DOM::DOMString string() const;
41 QString qstring() const;
42
43 const UChar *data() const { return _ustring.data(); }
44 int size() const { return _ustring.size(); }
45
46 const char *ascii() const { return _ustring.ascii(); }
47
48 static Identifier from(unsigned y) { return Identifier(UString::from(y)); }
49
50 bool isNull() const { return _ustring.isNull(); }
51 bool isEmpty() const { return _ustring.isEmpty(); }
52
53 unsigned long toULong(bool *ok) const { return _ustring.toULong(ok); }
54 uint32_t toUInt32(bool *ok) const { return _ustring.toUInt32(ok); }
55 uint32_t toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); }
56 unsigned toArrayIndex(bool *ok) const { return _ustring.toArrayIndex(ok); }
57 double toDouble() const { return _ustring.toDouble(); }
58
59 static const Identifier &null();
60
61 friend bool operator==(const Identifier &, const Identifier &);
62 friend bool operator!=(const Identifier &, const Identifier &);
63
64 friend bool operator==(const Identifier &, const char *);
65
66 static void remove(UString::Rep *);
67
68 private:
69 UString _ustring;
70
71 static bool equal(UString::Rep *, const char *);
72 static bool equal(UString::Rep *, const UChar *, int length);
73 static bool equal(UString::Rep *, UString::Rep *);
74
75 static bool equal(const Identifier &a, const Identifier &b)
76 { return a._ustring.rep == b._ustring.rep; }
77 static bool equal(const Identifier &a, const char *b)
78 { return equal(a._ustring.rep, b); }
79
80 static UString::Rep *add(const char *);
81 static UString::Rep *add(const UChar *, int length);
82 static UString::Rep *add(UString::Rep *);
83
84 static void insert(UString::Rep *);
85
86 static void rehash(int newTableSize);
87 static void expand();
88 static void shrink();
89
90 static UString::Rep **_table;
91 static int _tableSize;
92 static int _tableSizeMask;
93 static int _keyCount;
94 };
95
96 inline bool operator==(const Identifier &a, const Identifier &b)
97 { return Identifier::equal(a, b); }
98
99 inline bool operator!=(const Identifier &a, const Identifier &b)
100 { return !Identifier::equal(a, b); }
101
102 inline bool operator==(const Identifier &a, const char *b)
103 { return Identifier::equal(a, b); }
104
105 // List of property names, passed to a macro so we can do set them up various
106 // ways without repeating the list.
107 #define KJS_IDENTIFIER_EACH_GLOBAL(macro) \
108 macro(arguments) \
109 macro(callee) \
110 macro(constructor) \
111 macro(length) \
112 macro(message) \
113 macro(name) \
114 macro(prototype) \
115 macro(toLocaleString) \
116 macro(toString) \
117 macro(toFixed) \
118 macro(toExponential) \
119 macro(toPrecision) \
120 macro(valueOf)
121
122 // Define external global variables for all property names above (and one more).
123#if !KJS_IDENTIFIER_HIDE_GLOBALS
124 #define KJS_IDENTIFIER_DECLARE_GLOBAL(name) extern const Identifier name ## PropertyName;
125 KJS_IDENTIFIER_EACH_GLOBAL(KJS_IDENTIFIER_DECLARE_GLOBAL)
126 KJS_IDENTIFIER_DECLARE_GLOBAL(specialPrototype)
127 #undef KJS_IDENTIFIER_DECLARE_GLOBAL
128#endif
129
130}
131
132#endif
Note: See TracBrowser for help on using the repository browser.