Changeset 26682 in webkit for trunk/JavaScriptCore/kjs/nodes.h
- Timestamp:
- Oct 16, 2007, 2:35:50 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes.h
r26582 r26682 45 45 namespace KJS { 46 46 47 class FuncDeclNode; 47 48 class ProgramNode; 48 49 class PropertyNameNode; … … 51 52 class SourceElementsNode; 52 53 class SourceStream; 54 class VarDeclNode; 53 55 54 56 enum Operator { OpEqual, … … 82 84 OpInstanceOf 83 85 }; 86 87 struct DeclarationStacks { 88 typedef Vector<Node*, 16> NodeStack; 89 typedef Vector<VarDeclNode*, 16> VarStack; 90 typedef Vector<FuncDeclNode*, 16> FunctionStack; 91 92 NodeStack nodeStack; 93 VarStack varStack; 94 FunctionStack functionStack; 95 }; 84 96 85 97 class Node { … … 91 103 UString toString() const KJS_FAST_CALL; 92 104 virtual void streamTo(SourceStream&) const KJS_FAST_CALL = 0; 93 virtual void processVarDecls(ExecState*) KJS_FAST_CALL {}94 105 int lineNo() const KJS_FAST_CALL { return m_line; } 95 96 106 void ref() KJS_FAST_CALL; 97 107 void deref() KJS_FAST_CALL; … … 107 117 virtual bool isDotAccessorNode() const KJS_FAST_CALL { return false; } 108 118 virtual bool isGroupNode() const KJS_FAST_CALL { return false; } 119 120 // Used for iterative, depth-first traversal of the node tree. Does not cross function call boundaries. 121 bool mayHaveDeclarations() { return m_mayHaveDeclarations; } 122 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL { ASSERT_NOT_REACHED(); } 109 123 110 124 virtual void breakCycle() KJS_FAST_CALL { } … … 127 141 void handleException(ExecState*, JSValue*) KJS_FAST_CALL; 128 142 129 int m_line; 143 int m_line : 31; 144 bool m_mayHaveDeclarations : 1; 130 145 private: 131 146 // disallow assignment … … 143 158 virtual Completion execute(ExecState *exec) KJS_FAST_CALL = 0; 144 159 void pushLabel(const Identifier &id) KJS_FAST_CALL { ls.push(id); } 145 virtual void processFuncDecl(ExecState*) KJS_FAST_CALL;146 160 protected: 147 161 LabelStack ls; … … 800 814 VarDeclNode(const Identifier &id, AssignExprNode *in, Type t) KJS_FAST_CALL; 801 815 JSValue* evaluate(ExecState*) KJS_FAST_CALL; 802 virtual void processVarDecls(ExecState*) KJS_FAST_CALL; 803 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 816 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 817 void ALWAYS_INLINE processDeclaration(ExecState*) KJS_FAST_CALL; 818 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 804 819 private: 805 820 JSValue* handleSlowCase(ExecState*, const ScopeChain&, JSValue*) KJS_FAST_CALL KJS_NO_INLINE; … … 812 827 public: 813 828 // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor 814 VarDeclListNode(VarDeclNode *v) KJS_FAST_CALL : next(this), var(v) { Parser::noteNodeCycle(this); }829 VarDeclListNode(VarDeclNode *v) KJS_FAST_CALL : next(this), var(v) { Parser::noteNodeCycle(this); m_mayHaveDeclarations = true; } 815 830 VarDeclListNode(VarDeclListNode *l, VarDeclNode *v) KJS_FAST_CALL 816 : next(l->next), var(v) { l->next = this; } 817 JSValue* evaluate(ExecState*) KJS_FAST_CALL; 818 virtual void processVarDecls(ExecState*) KJS_FAST_CALL; 831 : next(l->next), var(v) { l->next = this; m_mayHaveDeclarations = true; } 832 JSValue* evaluate(ExecState*) KJS_FAST_CALL; 819 833 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 820 834 PassRefPtr<VarDeclListNode> releaseNext() KJS_FAST_CALL { return next.release(); } 821 835 virtual void breakCycle() KJS_FAST_CALL; 836 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 822 837 private: 823 838 friend class ForNode; … … 829 844 class VarStatementNode : public StatementNode { 830 845 public: 831 VarStatementNode(VarDeclListNode *l) KJS_FAST_CALL : next(l->next.release()) { Parser::removeNodeCycle(next.get()); }832 virtual Completion execute(ExecState*) KJS_FAST_CALL; 833 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;834 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;846 VarStatementNode(VarDeclListNode *l) KJS_FAST_CALL : next(l->next.release()) { Parser::removeNodeCycle(next.get()); m_mayHaveDeclarations = true; } 847 virtual Completion execute(ExecState*) KJS_FAST_CALL; 848 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 849 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 835 850 private: 836 851 RefPtr<VarDeclListNode> next; … … 841 856 BlockNode(SourceElementsNode *s) KJS_FAST_CALL; 842 857 virtual Completion execute(ExecState*) KJS_FAST_CALL; 843 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;844 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;858 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 859 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 845 860 protected: 846 861 RefPtr<SourceElementsNode> source; … … 866 881 public: 867 882 IfNode(Node *e, StatementNode *s1, StatementNode *s2) KJS_FAST_CALL 868 : expr(e), statement1(s1), statement2(s2) { }869 virtual Completion execute(ExecState*) KJS_FAST_CALL; 870 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;871 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;883 : expr(e), statement1(s1), statement2(s2) { m_mayHaveDeclarations = statement1->mayHaveDeclarations() || (statement2 && statement2->mayHaveDeclarations()); } 884 virtual Completion execute(ExecState*) KJS_FAST_CALL; 885 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 886 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 872 887 private: 873 888 RefPtr<Node> expr; … … 878 893 class DoWhileNode : public StatementNode { 879 894 public: 880 DoWhileNode(StatementNode *s, Node *e) KJS_FAST_CALL : statement(s), expr(e) { }881 virtual Completion execute(ExecState*) KJS_FAST_CALL; 882 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;883 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;895 DoWhileNode(StatementNode *s, Node *e) KJS_FAST_CALL : statement(s), expr(e) { m_mayHaveDeclarations = true; } 896 virtual Completion execute(ExecState*) KJS_FAST_CALL; 897 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 898 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 884 899 private: 885 900 RefPtr<StatementNode> statement; … … 889 904 class WhileNode : public StatementNode { 890 905 public: 891 WhileNode(Node *e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { }892 virtual Completion execute(ExecState*) KJS_FAST_CALL; 893 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;894 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;906 WhileNode(Node *e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { m_mayHaveDeclarations = true; } 907 virtual Completion execute(ExecState*) KJS_FAST_CALL; 908 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 909 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 895 910 private: 896 911 RefPtr<Node> expr; … … 901 916 public: 902 917 ForNode(Node *e1, Node *e2, Node *e3, StatementNode *s) KJS_FAST_CALL : 903 expr1(e1), expr2(e2), expr3(e3), statement(s) { }918 expr1(e1), expr2(e2), expr3(e3), statement(s) { m_mayHaveDeclarations = true; } 904 919 ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) KJS_FAST_CALL : 905 expr1(e1->next.release()), expr2(e2), expr3(e3), statement(s) { Parser::removeNodeCycle(expr1.get()); }906 virtual Completion execute(ExecState*) KJS_FAST_CALL; 907 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;908 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;920 expr1(e1->next.release()), expr2(e2), expr3(e3), statement(s) { Parser::removeNodeCycle(expr1.get()); m_mayHaveDeclarations = true; } 921 virtual Completion execute(ExecState*) KJS_FAST_CALL; 922 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 923 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 909 924 private: 910 925 RefPtr<Node> expr1; … … 919 934 ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s) KJS_FAST_CALL; 920 935 virtual Completion execute(ExecState*) KJS_FAST_CALL; 921 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;922 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;936 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 937 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 923 938 private: 924 939 Identifier ident; … … 961 976 class WithNode : public StatementNode { 962 977 public: 963 WithNode(Node *e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { }964 virtual Completion execute(ExecState*) KJS_FAST_CALL; 965 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;966 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;978 WithNode(Node *e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { m_mayHaveDeclarations = true; } 979 virtual Completion execute(ExecState*) KJS_FAST_CALL; 980 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 981 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 967 982 private: 968 983 RefPtr<Node> expr; … … 972 987 class LabelNode : public StatementNode { 973 988 public: 974 LabelNode(const Identifier &l, StatementNode *s) KJS_FAST_CALL : label(l), statement(s) { }975 virtual Completion execute(ExecState*) KJS_FAST_CALL; 976 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;977 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;989 LabelNode(const Identifier &l, StatementNode *s) KJS_FAST_CALL : label(l), statement(s) { m_mayHaveDeclarations = true; } 990 virtual Completion execute(ExecState*) KJS_FAST_CALL; 991 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 992 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 978 993 private: 979 994 Identifier label; … … 993 1008 public: 994 1009 TryNode(StatementNode *b, const Identifier &e, StatementNode *c, StatementNode *f) KJS_FAST_CALL 995 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { }996 virtual Completion execute(ExecState*) KJS_FAST_CALL; 997 virtual void processVarDecls(ExecState*)KJS_FAST_CALL;998 virtual void streamTo(SourceStream&) constKJS_FAST_CALL;1010 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { m_mayHaveDeclarations = true; } 1011 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1012 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1013 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 999 1014 private: 1000 1015 RefPtr<StatementNode> tryBlock; … … 1034 1049 public: 1035 1050 FunctionBodyNode(SourceElementsNode *) KJS_FAST_CALL; 1036 virtual void processFuncDecl(ExecState*) KJS_FAST_CALL;1037 1051 int sourceId() KJS_FAST_CALL { return m_sourceId; } 1038 1052 const UString& sourceURL() KJS_FAST_CALL { return m_sourceURL; } … … 1043 1057 UString paramString() const KJS_FAST_CALL; 1044 1058 Vector<Parameter>& parameters() KJS_FAST_CALL { return m_parameters; } 1059 void processDeclarations(ExecState*) KJS_FAST_CALL; 1045 1060 private: 1046 1061 UString m_sourceURL; … … 1067 1082 public: 1068 1083 FuncDeclNode(const Identifier &i, FunctionBodyNode *b) KJS_FAST_CALL 1069 : ident(i), body(b) { addParams(); }1084 : ident(i), body(b) { addParams(); m_mayHaveDeclarations = true; } 1070 1085 FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b) KJS_FAST_CALL 1071 : ident(i), param(p->next.release()), body(b) { Parser::removeNodeCycle(param.get()); addParams(); } 1072 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1073 virtual void processFuncDecl(ExecState*) KJS_FAST_CALL; 1074 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1086 : ident(i), param(p->next.release()), body(b) { Parser::removeNodeCycle(param.get()); addParams(); m_mayHaveDeclarations = true; } 1087 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1088 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1089 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 1090 void ALWAYS_INLINE processDeclaration(ExecState*) KJS_FAST_CALL; 1075 1091 private: 1076 1092 void addParams() KJS_FAST_CALL; … … 1089 1105 1090 1106 Completion execute(ExecState*) KJS_FAST_CALL; 1091 void processFuncDecl(ExecState*) KJS_FAST_CALL;1092 virtual void processVarDecls(ExecState*) KJS_FAST_CALL;1093 1107 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1094 1108 PassRefPtr<SourceElementsNode> releaseNext() KJS_FAST_CALL { return next.release(); } 1095 1109 virtual void breakCycle() KJS_FAST_CALL; 1110 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 1096 1111 private: 1097 1112 friend class BlockNode; … … 1103 1118 class CaseClauseNode : public Node { 1104 1119 public: 1105 CaseClauseNode(Node *e) KJS_FAST_CALL : expr(e) { }1120 CaseClauseNode(Node *e) KJS_FAST_CALL : expr(e) { m_mayHaveDeclarations = true; } 1106 1121 CaseClauseNode(Node *e, SourceElementsNode *s) KJS_FAST_CALL 1107 : expr(e), source(s->next.release()) { Parser::removeNodeCycle(source.get()); }1122 : expr(e), source(s->next.release()) { Parser::removeNodeCycle(source.get()); m_mayHaveDeclarations = true; } 1108 1123 JSValue* evaluate(ExecState*) KJS_FAST_CALL; 1109 1124 Completion evalStatements(ExecState*) KJS_FAST_CALL; 1110 void processFuncDecl(ExecState*) KJS_FAST_CALL;1111 virtual void processVarDecls(ExecState*) KJS_FAST_CALL;1112 1125 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1126 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 1113 1127 private: 1114 1128 RefPtr<Node> expr; … … 1119 1133 public: 1120 1134 // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor 1121 ClauseListNode(CaseClauseNode *c) KJS_FAST_CALL : clause(c), next(this) { Parser::noteNodeCycle(this); }1135 ClauseListNode(CaseClauseNode *c) KJS_FAST_CALL : clause(c), next(this) { Parser::noteNodeCycle(this); m_mayHaveDeclarations = true; } 1122 1136 ClauseListNode(ClauseListNode *n, CaseClauseNode *c) KJS_FAST_CALL 1123 : clause(c), next(n->next) { n->next = this; }1137 : clause(c), next(n->next) { n->next = this; m_mayHaveDeclarations = true; } 1124 1138 JSValue* evaluate(ExecState*) KJS_FAST_CALL; 1125 1139 CaseClauseNode *getClause() const KJS_FAST_CALL { return clause.get(); } 1126 1140 ClauseListNode *getNext() const KJS_FAST_CALL { return next.get(); } 1127 virtual void processVarDecls(ExecState*) KJS_FAST_CALL;1128 void processFuncDecl(ExecState*) KJS_FAST_CALL;1129 1141 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1130 1142 PassRefPtr<ClauseListNode> releaseNext() KJS_FAST_CALL { return next.release(); } 1131 1143 virtual void breakCycle() KJS_FAST_CALL; 1144 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 1132 1145 private: 1133 1146 friend class CaseBlockNode; … … 1141 1154 JSValue* evaluate(ExecState*) KJS_FAST_CALL; 1142 1155 Completion evalBlock(ExecState *exec, JSValue *input) KJS_FAST_CALL; 1143 virtual void processVarDecls(ExecState*) KJS_FAST_CALL;1144 void processFuncDecl(ExecState*) KJS_FAST_CALL;1145 1156 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1157 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 1146 1158 private: 1147 1159 RefPtr<ClauseListNode> list1; … … 1152 1164 class SwitchNode : public StatementNode { 1153 1165 public: 1154 SwitchNode(Node *e, CaseBlockNode *b) KJS_FAST_CALL : expr(e), block(b) { }1166 SwitchNode(Node *e, CaseBlockNode *b) KJS_FAST_CALL : expr(e), block(b) { m_mayHaveDeclarations = true; } 1155 1167 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1156 virtual void processVarDecls(ExecState*) KJS_FAST_CALL;1157 virtual void processFuncDecl(ExecState*) KJS_FAST_CALL;1158 1168 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1169 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL; 1159 1170 private: 1160 1171 RefPtr<Node> expr;
Note:
See TracChangeset
for help on using the changeset viewer.