]>
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 | { |
6fe7ccc8 | 57 | m_lineNumber = firstLine; |
f9bf01c6 | 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 | // ------------------------------ ScopeNode ----------------------------- |
77 | ||
6fe7ccc8 A |
78 | ScopeNode::ScopeNode(JSGlobalData* globalData, int lineNumber, bool inStrictContext) |
79 | : StatementNode(lineNumber) | |
ba379fdc | 80 | , ParserArenaRefCounted(globalData) |
14957cd0 | 81 | , m_features(inStrictContext ? StrictModeFeature : NoFeatures) |
6fe7ccc8 A |
82 | , m_numConstants(0) |
83 | , m_statements(0) | |
9dae56ea | 84 | { |
9dae56ea A |
85 | } |
86 | ||
6fe7ccc8 A |
87 | ScopeNode::ScopeNode(JSGlobalData* globalData, int lineNumber, const SourceCode& source, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, CodeFeatures features, int numConstants) |
88 | : StatementNode(lineNumber) | |
ba379fdc | 89 | , ParserArenaRefCounted(globalData) |
9dae56ea A |
90 | , m_features(features) |
91 | , m_source(source) | |
6fe7ccc8 A |
92 | , m_numConstants(numConstants) |
93 | , m_statements(children) | |
9dae56ea | 94 | { |
6fe7ccc8 A |
95 | m_arena.swap(*globalData->parserArena); |
96 | if (varStack) | |
97 | m_varStack.swap(*varStack); | |
98 | if (funcStack) | |
99 | m_functionStack.swap(*funcStack); | |
100 | m_capturedVariables.swap(capturedVariables); | |
f9bf01c6 A |
101 | } |
102 | ||
103 | StatementNode* ScopeNode::singleStatement() const | |
104 | { | |
6fe7ccc8 | 105 | return m_statements ? m_statements->singleStatement() : 0; |
9dae56ea A |
106 | } |
107 | ||
9dae56ea A |
108 | // ------------------------------ ProgramNode ----------------------------- |
109 | ||
6fe7ccc8 A |
110 | inline ProgramNode::ProgramNode(JSGlobalData* globalData, int lineNumber, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
111 | : ScopeNode(globalData, lineNumber, source, children, varStack, funcStack, capturedVariables, features, numConstants) | |
9dae56ea A |
112 | { |
113 | } | |
114 | ||
6fe7ccc8 | 115 | PassRefPtr<ProgramNode> ProgramNode::create(JSGlobalData* globalData, int lineNumber, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
9dae56ea | 116 | { |
6fe7ccc8 | 117 | RefPtr<ProgramNode> node = new ProgramNode(globalData, lineNumber, children, varStack, funcStack, capturedVariables, source, features, numConstants); |
ba379fdc | 118 | |
6fe7ccc8 A |
119 | ASSERT(node->m_arena.last() == node); |
120 | node->m_arena.removeLast(); | |
121 | ASSERT(!node->m_arena.contains(node.get())); | |
ba379fdc A |
122 | |
123 | return node.release(); | |
9dae56ea A |
124 | } |
125 | ||
9dae56ea A |
126 | // ------------------------------ EvalNode ----------------------------- |
127 | ||
6fe7ccc8 A |
128 | inline EvalNode::EvalNode(JSGlobalData* globalData, int lineNumber, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
129 | : ScopeNode(globalData, lineNumber, source, children, varStack, funcStack, capturedVariables, features, numConstants) | |
9dae56ea A |
130 | { |
131 | } | |
132 | ||
6fe7ccc8 | 133 | PassRefPtr<EvalNode> EvalNode::create(JSGlobalData* globalData, int lineNumber, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& source, CodeFeatures features, int numConstants) |
9dae56ea | 134 | { |
6fe7ccc8 | 135 | RefPtr<EvalNode> node = new EvalNode(globalData, lineNumber, children, varStack, funcStack, capturedVariables, source, features, numConstants); |
ba379fdc | 136 | |
6fe7ccc8 A |
137 | ASSERT(node->m_arena.last() == node); |
138 | node->m_arena.removeLast(); | |
139 | ASSERT(!node->m_arena.contains(node.get())); | |
ba379fdc A |
140 | |
141 | return node.release(); | |
9dae56ea A |
142 | } |
143 | ||
f9bf01c6 | 144 | // ------------------------------ FunctionBodyNode ----------------------------- |
9dae56ea | 145 | |
f9bf01c6 | 146 | FunctionParameters::FunctionParameters(ParameterNode* firstParameter) |
ba379fdc | 147 | { |
f9bf01c6 A |
148 | for (ParameterNode* parameter = firstParameter; parameter; parameter = parameter->nextParam()) |
149 | append(parameter->ident()); | |
ba379fdc | 150 | } |
9dae56ea | 151 | |
6fe7ccc8 A |
152 | inline FunctionBodyNode::FunctionBodyNode(JSGlobalData* globalData, int lineNumber, bool inStrictContext) |
153 | : ScopeNode(globalData, lineNumber, inStrictContext) | |
9dae56ea A |
154 | { |
155 | } | |
156 | ||
6fe7ccc8 A |
157 | inline FunctionBodyNode::FunctionBodyNode(JSGlobalData* globalData, int lineNumber, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants) |
158 | : ScopeNode(globalData, lineNumber, sourceCode, children, varStack, funcStack, capturedVariables, features, numConstants) | |
9dae56ea | 159 | { |
9dae56ea A |
160 | } |
161 | ||
f9bf01c6 | 162 | void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident) |
9dae56ea | 163 | { |
9dae56ea | 164 | setSource(source); |
f9bf01c6 | 165 | finishParsing(FunctionParameters::create(firstParameter), ident); |
9dae56ea A |
166 | } |
167 | ||
f9bf01c6 | 168 | void FunctionBodyNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident) |
9dae56ea A |
169 | { |
170 | ASSERT(!source().isNull()); | |
171 | m_parameters = parameters; | |
f9bf01c6 | 172 | m_ident = ident; |
ba379fdc A |
173 | } |
174 | ||
6fe7ccc8 | 175 | FunctionBodyNode* FunctionBodyNode::create(JSGlobalData* globalData, int lineNumber, bool inStrictContext) |
9dae56ea | 176 | { |
6fe7ccc8 | 177 | return new FunctionBodyNode(globalData, lineNumber, inStrictContext); |
9dae56ea A |
178 | } |
179 | ||
6fe7ccc8 | 180 | PassRefPtr<FunctionBodyNode> FunctionBodyNode::create(JSGlobalData* globalData, int lineNumber, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants) |
9dae56ea | 181 | { |
6fe7ccc8 | 182 | RefPtr<FunctionBodyNode> node = new FunctionBodyNode(globalData, lineNumber, children, varStack, funcStack, capturedVariables, sourceCode, features, numConstants); |
ba379fdc | 183 | |
6fe7ccc8 A |
184 | ASSERT(node->m_arena.last() == node); |
185 | node->m_arena.removeLast(); | |
186 | ASSERT(!node->m_arena.contains(node.get())); | |
ba379fdc A |
187 | |
188 | return node.release(); | |
9dae56ea A |
189 | } |
190 | ||
9dae56ea | 191 | } // namespace JSC |