]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2002 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) | |
4 | * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | |
5 | * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) | |
6 | * Copyright (C) 2007 Maks Orlovich | |
7 | * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | |
8 | * | |
9 | * This library is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Library General Public | |
11 | * License as published by the Free Software Foundation; either | |
12 | * version 2 of the License, or (at your option) any later version. | |
13 | * | |
14 | * This library is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * Library General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU Library General Public License | |
20 | * along with this library; see the file COPYING.LIB. If not, write to | |
21 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 | * Boston, MA 02110-1301, USA. | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "config.h" | |
27 | #include "Nodes.h" | |
ba379fdc | 28 | #include "NodeConstructors.h" |
9dae56ea A |
29 | |
30 | #include "BytecodeGenerator.h" | |
31 | #include "CallFrame.h" | |
ba379fdc A |
32 | #include "Debugger.h" |
33 | #include "JIT.h" | |
34 | #include "JSFunction.h" | |
9dae56ea A |
35 | #include "JSGlobalObject.h" |
36 | #include "JSStaticScopeObject.h" | |
37 | #include "LabelScope.h" | |
ba379fdc A |
38 | #include "Lexer.h" |
39 | #include "Operations.h" | |
9dae56ea A |
40 | #include "Parser.h" |
41 | #include "PropertyNameArray.h" | |
42 | #include "RegExpObject.h" | |
43 | #include "SamplingTool.h" | |
9dae56ea | 44 | #include <wtf/Assertions.h> |
9dae56ea A |
45 | #include <wtf/RefCountedLeakCounter.h> |
46 | #include <wtf/Threading.h> | |
47 | ||
48 | using namespace WTF; | |
49 | ||
50 | namespace JSC { | |
51 | ||
9dae56ea | 52 | |
f9bf01c6 | 53 | // ------------------------------ StatementNode -------------------------------- |
9dae56ea | 54 | |
f9bf01c6 | 55 | void StatementNode::setLoc(int firstLine, int lastLine) |
9dae56ea | 56 | { |
f9bf01c6 A |
57 | m_line = firstLine; |
58 | m_lastLine = lastLine; | |
9dae56ea A |
59 | } |
60 | ||
f9bf01c6 | 61 | // ------------------------------ SourceElements -------------------------------- |
9dae56ea | 62 | |
f9bf01c6 | 63 | void SourceElements::append(StatementNode* statement) |
9dae56ea | 64 | { |
f9bf01c6 A |
65 | if (statement->isEmptyStatement()) |
66 | return; | |
67 | m_statements.append(statement); | |
9dae56ea A |
68 | } |
69 | ||
14957cd0 | 70 | StatementNode* SourceElements::singleStatement() const |
9dae56ea | 71 | { |
f9bf01c6 A |
72 | size_t size = m_statements.size(); |
73 | return size == 1 ? m_statements[0] : 0; | |
9dae56ea A |
74 | } |
75 | ||
9dae56ea A |
76 | // -----------------------------ScopeNodeData --------------------------- |
77 | ||
14957cd0 | 78 | ScopeNodeData::ScopeNodeData(ParserArena& arena, SourceElements* statements, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, int numConstants) |
9dae56ea | 79 | : m_numConstants(numConstants) |
f9bf01c6 | 80 | , m_statements(statements) |
9dae56ea | 81 | { |
ba379fdc | 82 | m_arena.swap(arena); |
9dae56ea | 83 | if (varStack) |
ba379fdc | 84 | m_varStack.swap(*varStack); |
9dae56ea | 85 | if (funcStack) |
ba379fdc | 86 | m_functionStack.swap(*funcStack); |
14957cd0 | 87 | m_capturedVariables.swap(capturedVariables); |
9dae56ea A |
88 | } |
89 | ||
90 | // ------------------------------ ScopeNode ----------------------------- | |
91 | ||
14957cd0 | 92 | ScopeNode::ScopeNode(JSGlobalData* globalData, bool inStrictContext) |
9dae56ea | 93 | : StatementNode(globalData) |
ba379fdc | 94 | , ParserArenaRefCounted(globalData) |
14957cd0 | 95 | , m_features(inStrictContext ? StrictModeFeature : NoFeatures) |
9dae56ea | 96 | { |
9dae56ea A |
97 | } |
98 | ||
14957cd0 | 99 | ScopeNode::ScopeNode(JSGlobalData* globalData, const SourceCode& source, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, CodeFeatures features, int numConstants) |
9dae56ea | 100 | : StatementNode(globalData) |
ba379fdc | 101 | , ParserArenaRefCounted(globalData) |
14957cd0 | 102 | , m_data(adoptPtr(new ScopeNodeData(globalData->parser->arena(), children, varStack, funcStack, capturedVariables, numConstants))) |
9dae56ea A |
103 | , m_features(features) |
104 | , m_source(source) | |
105 | { | |
f9bf01c6 A |
106 | } |
107 | ||
108 | StatementNode* ScopeNode::singleStatement() const | |
109 | { | |
110 | return m_data->m_statements ? m_data->m_statements->singleStatement() : 0; | |
9dae56ea A |
111 | } |
112 | ||
9dae56ea A |
113 | // ------------------------------ ProgramNode ----------------------------- |
114 | ||
14957cd0 A |
115 | inline ProgramNode::ProgramNode(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
116 | : ScopeNode(globalData, source, children, varStack, funcStack, capturedVariables, features, numConstants) | |
9dae56ea A |
117 | { |
118 | } | |
119 | ||
14957cd0 | 120 | PassRefPtr<ProgramNode> ProgramNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
9dae56ea | 121 | { |
14957cd0 | 122 | RefPtr<ProgramNode> node = new ProgramNode(globalData, children, varStack, funcStack, capturedVariables, source, features, numConstants); |
ba379fdc A |
123 | |
124 | ASSERT(node->data()->m_arena.last() == node); | |
125 | node->data()->m_arena.removeLast(); | |
126 | ASSERT(!node->data()->m_arena.contains(node.get())); | |
127 | ||
128 | return node.release(); | |
9dae56ea A |
129 | } |
130 | ||
9dae56ea A |
131 | // ------------------------------ EvalNode ----------------------------- |
132 | ||
14957cd0 A |
133 | inline EvalNode::EvalNode(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
134 | : ScopeNode(globalData, source, children, varStack, funcStack, capturedVariables, features, numConstants) | |
9dae56ea A |
135 | { |
136 | } | |
137 | ||
14957cd0 | 138 | PassRefPtr<EvalNode> EvalNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
9dae56ea | 139 | { |
14957cd0 | 140 | RefPtr<EvalNode> node = new EvalNode(globalData, children, varStack, funcStack, capturedVariables, source, features, numConstants); |
ba379fdc A |
141 | |
142 | ASSERT(node->data()->m_arena.last() == node); | |
143 | node->data()->m_arena.removeLast(); | |
144 | ASSERT(!node->data()->m_arena.contains(node.get())); | |
145 | ||
146 | return node.release(); | |
9dae56ea A |
147 | } |
148 | ||
f9bf01c6 | 149 | // ------------------------------ FunctionBodyNode ----------------------------- |
9dae56ea | 150 | |
f9bf01c6 | 151 | FunctionParameters::FunctionParameters(ParameterNode* firstParameter) |
ba379fdc | 152 | { |
f9bf01c6 A |
153 | for (ParameterNode* parameter = firstParameter; parameter; parameter = parameter->nextParam()) |
154 | append(parameter->ident()); | |
ba379fdc | 155 | } |
9dae56ea | 156 | |
14957cd0 A |
157 | inline FunctionBodyNode::FunctionBodyNode(JSGlobalData* globalData, bool inStrictContext) |
158 | : ScopeNode(globalData, inStrictContext) | |
9dae56ea A |
159 | { |
160 | } | |
161 | ||
14957cd0 A |
162 | inline FunctionBodyNode::FunctionBodyNode(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants) |
163 | : ScopeNode(globalData, sourceCode, children, varStack, funcStack, capturedVariables, features, numConstants) | |
9dae56ea | 164 | { |
9dae56ea A |
165 | } |
166 | ||
f9bf01c6 | 167 | void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident) |
9dae56ea | 168 | { |
9dae56ea | 169 | setSource(source); |
f9bf01c6 | 170 | finishParsing(FunctionParameters::create(firstParameter), ident); |
9dae56ea A |
171 | } |
172 | ||
f9bf01c6 | 173 | void FunctionBodyNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident) |
9dae56ea A |
174 | { |
175 | ASSERT(!source().isNull()); | |
176 | m_parameters = parameters; | |
f9bf01c6 | 177 | m_ident = ident; |
ba379fdc A |
178 | } |
179 | ||
14957cd0 | 180 | FunctionBodyNode* FunctionBodyNode::create(JSGlobalData* globalData, bool inStrictContext) |
9dae56ea | 181 | { |
14957cd0 | 182 | return new FunctionBodyNode(globalData, inStrictContext); |
9dae56ea A |
183 | } |
184 | ||
14957cd0 | 185 | PassRefPtr<FunctionBodyNode> FunctionBodyNode::create(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants) |
9dae56ea | 186 | { |
14957cd0 | 187 | RefPtr<FunctionBodyNode> node = new FunctionBodyNode(globalData, children, varStack, funcStack, capturedVariables, sourceCode, features, numConstants); |
ba379fdc A |
188 | |
189 | ASSERT(node->data()->m_arena.last() == node); | |
190 | node->data()->m_arena.removeLast(); | |
191 | ASSERT(!node->data()->m_arena.contains(node.get())); | |
192 | ||
193 | return node.release(); | |
9dae56ea A |
194 | } |
195 | ||
9dae56ea | 196 | } // namespace JSC |