12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628 |
- /*
- * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
- * Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
- * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
- * Copyright (C) 2007 Maks Orlovich
- * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
- #ifndef Nodes_h
- #define Nodes_h
- #include "Error.h"
- #include "JITCode.h"
- #include "Opcode.h"
- #include "ParserArena.h"
- #include "ParserTokens.h"
- #include "ResultType.h"
- #include "SourceCode.h"
- #include "SymbolTable.h"
- #include <wtf/MathExtras.h>
- namespace JSC {
- class ArgumentListNode;
- class BytecodeGenerator;
- class FunctionBodyNode;
- class Label;
- class PropertyListNode;
- class ReadModifyResolveNode;
- class RegisterID;
- class JSScope;
- class ScopeNode;
- enum Operator {
- OpEqual,
- OpPlusEq,
- OpMinusEq,
- OpMultEq,
- OpDivEq,
- OpPlusPlus,
- OpMinusMinus,
- OpAndEq,
- OpXOrEq,
- OpOrEq,
- OpModEq,
- OpLShift,
- OpRShift,
- OpURShift
- };
-
- enum LogicalOperator {
- OpLogicalAnd,
- OpLogicalOr
- };
- enum FallThroughMode {
- FallThroughMeansTrue = 0,
- FallThroughMeansFalse = 1
- };
- inline FallThroughMode invert(FallThroughMode fallThroughMode) { return static_cast<FallThroughMode>(!fallThroughMode); }
- typedef HashSet<RefPtr<StringImpl>, IdentifierRepHash> IdentifierSet;
- namespace DeclarationStacks {
- enum VarAttrs { IsConstant = 1, HasInitializer = 2 };
- typedef Vector<std::pair<const Identifier*, unsigned> > VarStack;
- typedef Vector<FunctionBodyNode*> FunctionStack;
- }
- struct SwitchInfo {
- enum SwitchType { SwitchNone, SwitchImmediate, SwitchCharacter, SwitchString };
- uint32_t bytecodeOffset;
- SwitchType switchType;
- };
- class ParserArenaFreeable {
- public:
- // ParserArenaFreeable objects are are freed when the arena is deleted.
- // Destructors are not called. Clients must not call delete on such objects.
- void* operator new(size_t, VM*);
- };
- class ParserArenaDeletable {
- public:
- virtual ~ParserArenaDeletable() { }
- // ParserArenaDeletable objects are deleted when the arena is deleted.
- // Clients must not call delete directly on such objects.
- void* operator new(size_t, VM*);
- };
- template <typename T>
- struct ParserArenaData : ParserArenaDeletable {
- T data;
- };
- class ParserArenaRefCounted : public RefCounted<ParserArenaRefCounted> {
- protected:
- ParserArenaRefCounted(VM*);
- public:
- virtual ~ParserArenaRefCounted()
- {
- ASSERT(deletionHasBegun());
- }
- };
- class Node : public ParserArenaFreeable {
- protected:
- Node(const JSTokenLocation&);
- public:
- virtual ~Node() { }
- int lineNo() const { return m_lineNumber; }
- int startOffset() const { return m_startOffset; }
- int lineStartOffset() const { return m_lineStartOffset; }
- protected:
- int m_lineNumber;
- int m_startOffset;
- int m_lineStartOffset;
- };
- class ExpressionNode : public Node {
- protected:
- ExpressionNode(const JSTokenLocation&, ResultType = ResultType::unknownType());
- public:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0;
- virtual bool isNumber() const { return false; }
- virtual bool isString() const { return false; }
- virtual bool isNull() const { return false; }
- virtual bool isPure(BytecodeGenerator&) const { return false; }
- virtual bool isConstant() const { return false; }
- virtual bool isLocation() const { return false; }
- virtual bool isResolveNode() const { return false; }
- virtual bool isBracketAccessorNode() const { return false; }
- virtual bool isDotAccessorNode() const { return false; }
- virtual bool isFuncExprNode() const { return false; }
- virtual bool isCommaNode() const { return false; }
- virtual bool isSimpleArray() const { return false; }
- virtual bool isAdd() const { return false; }
- virtual bool isSubtract() const { return false; }
- virtual bool isBoolean() const { return false; }
- virtual void emitBytecodeInConditionContext(BytecodeGenerator&, Label*, Label*, FallThroughMode);
- virtual ExpressionNode* stripUnaryPlus() { return this; }
- ResultType resultDescriptor() const { return m_resultType; }
- private:
- ResultType m_resultType;
- };
- class StatementNode : public Node {
- protected:
- StatementNode(const JSTokenLocation&);
- public:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* destination = 0) = 0;
- void setLoc(unsigned firstLine, unsigned lastLine, int startOffset, int lineStartOffset);
- unsigned firstLine() const { return lineNo(); }
- unsigned lastLine() const { return m_lastLine; }
- virtual bool isEmptyStatement() const { return false; }
- virtual bool isReturnNode() const { return false; }
- virtual bool isExprStatement() const { return false; }
- virtual bool isBreak() const { return false; }
- virtual bool isContinue() const { return false; }
- virtual bool isBlock() const { return false; }
- private:
- int m_lastLine;
- };
- class ConstantNode : public ExpressionNode {
- public:
- ConstantNode(const JSTokenLocation&, ResultType);
- virtual bool isPure(BytecodeGenerator&) const { return true; }
- virtual bool isConstant() const { return true; }
- virtual JSValue jsValue(BytecodeGenerator&) const = 0;
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode);
- };
- class NullNode : public ConstantNode {
- public:
- NullNode(const JSTokenLocation&);
- private:
- virtual bool isNull() const { return true; }
- virtual JSValue jsValue(BytecodeGenerator&) const { return jsNull(); }
- };
- class BooleanNode : public ConstantNode {
- public:
- BooleanNode(const JSTokenLocation&, bool value);
- bool value() { return m_value; }
- private:
- virtual bool isBoolean() const { return true; }
- virtual JSValue jsValue(BytecodeGenerator&) const { return jsBoolean(m_value); }
- bool m_value;
- };
- class NumberNode : public ConstantNode {
- public:
- NumberNode(const JSTokenLocation&, double value);
- double value() { return m_value; }
- void setValue(double value) { m_value = value; }
- private:
- virtual bool isNumber() const { return true; }
- virtual JSValue jsValue(BytecodeGenerator&) const { return jsNumber(m_value); }
- double m_value;
- };
- class StringNode : public ConstantNode {
- public:
- StringNode(const JSTokenLocation&, const Identifier&);
- const Identifier& value() { return m_value; }
- private:
- virtual bool isString() const { return true; }
- virtual JSValue jsValue(BytecodeGenerator&) const;
- const Identifier& m_value;
- };
-
- class ThrowableExpressionData {
- public:
- ThrowableExpressionData()
- : m_divot(static_cast<uint32_t>(-1))
- , m_divotStartOffset(static_cast<uint16_t>(-1))
- , m_divotEndOffset(static_cast<uint16_t>(-1))
- , m_divotLine(static_cast<uint32_t>(-1))
- , m_divotLineStart(static_cast<uint32_t>(-1))
- {
- }
-
- ThrowableExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
- : m_divot(divot)
- , m_divotStartOffset(startOffset)
- , m_divotEndOffset(endOffset)
- , m_divotLine(divotLine)
- , m_divotLineStart(divotLineStart)
- {
- ASSERT(m_divot >= m_divotLineStart);
- }
-
- void setExceptionSourceCode(unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
- {
- ASSERT(divot >= divotLineStart);
- m_divot = divot;
- m_divotStartOffset = startOffset;
- m_divotEndOffset = endOffset;
- m_divotLine = divotLine;
- m_divotLineStart = divotLineStart;
- }
- uint32_t divot() const { return m_divot; }
- uint16_t divotStartOffset() const { return m_divotStartOffset; }
- uint16_t divotEndOffset() const { return m_divotEndOffset; }
- uint32_t divotLine() const { return m_divotLine; }
- uint32_t divotLineStart() const { return m_divotLineStart; }
- protected:
- RegisterID* emitThrowReferenceError(BytecodeGenerator&, const String& message);
- private:
- uint32_t m_divot;
- uint16_t m_divotStartOffset;
- uint16_t m_divotEndOffset;
- uint32_t m_divotLine;
- uint32_t m_divotLineStart;
- };
- class ThrowableSubExpressionData : public ThrowableExpressionData {
- public:
- ThrowableSubExpressionData()
- : m_subexpressionDivotOffset(0)
- , m_subexpressionEndOffset(0)
- , m_subexpressionLineOffset(0)
- , m_subexpressionLineStartOffset(0)
- {
- }
- ThrowableSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
- : ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
- , m_subexpressionDivotOffset(0)
- , m_subexpressionEndOffset(0)
- , m_subexpressionLineOffset(0)
- , m_subexpressionLineStartOffset(0)
- {
- }
- void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset, uint32_t subexpressionLine, uint32_t subexpressionLineStart)
- {
- ASSERT(subexpressionDivot <= divot());
- // Overflow means we can't do this safely, so just point at the primary divot,
- // divotLine, or divotLineStart.
- if ((divot() - subexpressionDivot) & ~0xFFFF)
- return;
- if ((divotLine() - subexpressionLine) & ~0xFFFF)
- return;
- if ((divotLineStart() - subexpressionLineStart) & ~0xFFFF)
- return;
- m_subexpressionDivotOffset = divot() - subexpressionDivot;
- m_subexpressionEndOffset = subexpressionOffset;
- m_subexpressionLineOffset = divotLine() - subexpressionLine;
- m_subexpressionLineStartOffset = divotLineStart() - subexpressionLineStart;
- }
- unsigned subexpressionDivot() { return divot() - m_subexpressionDivotOffset; }
- unsigned subexpressionStartOffset() { return divotStartOffset() - m_subexpressionDivotOffset; }
- unsigned subexpressionEndOffset() { return m_subexpressionEndOffset; }
- unsigned subexpressionLine() { return divotLine() - m_subexpressionLineOffset; }
- unsigned subexpressionLineStart() { return divotLineStart() - m_subexpressionLineStartOffset; }
- protected:
- uint16_t m_subexpressionDivotOffset;
- uint16_t m_subexpressionEndOffset;
- uint16_t m_subexpressionLineOffset;
- uint16_t m_subexpressionLineStartOffset;
- };
-
- class ThrowablePrefixedSubExpressionData : public ThrowableExpressionData {
- public:
- ThrowablePrefixedSubExpressionData()
- : m_subexpressionDivotOffset(0)
- , m_subexpressionStartOffset(0)
- , m_subexpressionLineOffset(0)
- , m_subexpressionLineStartOffset(0)
- {
- }
- ThrowablePrefixedSubExpressionData(unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart)
- : ThrowableExpressionData(divot, startOffset, endOffset, divotLine, divotLineStart)
- , m_subexpressionDivotOffset(0)
- , m_subexpressionStartOffset(0)
- , m_subexpressionLineOffset(0)
- , m_subexpressionLineStartOffset(0)
- {
- }
- void setSubexpressionInfo(uint32_t subexpressionDivot, uint16_t subexpressionOffset, uint32_t subexpressionLine, uint32_t subexpressionLineStart)
- {
- ASSERT(subexpressionDivot >= divot());
- // Overflow means we can't do this safely, so just point at the primary divot,
- // divotLine, or divotLineStart.
- if ((subexpressionDivot - divot()) & ~0xFFFF)
- return;
- if ((subexpressionLine - divotLine()) & ~0xFFFF)
- return;
- if ((subexpressionLineStart - divotLineStart()) & ~0xFFFF)
- return;
- m_subexpressionDivotOffset = subexpressionDivot - divot();
- m_subexpressionStartOffset = subexpressionOffset;
- m_subexpressionLineOffset = subexpressionLine - divotLine();
- m_subexpressionLineStartOffset = subexpressionLineStart - divotLineStart();
- }
- unsigned subexpressionDivot() { return divot() + m_subexpressionDivotOffset; }
- unsigned subexpressionStartOffset() { return m_subexpressionStartOffset; }
- unsigned subexpressionEndOffset() { return divotEndOffset() + m_subexpressionDivotOffset; }
- unsigned subexpressionLine() { return divotLine() + m_subexpressionLineOffset; }
- unsigned subexpressionLineStart() { return divotLineStart() + m_subexpressionLineStartOffset; }
- protected:
- uint16_t m_subexpressionDivotOffset;
- uint16_t m_subexpressionStartOffset;
- uint16_t m_subexpressionLineOffset;
- uint16_t m_subexpressionLineStartOffset;
- };
- class RegExpNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- RegExpNode(const JSTokenLocation&, const Identifier& pattern, const Identifier& flags);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_pattern;
- const Identifier& m_flags;
- };
- class ThisNode : public ExpressionNode {
- public:
- ThisNode(const JSTokenLocation&);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class ResolveNode : public ExpressionNode {
- public:
- ResolveNode(const JSTokenLocation&, const Identifier&, unsigned startOffset, unsigned divotLine, unsigned divotLineStart);
- const Identifier& identifier() const { return m_ident; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isPure(BytecodeGenerator&) const ;
- virtual bool isLocation() const { return true; }
- virtual bool isResolveNode() const { return true; }
- const Identifier& m_ident;
- uint32_t m_startOffset;
- uint32_t m_divotLine;
- uint32_t m_divotLineStart;
- };
- class ElementNode : public ParserArenaFreeable {
- public:
- ElementNode(int elision, ExpressionNode*);
- ElementNode(ElementNode*, int elision, ExpressionNode*);
- int elision() const { return m_elision; }
- ExpressionNode* value() { return m_node; }
- ElementNode* next() { return m_next; }
- private:
- ElementNode* m_next;
- int m_elision;
- ExpressionNode* m_node;
- };
- class ArrayNode : public ExpressionNode {
- public:
- ArrayNode(const JSTokenLocation&, int elision);
- ArrayNode(const JSTokenLocation&, ElementNode*);
- ArrayNode(const JSTokenLocation&, int elision, ElementNode*);
- ArgumentListNode* toArgumentList(VM*, int, int) const;
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isSimpleArray() const ;
- ElementNode* m_element;
- int m_elision;
- bool m_optional;
- };
- class PropertyNode : public ParserArenaFreeable {
- public:
- enum Type { Constant = 1, Getter = 2, Setter = 4 };
- PropertyNode(VM*, const Identifier&, ExpressionNode*, Type);
- PropertyNode(VM*, double, ExpressionNode*, Type);
- const Identifier& name() const { return m_name; }
- Type type() const { return m_type; }
- private:
- friend class PropertyListNode;
- const Identifier& m_name;
- ExpressionNode* m_assign;
- Type m_type;
- };
- class PropertyListNode : public ExpressionNode {
- public:
- PropertyListNode(const JSTokenLocation&, PropertyNode*);
- PropertyListNode(const JSTokenLocation&, PropertyNode*, PropertyListNode*);
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- private:
- PropertyNode* m_node;
- PropertyListNode* m_next;
- };
- class ObjectLiteralNode : public ExpressionNode {
- public:
- ObjectLiteralNode(const JSTokenLocation&);
- ObjectLiteralNode(const JSTokenLocation&, PropertyListNode*);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- PropertyListNode* m_list;
- };
-
- class BracketAccessorNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- BracketAccessorNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, bool subscriptHasAssignments);
- ExpressionNode* base() const { return m_base; }
- ExpressionNode* subscript() const { return m_subscript; }
- bool subscriptHasAssignments() const { return m_subscriptHasAssignments; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isLocation() const { return true; }
- virtual bool isBracketAccessorNode() const { return true; }
- ExpressionNode* m_base;
- ExpressionNode* m_subscript;
- bool m_subscriptHasAssignments;
- };
- class DotAccessorNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- DotAccessorNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&);
- ExpressionNode* base() const { return m_base; }
- const Identifier& identifier() const { return m_ident; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isLocation() const { return true; }
- virtual bool isDotAccessorNode() const { return true; }
- ExpressionNode* m_base;
- const Identifier& m_ident;
- };
- class ArgumentListNode : public ExpressionNode {
- public:
- ArgumentListNode(const JSTokenLocation&, ExpressionNode*);
- ArgumentListNode(const JSTokenLocation&, ArgumentListNode*, ExpressionNode*);
- ArgumentListNode* m_next;
- ExpressionNode* m_expr;
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class ArgumentsNode : public ParserArenaFreeable {
- public:
- ArgumentsNode();
- ArgumentsNode(ArgumentListNode*);
- ArgumentListNode* m_listNode;
- };
- class NewExprNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- NewExprNode(const JSTokenLocation&, ExpressionNode*);
- NewExprNode(const JSTokenLocation&, ExpressionNode*, ArgumentsNode*);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- ArgumentsNode* m_args;
- };
- class EvalFunctionCallNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- EvalFunctionCallNode(const JSTokenLocation&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ArgumentsNode* m_args;
- };
- class FunctionCallValueNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- FunctionCallValueNode(const JSTokenLocation&, ExpressionNode*, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- ArgumentsNode* m_args;
- };
- class FunctionCallResolveNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- FunctionCallResolveNode(const JSTokenLocation&, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- ArgumentsNode* m_args;
- };
-
- class FunctionCallBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
- public:
- FunctionCallBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- ExpressionNode* m_subscript;
- ArgumentsNode* m_args;
- };
- class FunctionCallDotNode : public ExpressionNode, public ThrowableSubExpressionData {
- public:
- FunctionCallDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- protected:
- ExpressionNode* m_base;
- const Identifier& m_ident;
- ArgumentsNode* m_args;
- };
- class CallFunctionCallDotNode : public FunctionCallDotNode {
- public:
- CallFunctionCallDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
-
- class ApplyFunctionCallDotNode : public FunctionCallDotNode {
- public:
- ApplyFunctionCallDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ArgumentsNode*, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class DeleteResolveNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- DeleteResolveNode(const JSTokenLocation&, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- };
- class DeleteBracketNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- DeleteBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- ExpressionNode* m_subscript;
- };
- class DeleteDotNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- DeleteDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- const Identifier& m_ident;
- };
- class DeleteValueNode : public ExpressionNode {
- public:
- DeleteValueNode(const JSTokenLocation&, ExpressionNode*);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
- class VoidNode : public ExpressionNode {
- public:
- VoidNode(const JSTokenLocation&, ExpressionNode*);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
- class TypeOfResolveNode : public ExpressionNode {
- public:
- TypeOfResolveNode(const JSTokenLocation&, const Identifier&);
- const Identifier& identifier() const { return m_ident; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- };
- class TypeOfValueNode : public ExpressionNode {
- public:
- TypeOfValueNode(const JSTokenLocation&, ExpressionNode*);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
- class PrefixNode : public ExpressionNode, public ThrowablePrefixedSubExpressionData {
- public:
- PrefixNode(const JSTokenLocation&, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- protected:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitResolve(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitBracket(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitDot(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- Operator m_operator;
- };
- class PostfixNode : public PrefixNode {
- public:
- PostfixNode(const JSTokenLocation&, ExpressionNode*, Operator, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitResolve(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitBracket(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitDot(BytecodeGenerator&, RegisterID* = 0);
- };
- class UnaryOpNode : public ExpressionNode {
- public:
- UnaryOpNode(const JSTokenLocation&, ResultType, ExpressionNode*, OpcodeID);
- protected:
- ExpressionNode* expr() { return m_expr; }
- const ExpressionNode* expr() const { return m_expr; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- OpcodeID opcodeID() const { return m_opcodeID; }
- ExpressionNode* m_expr;
- OpcodeID m_opcodeID;
- };
- class UnaryPlusNode : public UnaryOpNode {
- public:
- UnaryPlusNode(const JSTokenLocation&, ExpressionNode*);
- private:
- virtual ExpressionNode* stripUnaryPlus() { return expr(); }
- };
- class NegateNode : public UnaryOpNode {
- public:
- NegateNode(const JSTokenLocation&, ExpressionNode*);
- };
- class BitwiseNotNode : public ExpressionNode {
- public:
- BitwiseNotNode(const JSTokenLocation&, ExpressionNode*);
- protected:
- ExpressionNode* expr() { return m_expr; }
- const ExpressionNode* expr() const { return m_expr; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
-
- class LogicalNotNode : public UnaryOpNode {
- public:
- LogicalNotNode(const JSTokenLocation&, ExpressionNode*);
- private:
- void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode);
- };
- class BinaryOpNode : public ExpressionNode {
- public:
- BinaryOpNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
- BinaryOpNode(const JSTokenLocation&, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
- RegisterID* emitStrcat(BytecodeGenerator& generator, RegisterID* destination, RegisterID* lhs = 0, ReadModifyResolveNode* emitExpressionInfoForMe = 0);
- void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode);
- ExpressionNode* lhs() { return m_expr1; };
- ExpressionNode* rhs() { return m_expr2; };
- private:
- void tryFoldToBranch(BytecodeGenerator&, TriState& branchCondition, ExpressionNode*& branchExpression);
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- protected:
- OpcodeID opcodeID() const { return m_opcodeID; }
- protected:
- ExpressionNode* m_expr1;
- ExpressionNode* m_expr2;
- private:
- OpcodeID m_opcodeID;
- protected:
- bool m_rightHasAssignments;
- };
- class MultNode : public BinaryOpNode {
- public:
- MultNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class DivNode : public BinaryOpNode {
- public:
- DivNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class ModNode : public BinaryOpNode {
- public:
- ModNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class AddNode : public BinaryOpNode {
- public:
- AddNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- virtual bool isAdd() const { return true; }
- };
- class SubNode : public BinaryOpNode {
- public:
- SubNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- virtual bool isSubtract() const { return true; }
- };
- class LeftShiftNode : public BinaryOpNode {
- public:
- LeftShiftNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class RightShiftNode : public BinaryOpNode {
- public:
- RightShiftNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class UnsignedRightShiftNode : public BinaryOpNode {
- public:
- UnsignedRightShiftNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class LessNode : public BinaryOpNode {
- public:
- LessNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class GreaterNode : public BinaryOpNode {
- public:
- GreaterNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class LessEqNode : public BinaryOpNode {
- public:
- LessEqNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class GreaterEqNode : public BinaryOpNode {
- public:
- GreaterEqNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class ThrowableBinaryOpNode : public BinaryOpNode, public ThrowableExpressionData {
- public:
- ThrowableBinaryOpNode(const JSTokenLocation&, ResultType, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
- ThrowableBinaryOpNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, OpcodeID, bool rightHasAssignments);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
-
- class InstanceOfNode : public ThrowableBinaryOpNode {
- public:
- InstanceOfNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class InNode : public ThrowableBinaryOpNode {
- public:
- InNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class EqualNode : public BinaryOpNode {
- public:
- EqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class NotEqualNode : public BinaryOpNode {
- public:
- NotEqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class StrictEqualNode : public BinaryOpNode {
- public:
- StrictEqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class NotStrictEqualNode : public BinaryOpNode {
- public:
- NotStrictEqualNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class BitAndNode : public BinaryOpNode {
- public:
- BitAndNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class BitOrNode : public BinaryOpNode {
- public:
- BitOrNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- class BitXOrNode : public BinaryOpNode {
- public:
- BitXOrNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments);
- };
- // m_expr1 && m_expr2, m_expr1 || m_expr2
- class LogicalOpNode : public ExpressionNode {
- public:
- LogicalOpNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, LogicalOperator);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- void emitBytecodeInConditionContext(BytecodeGenerator&, Label* trueTarget, Label* falseTarget, FallThroughMode);
- ExpressionNode* m_expr1;
- ExpressionNode* m_expr2;
- LogicalOperator m_operator;
- };
- // The ternary operator, "m_logical ? m_expr1 : m_expr2"
- class ConditionalNode : public ExpressionNode {
- public:
- ConditionalNode(const JSTokenLocation&, ExpressionNode* logical, ExpressionNode* expr1, ExpressionNode* expr2);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_logical;
- ExpressionNode* m_expr1;
- ExpressionNode* m_expr2;
- };
- class ReadModifyResolveNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- ReadModifyResolveNode(const JSTokenLocation&, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned line, unsigned lineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- ExpressionNode* m_right;
- Operator m_operator;
- bool m_rightHasAssignments;
- };
- class AssignResolveNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- AssignResolveNode(const JSTokenLocation&, const Identifier&, ExpressionNode* right);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- ExpressionNode* m_right;
- };
- class ReadModifyBracketNode : public ExpressionNode, public ThrowableSubExpressionData {
- public:
- ReadModifyBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, Operator, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- ExpressionNode* m_subscript;
- ExpressionNode* m_right;
- Operator m_operator : 30;
- bool m_subscriptHasAssignments : 1;
- bool m_rightHasAssignments : 1;
- };
- class AssignBracketNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- AssignBracketNode(const JSTokenLocation&, ExpressionNode* base, ExpressionNode* subscript, ExpressionNode* right, bool subscriptHasAssignments, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- ExpressionNode* m_subscript;
- ExpressionNode* m_right;
- bool m_subscriptHasAssignments : 1;
- bool m_rightHasAssignments : 1;
- };
- class AssignDotNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- AssignDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- const Identifier& m_ident;
- ExpressionNode* m_right;
- bool m_rightHasAssignments;
- };
- class ReadModifyDotNode : public ExpressionNode, public ThrowableSubExpressionData {
- public:
- ReadModifyDotNode(const JSTokenLocation&, ExpressionNode* base, const Identifier&, Operator, ExpressionNode* right, bool rightHasAssignments, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_base;
- const Identifier& m_ident;
- ExpressionNode* m_right;
- Operator m_operator : 31;
- bool m_rightHasAssignments : 1;
- };
- class AssignErrorNode : public ExpressionNode, public ThrowableExpressionData {
- public:
- AssignErrorNode(const JSTokenLocation&, unsigned divot, unsigned startOffset, unsigned endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
-
- typedef Vector<ExpressionNode*, 8> ExpressionVector;
- class CommaNode : public ExpressionNode, public ParserArenaDeletable {
- public:
- CommaNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2);
- using ParserArenaDeletable::operator new;
- void append(ExpressionNode* expr) { m_expressions.append(expr); }
- private:
- virtual bool isCommaNode() const { return true; }
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionVector m_expressions;
- };
-
- class ConstDeclNode : public ExpressionNode {
- public:
- ConstDeclNode(const JSTokenLocation&, const Identifier&, ExpressionNode*);
- bool hasInitializer() const { return m_init; }
- const Identifier& ident() { return m_ident; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual RegisterID* emitCodeSingle(BytecodeGenerator&);
- const Identifier& m_ident;
- public:
- ConstDeclNode* m_next;
- private:
- ExpressionNode* m_init;
- };
- class ConstStatementNode : public StatementNode {
- public:
- ConstStatementNode(const JSTokenLocation&, ConstDeclNode* next);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ConstDeclNode* m_next;
- };
- class SourceElements : public ParserArenaDeletable {
- public:
- SourceElements();
- void append(StatementNode*);
- StatementNode* singleStatement() const;
- StatementNode* lastStatement() const;
- void emitBytecode(BytecodeGenerator&, RegisterID* destination);
- private:
- Vector<StatementNode*> m_statements;
- };
- class BlockNode : public StatementNode {
- public:
- BlockNode(const JSTokenLocation&, SourceElements* = 0);
- StatementNode* singleStatement() const;
- StatementNode* lastStatement() const;
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isBlock() const { return true; }
- SourceElements* m_statements;
- };
- class EmptyStatementNode : public StatementNode {
- public:
- EmptyStatementNode(const JSTokenLocation&);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isEmptyStatement() const { return true; }
- };
-
- class DebuggerStatementNode : public StatementNode {
- public:
- DebuggerStatementNode(const JSTokenLocation&);
-
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class ExprStatementNode : public StatementNode {
- public:
- ExprStatementNode(const JSTokenLocation&, ExpressionNode*);
- ExpressionNode* expr() const { return m_expr; }
- private:
- virtual bool isExprStatement() const { return true; }
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
- class VarStatementNode : public StatementNode {
- public:
- VarStatementNode(const JSTokenLocation&, ExpressionNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
- class IfElseNode : public StatementNode {
- public:
- IfElseNode(const JSTokenLocation&, ExpressionNode* condition, StatementNode* ifBlock, StatementNode* elseBlock);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- bool tryFoldBreakAndContinue(BytecodeGenerator&, StatementNode* ifBlock,
- Label*& trueTarget, FallThroughMode&);
- ExpressionNode* m_condition;
- StatementNode* m_ifBlock;
- StatementNode* m_elseBlock;
- };
- class DoWhileNode : public StatementNode {
- public:
- DoWhileNode(const JSTokenLocation&, StatementNode*, ExpressionNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- StatementNode* m_statement;
- ExpressionNode* m_expr;
- };
- class WhileNode : public StatementNode {
- public:
- WhileNode(const JSTokenLocation&, ExpressionNode*, StatementNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- StatementNode* m_statement;
- };
- class ForNode : public StatementNode {
- public:
- ForNode(const JSTokenLocation&, ExpressionNode* expr1, ExpressionNode* expr2, ExpressionNode* expr3, StatementNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr1;
- ExpressionNode* m_expr2;
- ExpressionNode* m_expr3;
- StatementNode* m_statement;
- };
- class ForInNode : public StatementNode, public ThrowableExpressionData {
- public:
- ForInNode(const JSTokenLocation&, ExpressionNode*, ExpressionNode*, StatementNode*);
- ForInNode(VM*, const JSTokenLocation&, const Identifier&, ExpressionNode*, ExpressionNode*, StatementNode*, unsigned divot, int startOffset, int endOffset, unsigned divotLine, unsigned divotLineStart);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_init;
- ExpressionNode* m_lexpr;
- ExpressionNode* m_expr;
- StatementNode* m_statement;
- };
- class ContinueNode : public StatementNode, public ThrowableExpressionData {
- public:
- ContinueNode(VM*, const JSTokenLocation&);
- ContinueNode(const JSTokenLocation&, const Identifier&);
- Label* trivialTarget(BytecodeGenerator&);
-
- private:
- virtual bool isContinue() const { return true; }
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- };
- class BreakNode : public StatementNode, public ThrowableExpressionData {
- public:
- BreakNode(VM*, const JSTokenLocation&);
- BreakNode(const JSTokenLocation&, const Identifier&);
- Label* trivialTarget(BytecodeGenerator&);
-
- private:
- virtual bool isBreak() const { return true; }
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_ident;
- };
- class ReturnNode : public StatementNode, public ThrowableExpressionData {
- public:
- ReturnNode(const JSTokenLocation&, ExpressionNode* value);
- ExpressionNode* value() { return m_value; }
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isReturnNode() const { return true; }
- ExpressionNode* m_value;
- };
- class WithNode : public StatementNode {
- public:
- WithNode(const JSTokenLocation&, ExpressionNode*, StatementNode*, uint32_t divot, unsigned divotLine, unsigned divotLineStart, uint32_t expressionLength);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- StatementNode* m_statement;
- uint32_t m_divot;
- uint32_t m_divotLine;
- uint32_t m_divotLineStart;
- uint32_t m_expressionLength;
- };
- class LabelNode : public StatementNode, public ThrowableExpressionData {
- public:
- LabelNode(const JSTokenLocation&, const Identifier& name, StatementNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- const Identifier& m_name;
- StatementNode* m_statement;
- };
- class ThrowNode : public StatementNode, public ThrowableExpressionData {
- public:
- ThrowNode(const JSTokenLocation&, ExpressionNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- };
- class TryNode : public StatementNode {
- public:
- TryNode(const JSTokenLocation&, StatementNode* tryBlock, const Identifier& exceptionIdent, StatementNode* catchBlock, StatementNode* finallyBlock);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- StatementNode* m_tryBlock;
- const Identifier& m_exceptionIdent;
- StatementNode* m_catchBlock;
- StatementNode* m_finallyBlock;
- };
- class ParameterNode : public ParserArenaFreeable {
- public:
- ParameterNode(const Identifier&);
- ParameterNode(ParameterNode*, const Identifier&);
- const Identifier& ident() const { return m_ident; }
- ParameterNode* nextParam() const { return m_next; }
- private:
- const Identifier& m_ident;
- ParameterNode* m_next;
- };
- class ScopeNode : public StatementNode, public ParserArenaRefCounted {
- public:
- typedef DeclarationStacks::VarStack VarStack;
- typedef DeclarationStacks::FunctionStack FunctionStack;
- ScopeNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, bool inStrictContext);
- ScopeNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, const SourceCode&, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, CodeFeatures, int numConstants);
- using ParserArenaRefCounted::operator new;
- void destroyData()
- {
- m_arena.reset();
- m_varStack.clear();
- m_functionStack.clear();
- m_statements = 0;
- m_capturedVariables.clear();
- }
- const SourceCode& source() const { return m_source; }
- const String& sourceURL() const { return m_source.provider()->url(); }
- intptr_t sourceID() const { return m_source.providerID(); }
- int startLine() const { return m_startLineNumber; }
- int startStartOffset() const { return m_startStartOffset; }
- int startLineStartOffset() const { return m_startLineStartOffset; }
- void setFeatures(CodeFeatures features) { m_features = features; }
- CodeFeatures features() { return m_features; }
- bool usesEval() const { return m_features & EvalFeature; }
- bool usesArguments() const { return (m_features & ArgumentsFeature) && !(m_features & ShadowsArgumentsFeature); }
- bool isStrictMode() const { return m_features & StrictModeFeature; }
- void setUsesArguments() { m_features |= ArgumentsFeature; }
- bool usesThis() const { return m_features & ThisFeature; }
- bool needsActivationForMoreThanVariables() const { return m_features & (EvalFeature | WithFeature | CatchFeature); }
- bool needsActivation() const { return (hasCapturedVariables()) || (m_features & (EvalFeature | WithFeature | CatchFeature)); }
- bool hasCapturedVariables() const { return !!m_capturedVariables.size(); }
- size_t capturedVariableCount() const { return m_capturedVariables.size(); }
- bool captures(const Identifier& ident) { return m_capturedVariables.contains(ident.impl()); }
- VarStack& varStack() { return m_varStack; }
- FunctionStack& functionStack() { return m_functionStack; }
- int neededConstants()
- {
- // We may need 2 more constants than the count given by the parser,
- // because of the various uses of jsUndefined() and jsNull().
- return m_numConstants + 2;
- }
- StatementNode* singleStatement() const;
- void emitStatementsBytecode(BytecodeGenerator&, RegisterID* destination);
- protected:
- void setSource(const SourceCode& source) { m_source = source; }
- ParserArena m_arena;
- int m_startLineNumber;
- unsigned m_startStartOffset;
- unsigned m_startLineStartOffset;
- private:
- CodeFeatures m_features;
- SourceCode m_source;
- VarStack m_varStack;
- FunctionStack m_functionStack;
- int m_numConstants;
- SourceElements* m_statements;
- IdentifierSet m_capturedVariables;
- };
- class ProgramNode : public ScopeNode {
- public:
- static const bool isFunctionNode = false;
- static PassRefPtr<ProgramNode> create(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
- unsigned startColumn() { return m_startColumn; }
- static const bool scopeIsFunction = false;
- private:
- ProgramNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- unsigned m_startColumn;
- };
- class EvalNode : public ScopeNode {
- public:
- static const bool isFunctionNode = false;
- static PassRefPtr<EvalNode> create(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
- unsigned startColumn() { return 1; }
- static const bool scopeIsFunction = false;
- private:
- EvalNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- };
- class FunctionParameters : public RefCounted<FunctionParameters> {
- WTF_MAKE_FAST_ALLOCATED;
- public:
- static PassRefPtr<FunctionParameters> create(ParameterNode*);
- ~FunctionParameters();
- unsigned size() const { return m_size; }
- const Identifier& at(unsigned index) const { ASSERT(index < m_size); return identifiers()[index]; }
- private:
- FunctionParameters(ParameterNode*, unsigned size);
- Identifier* identifiers() { return reinterpret_cast<Identifier*>(&m_storage); }
- const Identifier* identifiers() const { return reinterpret_cast<const Identifier*>(&m_storage); }
- unsigned m_size;
- void* m_storage;
- };
- class FunctionBodyNode : public ScopeNode {
- public:
- static const bool isFunctionNode = true;
- static FunctionBodyNode* create(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, bool isStrictMode);
- static PassRefPtr<FunctionBodyNode> create(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
- FunctionParameters* parameters() const { return m_parameters.get(); }
- size_t parameterCount() const { return m_parameters->size(); }
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- void finishParsing(const SourceCode&, ParameterNode*, const Identifier&, FunctionNameIsInScopeToggle);
- void finishParsing(PassRefPtr<FunctionParameters>, const Identifier&, FunctionNameIsInScopeToggle);
-
- const Identifier& ident() { return m_ident; }
- void setInferredName(const Identifier& inferredName) { ASSERT(!inferredName.isNull()); m_inferredName = inferredName; }
- const Identifier& inferredName() { return m_inferredName.isEmpty() ? m_ident : m_inferredName; }
- bool functionNameIsInScope() { return m_functionNameIsInScopeToggle == FunctionNameIsInScope; }
- FunctionNameIsInScopeToggle functionNameIsInScopeToggle() { return m_functionNameIsInScopeToggle; }
- void setFunctionStart(int functionStart) { m_functionStart = functionStart; }
- int functionStart() const { return m_functionStart; }
- unsigned startColumn() const { return m_startColumn; }
- static const bool scopeIsFunction = true;
- private:
- FunctionBodyNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, bool inStrictContext);
- FunctionBodyNode(VM*, const JSTokenLocation& start, const JSTokenLocation& end, unsigned startColumn, SourceElements*, VarStack*, FunctionStack*, IdentifierSet&, const SourceCode&, CodeFeatures, int numConstants);
- Identifier m_ident;
- Identifier m_inferredName;
- FunctionNameIsInScopeToggle m_functionNameIsInScopeToggle;
- RefPtr<FunctionParameters> m_parameters;
- int m_functionStart;
- unsigned m_startColumn;
- };
- class FuncExprNode : public ExpressionNode {
- public:
- FuncExprNode(const JSTokenLocation&, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
- FunctionBodyNode* body() { return m_body; }
- private:
- virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- virtual bool isFuncExprNode() const { return true; }
- FunctionBodyNode* m_body;
- };
- class FuncDeclNode : public StatementNode {
- public:
- FuncDeclNode(const JSTokenLocation&, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0);
- FunctionBodyNode* body() { return m_body; }
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- FunctionBodyNode* m_body;
- };
- class CaseClauseNode : public ParserArenaFreeable {
- public:
- CaseClauseNode(ExpressionNode*, SourceElements* = 0);
- ExpressionNode* expr() const { return m_expr; }
- void emitBytecode(BytecodeGenerator&, RegisterID* destination);
- private:
- ExpressionNode* m_expr;
- SourceElements* m_statements;
- };
- class ClauseListNode : public ParserArenaFreeable {
- public:
- ClauseListNode(CaseClauseNode*);
- ClauseListNode(ClauseListNode*, CaseClauseNode*);
- CaseClauseNode* getClause() const { return m_clause; }
- ClauseListNode* getNext() const { return m_next; }
- private:
- CaseClauseNode* m_clause;
- ClauseListNode* m_next;
- };
- class CaseBlockNode : public ParserArenaFreeable {
- public:
- CaseBlockNode(ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2);
- void emitBytecodeForBlock(BytecodeGenerator&, RegisterID* input, RegisterID* destination);
- private:
- SwitchInfo::SwitchType tryTableSwitch(Vector<ExpressionNode*, 8>& literalVector, int32_t& min_num, int32_t& max_num);
- static const size_t s_tableSwitchMinimum = 10;
- ClauseListNode* m_list1;
- CaseClauseNode* m_defaultClause;
- ClauseListNode* m_list2;
- };
- class SwitchNode : public StatementNode {
- public:
- SwitchNode(const JSTokenLocation&, ExpressionNode*, CaseBlockNode*);
- private:
- virtual void emitBytecode(BytecodeGenerator&, RegisterID* = 0);
- ExpressionNode* m_expr;
- CaseBlockNode* m_block;
- };
- struct ElementList {
- ElementNode* head;
- ElementNode* tail;
- };
- struct PropertyList {
- PropertyListNode* head;
- PropertyListNode* tail;
- };
- struct ArgumentList {
- ArgumentListNode* head;
- ArgumentListNode* tail;
- };
- struct ConstDeclList {
- ConstDeclNode* head;
- ConstDeclNode* tail;
- };
- struct ParameterList {
- ParameterNode* head;
- ParameterNode* tail;
- };
- struct ClauseList {
- ClauseListNode* head;
- ClauseListNode* tail;
- };
- } // namespace JSC
- #endif // Nodes_h
|