NodeConstructors.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*
  2. * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #ifndef NodeConstructors_h
  21. #define NodeConstructors_h
  22. #include "Nodes.h"
  23. #include "Lexer.h"
  24. #include "Parser.h"
  25. namespace JSC {
  26. inline void* ParserArenaFreeable::operator new(size_t size, VM* vm)
  27. {
  28. return vm->parserArena->allocateFreeable(size);
  29. }
  30. inline void* ParserArenaDeletable::operator new(size_t size, VM* vm)
  31. {
  32. return vm->parserArena->allocateDeletable(size);
  33. }
  34. inline ParserArenaRefCounted::ParserArenaRefCounted(VM* vm)
  35. {
  36. vm->parserArena->derefWithArena(adoptRef(this));
  37. }
  38. inline Node::Node(const JSTokenLocation& location)
  39. : m_lineNumber(location.line)
  40. , m_startOffset(location.startOffset)
  41. , m_lineStartOffset(location.lineStartOffset)
  42. {
  43. ASSERT(location.startOffset >= location.lineStartOffset);
  44. }
  45. inline ExpressionNode::ExpressionNode(const JSTokenLocation& location, ResultType resultType)
  46. : Node(location)
  47. , m_resultType(resultType)
  48. {
  49. }
  50. inline StatementNode::StatementNode(const JSTokenLocation& location)
  51. : Node(location)
  52. , m_lastLine(-1)
  53. {
  54. }
  55. inline ConstantNode::ConstantNode(const JSTokenLocation& location, ResultType resultType)
  56. : ExpressionNode(location, resultType)
  57. {
  58. }
  59. inline NullNode::NullNode(const JSTokenLocation& location)
  60. : ConstantNode(location, ResultType::nullType())
  61. {
  62. }
  63. inline BooleanNode::BooleanNode(const JSTokenLocation& location, bool value)
  64. : ConstantNode(location, ResultType::booleanType())
  65. , m_value(value)
  66. {
  67. }
  68. inline NumberNode::NumberNode(const JSTokenLocation& location, double value)
  69. : ConstantNode(location, JSValue(value).isInt32() ? ResultType::numberTypeIsInt32() : ResultType::numberType())
  70. , m_value(value)
  71. {
  72. }
  73. inline StringNode::StringNode(const JSTokenLocation& location, const Identifier& value)
  74. : ConstantNode(location, ResultType::stringType())
  75. , m_value(value)
  76. {
  77. }
  78. inline RegExpNode::RegExpNode(const JSTokenLocation& location, const Identifier& pattern, const Identifier& flags)
  79. : ExpressionNode(location)
  80. , m_pattern(pattern)
  81. , m_flags(flags)
  82. {
  83. }
  84. inline ThisNode::ThisNode(const JSTokenLocation& location)
  85. : ExpressionNode(location)
  86. {
  87. }
  88. inline ResolveNode::ResolveNode(const JSTokenLocation& location, const Identifier& ident, unsigned startOffset, unsigned divotLine, unsigned divotLineStart)
  89. : ExpressionNode(location)
  90. , m_ident(ident)
  91. , m_startOffset(startOffset)
  92. , m_divotLine(divotLine)
  93. , m_divotLineStart(divotLineStart)
  94. {
  95. ASSERT(m_startOffset >= m_divotLineStart);
  96. }
  97. inline ElementNode::ElementNode(int elision, ExpressionNode* node)
  98. : m_next(0)
  99. , m_elision(elision)
  100. , m_node(node)
  101. {
  102. }
  103. inline ElementNode::ElementNode(ElementNode* l, int elision, ExpressionNode* node)
  104. : m_next(0)
  105. , m_elision(elision)
  106. , m_node(node)
  107. {
  108. l->m_next = this;
  109. }
  110. inline ArrayNode::ArrayNode(const JSTokenLocation& location, int elision)
  111. : ExpressionNode(location)
  112. , m_element(0)
  113. , m_elision(elision)
  114. , m_optional(true)
  115. {
  116. }
  117. inline ArrayNode::ArrayNode(const JSTokenLocation& location, ElementNode* element)
  118. : ExpressionNode(location)
  119. , m_element(element)
  120. , m_elision(0)
  121. , m_optional(false)
  122. {
  123. }
  124. inline ArrayNode::ArrayNode(const JSTokenLocation& location, int elision, ElementNode* element)
  125. : ExpressionNode(location)
  126. , m_element(element)
  127. , m_elision(elision)
  128. , m_optional(true)
  129. {
  130. }
  131. inline PropertyNode::PropertyNode(VM*, const Identifier& name, ExpressionNode* assign, Type type)
  132. : m_name(name)
  133. , m_assign(assign)
  134. , m_type(type)
  135. {
  136. }
  137. inline PropertyNode::PropertyNode(VM* vm, double name, ExpressionNode* assign, Type type)
  138. : m_name(vm->parserArena->identifierArena().makeNumericIdentifier(vm, name))
  139. , m_assign(assign)
  140. , m_type(type)
  141. {
  142. }
  143. inline PropertyListNode::PropertyListNode(const JSTokenLocation& location, PropertyNode* node)
  144. : ExpressionNode(location)
  145. , m_node(node)
  146. , m_next(0)
  147. {
  148. }
  149. inline PropertyListNode::PropertyListNode(const JSTokenLocation& location, PropertyNode* node, PropertyListNode* list)
  150. : ExpressionNode(location)
  151. , m_node(node)
  152. , m_next(0)
  153. {
  154. list->m_next = this;
  155. }
  156. inline ObjectLiteralNode::ObjectLiteralNode(const JSTokenLocation& location)
  157. : ExpressionNode(location)
  158. , m_list(0)
  159. {
  160. }
  161. inline ObjectLiteralNode::ObjectLiteralNode(const JSTokenLocation& location, PropertyListNode* list)
  162. : ExpressionNode(location)
  163. , m_list(list)
  164. {
  165. }
  166. inline BracketAccessorNode::BracketAccessorNode(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments)
  167. : ExpressionNode(location)
  168. , m_base(base)
  169. , m_subscript(subscript)
  170. , m_subscriptHasAssignments(subscriptHasAssignments)
  171. {
  172. }
  173. inline DotAccessorNode::DotAccessorNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident)
  174. : ExpressionNode(location)
  175. , m_base(base)
  176. , m_ident(ident)
  177. {
  178. }
  179. inline ArgumentListNode::ArgumentListNode(const JSTokenLocation& location, ExpressionNode* expr)
  180. : ExpressionNode(location)
  181. , m_next(0)
  182. , m_expr(expr)
  183. {
  184. }
  185. inline ArgumentListNode::ArgumentListNode(const JSTokenLocation& location, ArgumentListNode* listNode, ExpressionNode* expr)
  186. : ExpressionNode(location)
  187. , m_next(0)
  188. , m_expr(expr)
  189. {
  190. listNode->m_next = this;
  191. }
  192. inline ArgumentsNode::ArgumentsNode()
  193. : m_listNode(0)
  194. {
  195. }
  196. inline ArgumentsNode::ArgumentsNode(ArgumentListNode* listNode)
  197. : m_listNode(listNode)
  198. {
  199. }
  200. inline NewExprNode::NewExprNode(const JSTokenLocation& location, ExpressionNode* expr)
  201. : ExpressionNode(location)
  202. , m_expr(expr)
  203. , m_args(0)
  204. {
  205. }
  206. inline NewExprNode::NewExprNode(const JSTokenLocation& location, ExpressionNode* expr, ArgumentsNode* args)
  207. : ExpressionNode(location)
  208. , m_expr(expr)
  209. , m_args(args)
  210. {
  211. }
  212. inline EvalFunctionCallNode::EvalFunctionCallNode(const JSTokenLocation& location, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  213. : ExpressionNode(location)
  214. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  215. , m_args(args)
  216. {
  217. ASSERT(divot >= divotLineStart);
  218. }
  219. inline FunctionCallValueNode::FunctionCallValueNode(const JSTokenLocation& location, ExpressionNode* expr, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  220. : ExpressionNode(location)
  221. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  222. , m_expr(expr)
  223. , m_args(args)
  224. {
  225. }
  226. inline FunctionCallResolveNode::FunctionCallResolveNode(const JSTokenLocation& location, const Identifier& ident, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  227. : ExpressionNode(location)
  228. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  229. , m_ident(ident)
  230. , m_args(args)
  231. {
  232. }
  233. inline FunctionCallBracketNode::FunctionCallBracketNode(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* subscript, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  234. : ExpressionNode(location)
  235. , ThrowableSubExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  236. , m_base(base)
  237. , m_subscript(subscript)
  238. , m_args(args)
  239. {
  240. }
  241. inline FunctionCallDotNode::FunctionCallDotNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  242. : ExpressionNode(location)
  243. , ThrowableSubExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  244. , m_base(base)
  245. , m_ident(ident)
  246. , m_args(args)
  247. {
  248. }
  249. inline CallFunctionCallDotNode::CallFunctionCallDotNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  250. : FunctionCallDotNode(location, base, ident, args, divot, startOffset, endOffset, divotLine, divotLineStart)
  251. {
  252. }
  253. inline ApplyFunctionCallDotNode::ApplyFunctionCallDotNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident, ArgumentsNode* args, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  254. : FunctionCallDotNode(location, base, ident, args, divot, startOffset, endOffset, divotLine, divotLineStart)
  255. {
  256. }
  257. inline PostfixNode::PostfixNode(const JSTokenLocation& location, ExpressionNode* expr, Operator oper, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  258. : PrefixNode(location, expr, oper, divot, startOffset, endOffset, divotLine, divotLineStart)
  259. {
  260. }
  261. inline DeleteResolveNode::DeleteResolveNode(const JSTokenLocation& location, const Identifier& ident, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  262. : ExpressionNode(location)
  263. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  264. , m_ident(ident)
  265. {
  266. }
  267. inline DeleteBracketNode::DeleteBracketNode(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* subscript, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  268. : ExpressionNode(location)
  269. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  270. , m_base(base)
  271. , m_subscript(subscript)
  272. {
  273. }
  274. inline DeleteDotNode::DeleteDotNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  275. : ExpressionNode(location)
  276. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  277. , m_base(base)
  278. , m_ident(ident)
  279. {
  280. }
  281. inline DeleteValueNode::DeleteValueNode(const JSTokenLocation& location, ExpressionNode* expr)
  282. : ExpressionNode(location)
  283. , m_expr(expr)
  284. {
  285. }
  286. inline VoidNode::VoidNode(const JSTokenLocation& location, ExpressionNode* expr)
  287. : ExpressionNode(location)
  288. , m_expr(expr)
  289. {
  290. }
  291. inline TypeOfResolveNode::TypeOfResolveNode(const JSTokenLocation& location, const Identifier& ident)
  292. : ExpressionNode(location, ResultType::stringType())
  293. , m_ident(ident)
  294. {
  295. }
  296. inline TypeOfValueNode::TypeOfValueNode(const JSTokenLocation& location, ExpressionNode* expr)
  297. : ExpressionNode(location, ResultType::stringType())
  298. , m_expr(expr)
  299. {
  300. }
  301. inline PrefixNode::PrefixNode(const JSTokenLocation& location, ExpressionNode* expr, Operator oper, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  302. : ExpressionNode(location)
  303. , ThrowablePrefixedSubExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  304. , m_expr(expr)
  305. , m_operator(oper)
  306. {
  307. }
  308. inline UnaryOpNode::UnaryOpNode(const JSTokenLocation& location, ResultType type, ExpressionNode* expr, OpcodeID opcodeID)
  309. : ExpressionNode(location, type)
  310. , m_expr(expr)
  311. , m_opcodeID(opcodeID)
  312. {
  313. }
  314. inline UnaryPlusNode::UnaryPlusNode(const JSTokenLocation& location, ExpressionNode* expr)
  315. : UnaryOpNode(location, ResultType::numberType(), expr, op_to_number)
  316. {
  317. }
  318. inline NegateNode::NegateNode(const JSTokenLocation& location, ExpressionNode* expr)
  319. : UnaryOpNode(location, ResultType::numberType(), expr, op_negate)
  320. {
  321. }
  322. inline BitwiseNotNode::BitwiseNotNode(const JSTokenLocation& location, ExpressionNode* expr)
  323. : ExpressionNode(location, ResultType::forBitOp())
  324. , m_expr(expr)
  325. {
  326. }
  327. inline LogicalNotNode::LogicalNotNode(const JSTokenLocation& location, ExpressionNode* expr)
  328. : UnaryOpNode(location, ResultType::booleanType(), expr, op_not)
  329. {
  330. }
  331. inline BinaryOpNode::BinaryOpNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID opcodeID, bool rightHasAssignments)
  332. : ExpressionNode(location)
  333. , m_expr1(expr1)
  334. , m_expr2(expr2)
  335. , m_opcodeID(opcodeID)
  336. , m_rightHasAssignments(rightHasAssignments)
  337. {
  338. }
  339. inline BinaryOpNode::BinaryOpNode(const JSTokenLocation& location, ResultType type, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID opcodeID, bool rightHasAssignments)
  340. : ExpressionNode(location, type)
  341. , m_expr1(expr1)
  342. , m_expr2(expr2)
  343. , m_opcodeID(opcodeID)
  344. , m_rightHasAssignments(rightHasAssignments)
  345. {
  346. }
  347. inline MultNode::MultNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  348. : BinaryOpNode(location, ResultType::numberType(), expr1, expr2, op_mul, rightHasAssignments)
  349. {
  350. }
  351. inline DivNode::DivNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  352. : BinaryOpNode(location, ResultType::numberType(), expr1, expr2, op_div, rightHasAssignments)
  353. {
  354. }
  355. inline ModNode::ModNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  356. : BinaryOpNode(location, ResultType::numberType(), expr1, expr2, op_mod, rightHasAssignments)
  357. {
  358. }
  359. inline AddNode::AddNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  360. : BinaryOpNode(location, ResultType::forAdd(expr1->resultDescriptor(), expr2->resultDescriptor()), expr1, expr2, op_add, rightHasAssignments)
  361. {
  362. }
  363. inline SubNode::SubNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  364. : BinaryOpNode(location, ResultType::numberType(), expr1, expr2, op_sub, rightHasAssignments)
  365. {
  366. }
  367. inline LeftShiftNode::LeftShiftNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  368. : BinaryOpNode(location, ResultType::forBitOp(), expr1, expr2, op_lshift, rightHasAssignments)
  369. {
  370. }
  371. inline RightShiftNode::RightShiftNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  372. : BinaryOpNode(location, ResultType::forBitOp(), expr1, expr2, op_rshift, rightHasAssignments)
  373. {
  374. }
  375. inline UnsignedRightShiftNode::UnsignedRightShiftNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  376. : BinaryOpNode(location, ResultType::numberType(), expr1, expr2, op_urshift, rightHasAssignments)
  377. {
  378. }
  379. inline LessNode::LessNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  380. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_less, rightHasAssignments)
  381. {
  382. }
  383. inline GreaterNode::GreaterNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  384. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_greater, rightHasAssignments)
  385. {
  386. }
  387. inline LessEqNode::LessEqNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  388. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_lesseq, rightHasAssignments)
  389. {
  390. }
  391. inline GreaterEqNode::GreaterEqNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  392. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_greatereq, rightHasAssignments)
  393. {
  394. }
  395. inline ThrowableBinaryOpNode::ThrowableBinaryOpNode(const JSTokenLocation& location, ResultType type, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID opcodeID, bool rightHasAssignments)
  396. : BinaryOpNode(location, type, expr1, expr2, opcodeID, rightHasAssignments)
  397. {
  398. }
  399. inline ThrowableBinaryOpNode::ThrowableBinaryOpNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID opcodeID, bool rightHasAssignments)
  400. : BinaryOpNode(location, expr1, expr2, opcodeID, rightHasAssignments)
  401. {
  402. }
  403. inline InstanceOfNode::InstanceOfNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  404. : ThrowableBinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_instanceof, rightHasAssignments)
  405. {
  406. }
  407. inline InNode::InNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  408. : ThrowableBinaryOpNode(location, expr1, expr2, op_in, rightHasAssignments)
  409. {
  410. }
  411. inline EqualNode::EqualNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  412. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_eq, rightHasAssignments)
  413. {
  414. }
  415. inline NotEqualNode::NotEqualNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  416. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_neq, rightHasAssignments)
  417. {
  418. }
  419. inline StrictEqualNode::StrictEqualNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  420. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_stricteq, rightHasAssignments)
  421. {
  422. }
  423. inline NotStrictEqualNode::NotStrictEqualNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  424. : BinaryOpNode(location, ResultType::booleanType(), expr1, expr2, op_nstricteq, rightHasAssignments)
  425. {
  426. }
  427. inline BitAndNode::BitAndNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  428. : BinaryOpNode(location, ResultType::forBitOp(), expr1, expr2, op_bitand, rightHasAssignments)
  429. {
  430. }
  431. inline BitOrNode::BitOrNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  432. : BinaryOpNode(location, ResultType::forBitOp(), expr1, expr2, op_bitor, rightHasAssignments)
  433. {
  434. }
  435. inline BitXOrNode::BitXOrNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
  436. : BinaryOpNode(location, ResultType::forBitOp(), expr1, expr2, op_bitxor, rightHasAssignments)
  437. {
  438. }
  439. inline LogicalOpNode::LogicalOpNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator oper)
  440. : ExpressionNode(location, ResultType::booleanType())
  441. , m_expr1(expr1)
  442. , m_expr2(expr2)
  443. , m_operator(oper)
  444. {
  445. }
  446. inline ConditionalNode::ConditionalNode(const JSTokenLocation& location, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2)
  447. : ExpressionNode(location)
  448. , m_logical(logical)
  449. , m_expr1(expr1)
  450. , m_expr2(expr2)
  451. {
  452. }
  453. inline ReadModifyResolveNode::ReadModifyResolveNode(const JSTokenLocation& location, const Identifier& ident, Operator oper, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  454. : ExpressionNode(location)
  455. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  456. , m_ident(ident)
  457. , m_right(right)
  458. , m_operator(oper)
  459. , m_rightHasAssignments(rightHasAssignments)
  460. {
  461. ASSERT(divot >= divotLineStart);
  462. ASSERT(divot - startOffset >= divotLineStart);
  463. }
  464. inline AssignResolveNode::AssignResolveNode(const JSTokenLocation& location, const Identifier& ident, ExpressionNode* right)
  465. : ExpressionNode(location)
  466. , m_ident(ident)
  467. , m_right(right)
  468. {
  469. }
  470. inline ReadModifyBracketNode::ReadModifyBracketNode(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* subscript, Operator oper, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  471. : ExpressionNode(location)
  472. , ThrowableSubExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  473. , m_base(base)
  474. , m_subscript(subscript)
  475. , m_right(right)
  476. , m_operator(oper)
  477. , m_subscriptHasAssignments(subscriptHasAssignments)
  478. , m_rightHasAssignments(rightHasAssignments)
  479. {
  480. }
  481. inline AssignBracketNode::AssignBracketNode(const JSTokenLocation& location, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  482. : ExpressionNode(location)
  483. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  484. , m_base(base)
  485. , m_subscript(subscript)
  486. , m_right(right)
  487. , m_subscriptHasAssignments(subscriptHasAssignments)
  488. , m_rightHasAssignments(rightHasAssignments)
  489. {
  490. }
  491. inline AssignDotNode::AssignDotNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  492. : ExpressionNode(location)
  493. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  494. , m_base(base)
  495. , m_ident(ident)
  496. , m_right(right)
  497. , m_rightHasAssignments(rightHasAssignments)
  498. {
  499. }
  500. inline ReadModifyDotNode::ReadModifyDotNode(const JSTokenLocation& location, ExpressionNode* base, const Identifier& ident, Operator oper, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  501. : ExpressionNode(location)
  502. , ThrowableSubExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  503. , m_base(base)
  504. , m_ident(ident)
  505. , m_right(right)
  506. , m_operator(oper)
  507. , m_rightHasAssignments(rightHasAssignments)
  508. {
  509. }
  510. inline AssignErrorNode::AssignErrorNode(const JSTokenLocation& location, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
  511. : ExpressionNode(location)
  512. , ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
  513. {
  514. }
  515. inline CommaNode::CommaNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2)
  516. : ExpressionNode(location)
  517. {
  518. m_expressions.append(expr1);
  519. m_expressions.append(expr2);
  520. }
  521. inline ConstStatementNode::ConstStatementNode(const JSTokenLocation& location, ConstDeclNode* next)
  522. : StatementNode(location)
  523. , m_next(next)
  524. {
  525. }
  526. inline SourceElements::SourceElements()
  527. {
  528. }
  529. inline EmptyStatementNode::EmptyStatementNode(const JSTokenLocation& location)
  530. : StatementNode(location)
  531. {
  532. }
  533. inline DebuggerStatementNode::DebuggerStatementNode(const JSTokenLocation& location)
  534. : StatementNode(location)
  535. {
  536. }
  537. inline ExprStatementNode::ExprStatementNode(const JSTokenLocation& location, ExpressionNode* expr)
  538. : StatementNode(location)
  539. , m_expr(expr)
  540. {
  541. }
  542. inline VarStatementNode::VarStatementNode(const JSTokenLocation& location, ExpressionNode* expr)
  543. : StatementNode(location)
  544. , m_expr(expr)
  545. {
  546. }
  547. inline IfElseNode::IfElseNode(const JSTokenLocation& location, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock)
  548. : StatementNode(location)
  549. , m_condition(condition)
  550. , m_ifBlock(ifBlock)
  551. , m_elseBlock(elseBlock)
  552. {
  553. }
  554. inline DoWhileNode::DoWhileNode(const JSTokenLocation& location, StatementNode* statement, ExpressionNode* expr)
  555. : StatementNode(location)
  556. , m_statement(statement)
  557. , m_expr(expr)
  558. {
  559. }
  560. inline WhileNode::WhileNode(const JSTokenLocation& location, ExpressionNode* expr, StatementNode* statement)
  561. : StatementNode(location)
  562. , m_expr(expr)
  563. , m_statement(statement)
  564. {
  565. }
  566. inline ForNode::ForNode(const JSTokenLocation& location, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode* statement)
  567. : StatementNode(location)
  568. , m_expr1(expr1)
  569. , m_expr2(expr2)
  570. , m_expr3(expr3)
  571. , m_statement(statement)
  572. {
  573. ASSERT(statement);
  574. }
  575. inline ContinueNode::ContinueNode(VM* vm, const JSTokenLocation& location)
  576. : StatementNode(location)
  577. , m_ident(vm->propertyNames->nullIdentifier)
  578. {
  579. }
  580. inline ContinueNode::ContinueNode(const JSTokenLocation& location, const Identifier& ident)
  581. : StatementNode(location)
  582. , m_ident(ident)
  583. {
  584. }
  585. inline BreakNode::BreakNode(VM* vm, const JSTokenLocation& location)
  586. : StatementNode(location)
  587. , m_ident(vm->propertyNames->nullIdentifier)
  588. {
  589. }
  590. inline BreakNode::BreakNode(const JSTokenLocation& location, const Identifier& ident)
  591. : StatementNode(location)
  592. , m_ident(ident)
  593. {
  594. }
  595. inline ReturnNode::ReturnNode(const JSTokenLocation& location, ExpressionNode* value)
  596. : StatementNode(location)
  597. , m_value(value)
  598. {
  599. }
  600. inline WithNode::WithNode(const JSTokenLocation& location, ExpressionNode* expr, StatementNode* statement, uint32_t divot, unsigned divotLine, unsigned divotLineStart, uint32_t expressionLength)
  601. : StatementNode(location)
  602. , m_expr(expr)
  603. , m_statement(statement)
  604. , m_divot(divot)
  605. , m_divotLine(divotLine)
  606. , m_divotLineStart(divotLineStart)
  607. , m_expressionLength(expressionLength)
  608. {
  609. }
  610. inline LabelNode::LabelNode(const JSTokenLocation& location, const Identifier& name, StatementNode* statement)
  611. : StatementNode(location)
  612. , m_name(name)
  613. , m_statement(statement)
  614. {
  615. }
  616. inline ThrowNode::ThrowNode(const JSTokenLocation& location, ExpressionNode* expr)
  617. : StatementNode(location)
  618. , m_expr(expr)
  619. {
  620. }
  621. inline TryNode::TryNode(const JSTokenLocation& location, StatementNode* tryBlock, const Identifier& exceptionIdent, StatementNode* catchBlock, StatementNode* finallyBlock)
  622. : StatementNode(location)
  623. , m_tryBlock(tryBlock)
  624. , m_exceptionIdent(exceptionIdent)
  625. , m_catchBlock(catchBlock)
  626. , m_finallyBlock(finallyBlock)
  627. {
  628. }
  629. inline ParameterNode::ParameterNode(const Identifier& ident)
  630. : m_ident(ident)
  631. , m_next(0)
  632. {
  633. }
  634. inline ParameterNode::ParameterNode(ParameterNode* l, const Identifier& ident)
  635. : m_ident(ident)
  636. , m_next(0)
  637. {
  638. l->m_next = this;
  639. }
  640. inline FuncExprNode::FuncExprNode(const JSTokenLocation& location, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter)
  641. : ExpressionNode(location)
  642. , m_body(body)
  643. {
  644. m_body->finishParsing(source, parameter, ident, FunctionNameIsInScope);
  645. }
  646. inline FuncDeclNode::FuncDeclNode(const JSTokenLocation& location, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter)
  647. : StatementNode(location)
  648. , m_body(body)
  649. {
  650. m_body->finishParsing(source, parameter, ident, FunctionNameIsNotInScope);
  651. }
  652. inline CaseClauseNode::CaseClauseNode(ExpressionNode* expr, SourceElements* statements)
  653. : m_expr(expr)
  654. , m_statements(statements)
  655. {
  656. }
  657. inline ClauseListNode::ClauseListNode(CaseClauseNode* clause)
  658. : m_clause(clause)
  659. , m_next(0)
  660. {
  661. }
  662. inline ClauseListNode::ClauseListNode(ClauseListNode* clauseList, CaseClauseNode* clause)
  663. : m_clause(clause)
  664. , m_next(0)
  665. {
  666. clauseList->m_next = this;
  667. }
  668. inline CaseBlockNode::CaseBlockNode(ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2)
  669. : m_list1(list1)
  670. , m_defaultClause(defaultClause)
  671. , m_list2(list2)
  672. {
  673. }
  674. inline SwitchNode::SwitchNode(const JSTokenLocation& location, ExpressionNode* expr, CaseBlockNode* block)
  675. : StatementNode(location)
  676. , m_expr(expr)
  677. , m_block(block)
  678. {
  679. }
  680. inline ConstDeclNode::ConstDeclNode(const JSTokenLocation& location, const Identifier& ident, ExpressionNode* init)
  681. : ExpressionNode(location)
  682. , m_ident(ident)
  683. , m_next(0)
  684. , m_init(init)
  685. {
  686. }
  687. inline BlockNode::BlockNode(const JSTokenLocation& location, SourceElements* statements)
  688. : StatementNode(location)
  689. , m_statements(statements)
  690. {
  691. }
  692. inline ForInNode::ForInNode(const JSTokenLocation& location, ExpressionNode* l, ExpressionNode* expr, StatementNode* statement)
  693. : StatementNode(location)
  694. , m_init(0)
  695. , m_lexpr(l)
  696. , m_expr(expr)
  697. , m_statement(statement)
  698. {
  699. }
  700. inline ForInNode::ForInNode(VM* vm, const JSTokenLocation& location, const Identifier& ident, ExpressionNode* in, ExpressionNode* expr, StatementNode* statement, unsigned divot, int startOffset, int endOffset, unsigned divotLine, unsigned divotLineStart)
  701. : StatementNode(location)
  702. , m_init(0)
  703. , m_lexpr(new (vm) ResolveNode(location, ident, divot - startOffset, divotLine, divotLineStart))
  704. , m_expr(expr)
  705. , m_statement(statement)
  706. {
  707. if (in) {
  708. AssignResolveNode* node = new (vm) AssignResolveNode(location, ident, in);
  709. ASSERT(divot >= divotLineStart);
  710. node->setExceptionSourceCode(divot, divot - startOffset, endOffset - divot, divotLine, divotLineStart);
  711. m_init = node;
  712. }
  713. // for( var foo = bar in baz )
  714. }
  715. } // namespace JSC
  716. #endif // NodeConstructors_h