| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 // True if the expression does not have (evaluated) subexpressions. | 214 // True if the expression does not have (evaluated) subexpressions. |
| 215 // Function literals are leaves because their subexpressions are not | 215 // Function literals are leaves because their subexpressions are not |
| 216 // evaluated. | 216 // evaluated. |
| 217 virtual bool IsLeaf() { return false; } | 217 virtual bool IsLeaf() { return false; } |
| 218 | 218 |
| 219 // True if the expression has no side effects and is safe to | 219 // True if the expression has no side effects and is safe to |
| 220 // evaluate out of order. | 220 // evaluate out of order. |
| 221 virtual bool IsTrivial() { return false; } | 221 virtual bool IsTrivial() { return false; } |
| 222 | 222 |
| 223 // True if the expression always has one of the non-Object JS types |
| 224 // (Undefined, Null, Boolean, String, or Number). |
| 225 virtual bool IsPrimitive() = 0; |
| 226 |
| 223 // Mark the expression as being compiled as an expression | 227 // Mark the expression as being compiled as an expression |
| 224 // statement. This is used to transform postfix increments to | 228 // statement. This is used to transform postfix increments to |
| 225 // (faster) prefix increments. | 229 // (faster) prefix increments. |
| 226 virtual void MarkAsStatement() { /* do nothing */ } | 230 virtual void MarkAsStatement() { /* do nothing */ } |
| 227 | 231 |
| 228 // Static type information for this expression. | 232 // Static type information for this expression. |
| 229 StaticType* type() { return &type_; } | 233 StaticType* type() { return &type_; } |
| 230 | 234 |
| 231 // Data flow information. | 235 // Data flow information. |
| 232 DefinitionInfo* var_def() { return def_; } | 236 DefinitionInfo* var_def() { return def_; } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 /** | 277 /** |
| 274 * A sentinel used during pre parsing that represents some expression | 278 * A sentinel used during pre parsing that represents some expression |
| 275 * that is a valid left hand side without having to actually build | 279 * that is a valid left hand side without having to actually build |
| 276 * the expression. | 280 * the expression. |
| 277 */ | 281 */ |
| 278 class ValidLeftHandSideSentinel: public Expression { | 282 class ValidLeftHandSideSentinel: public Expression { |
| 279 public: | 283 public: |
| 280 virtual bool IsValidLeftHandSide() { return true; } | 284 virtual bool IsValidLeftHandSide() { return true; } |
| 281 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } | 285 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
| 282 static ValidLeftHandSideSentinel* instance() { return &instance_; } | 286 static ValidLeftHandSideSentinel* instance() { return &instance_; } |
| 287 |
| 288 virtual bool IsPrimitive() { UNREACHABLE(); return false; } |
| 289 |
| 283 private: | 290 private: |
| 284 static ValidLeftHandSideSentinel instance_; | 291 static ValidLeftHandSideSentinel instance_; |
| 285 }; | 292 }; |
| 286 | 293 |
| 287 | 294 |
| 288 class BreakableStatement: public Statement { | 295 class BreakableStatement: public Statement { |
| 289 public: | 296 public: |
| 290 enum Type { | 297 enum Type { |
| 291 TARGET_FOR_ANONYMOUS, | 298 TARGET_FOR_ANONYMOUS, |
| 292 TARGET_FOR_NAMED_ONLY | 299 TARGET_FOR_NAMED_ONLY |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 virtual bool IsPropertyName() { | 798 virtual bool IsPropertyName() { |
| 792 if (handle_->IsSymbol()) { | 799 if (handle_->IsSymbol()) { |
| 793 uint32_t ignored; | 800 uint32_t ignored; |
| 794 return !String::cast(*handle_)->AsArrayIndex(&ignored); | 801 return !String::cast(*handle_)->AsArrayIndex(&ignored); |
| 795 } | 802 } |
| 796 return false; | 803 return false; |
| 797 } | 804 } |
| 798 | 805 |
| 799 virtual bool IsLeaf() { return true; } | 806 virtual bool IsLeaf() { return true; } |
| 800 virtual bool IsTrivial() { return true; } | 807 virtual bool IsTrivial() { return true; } |
| 808 virtual bool IsPrimitive(); |
| 801 | 809 |
| 802 // Identity testers. | 810 // Identity testers. |
| 803 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } | 811 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } |
| 804 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } | 812 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } |
| 805 bool IsFalse() const { | 813 bool IsFalse() const { |
| 806 return handle_.is_identical_to(Factory::false_value()); | 814 return handle_.is_identical_to(Factory::false_value()); |
| 807 } | 815 } |
| 808 | 816 |
| 809 Handle<Object> handle() const { return handle_; } | 817 Handle<Object> handle() const { return handle_; } |
| 810 | 818 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 : MaterializedLiteral(literal_index, is_simple, depth), | 886 : MaterializedLiteral(literal_index, is_simple, depth), |
| 879 constant_properties_(constant_properties), | 887 constant_properties_(constant_properties), |
| 880 properties_(properties), | 888 properties_(properties), |
| 881 fast_elements_(fast_elements) {} | 889 fast_elements_(fast_elements) {} |
| 882 | 890 |
| 883 virtual ObjectLiteral* AsObjectLiteral() { return this; } | 891 virtual ObjectLiteral* AsObjectLiteral() { return this; } |
| 884 virtual void Accept(AstVisitor* v); | 892 virtual void Accept(AstVisitor* v); |
| 885 | 893 |
| 886 virtual bool IsLeaf() { return properties()->is_empty(); } | 894 virtual bool IsLeaf() { return properties()->is_empty(); } |
| 887 | 895 |
| 896 virtual bool IsPrimitive(); |
| 897 |
| 888 Handle<FixedArray> constant_properties() const { | 898 Handle<FixedArray> constant_properties() const { |
| 889 return constant_properties_; | 899 return constant_properties_; |
| 890 } | 900 } |
| 891 ZoneList<Property*>* properties() const { return properties_; } | 901 ZoneList<Property*>* properties() const { return properties_; } |
| 892 | 902 |
| 893 bool fast_elements() const { return fast_elements_; } | 903 bool fast_elements() const { return fast_elements_; } |
| 894 | 904 |
| 895 private: | 905 private: |
| 896 Handle<FixedArray> constant_properties_; | 906 Handle<FixedArray> constant_properties_; |
| 897 ZoneList<Property*>* properties_; | 907 ZoneList<Property*>* properties_; |
| 898 bool fast_elements_; | 908 bool fast_elements_; |
| 899 }; | 909 }; |
| 900 | 910 |
| 901 | 911 |
| 902 // Node for capturing a regexp literal. | 912 // Node for capturing a regexp literal. |
| 903 class RegExpLiteral: public MaterializedLiteral { | 913 class RegExpLiteral: public MaterializedLiteral { |
| 904 public: | 914 public: |
| 905 RegExpLiteral(Handle<String> pattern, | 915 RegExpLiteral(Handle<String> pattern, |
| 906 Handle<String> flags, | 916 Handle<String> flags, |
| 907 int literal_index) | 917 int literal_index) |
| 908 : MaterializedLiteral(literal_index, false, 1), | 918 : MaterializedLiteral(literal_index, false, 1), |
| 909 pattern_(pattern), | 919 pattern_(pattern), |
| 910 flags_(flags) {} | 920 flags_(flags) {} |
| 911 | 921 |
| 912 virtual void Accept(AstVisitor* v); | 922 virtual void Accept(AstVisitor* v); |
| 913 | 923 |
| 914 virtual bool IsLeaf() { return true; } | 924 virtual bool IsLeaf() { return true; } |
| 915 | 925 |
| 926 virtual bool IsPrimitive(); |
| 927 |
| 916 Handle<String> pattern() const { return pattern_; } | 928 Handle<String> pattern() const { return pattern_; } |
| 917 Handle<String> flags() const { return flags_; } | 929 Handle<String> flags() const { return flags_; } |
| 918 | 930 |
| 919 private: | 931 private: |
| 920 Handle<String> pattern_; | 932 Handle<String> pattern_; |
| 921 Handle<String> flags_; | 933 Handle<String> flags_; |
| 922 }; | 934 }; |
| 923 | 935 |
| 924 // An array literal has a literals object that is used | 936 // An array literal has a literals object that is used |
| 925 // for minimizing the work when constructing it at runtime. | 937 // for minimizing the work when constructing it at runtime. |
| 926 class ArrayLiteral: public MaterializedLiteral { | 938 class ArrayLiteral: public MaterializedLiteral { |
| 927 public: | 939 public: |
| 928 ArrayLiteral(Handle<FixedArray> constant_elements, | 940 ArrayLiteral(Handle<FixedArray> constant_elements, |
| 929 ZoneList<Expression*>* values, | 941 ZoneList<Expression*>* values, |
| 930 int literal_index, | 942 int literal_index, |
| 931 bool is_simple, | 943 bool is_simple, |
| 932 int depth) | 944 int depth) |
| 933 : MaterializedLiteral(literal_index, is_simple, depth), | 945 : MaterializedLiteral(literal_index, is_simple, depth), |
| 934 constant_elements_(constant_elements), | 946 constant_elements_(constant_elements), |
| 935 values_(values) {} | 947 values_(values) {} |
| 936 | 948 |
| 937 virtual void Accept(AstVisitor* v); | 949 virtual void Accept(AstVisitor* v); |
| 938 virtual ArrayLiteral* AsArrayLiteral() { return this; } | 950 virtual ArrayLiteral* AsArrayLiteral() { return this; } |
| 939 | 951 |
| 940 virtual bool IsLeaf() { return values()->is_empty(); } | 952 virtual bool IsLeaf() { return values()->is_empty(); } |
| 941 | 953 |
| 954 virtual bool IsPrimitive(); |
| 955 |
| 942 Handle<FixedArray> constant_elements() const { return constant_elements_; } | 956 Handle<FixedArray> constant_elements() const { return constant_elements_; } |
| 943 ZoneList<Expression*>* values() const { return values_; } | 957 ZoneList<Expression*>* values() const { return values_; } |
| 944 | 958 |
| 945 private: | 959 private: |
| 946 Handle<FixedArray> constant_elements_; | 960 Handle<FixedArray> constant_elements_; |
| 947 ZoneList<Expression*>* values_; | 961 ZoneList<Expression*>* values_; |
| 948 }; | 962 }; |
| 949 | 963 |
| 950 | 964 |
| 951 // Node for constructing a context extension object for a catch block. | 965 // Node for constructing a context extension object for a catch block. |
| 952 // The catch context extension object has one property, the catch | 966 // The catch context extension object has one property, the catch |
| 953 // variable, which should be DontDelete. | 967 // variable, which should be DontDelete. |
| 954 class CatchExtensionObject: public Expression { | 968 class CatchExtensionObject: public Expression { |
| 955 public: | 969 public: |
| 956 CatchExtensionObject(Literal* key, VariableProxy* value) | 970 CatchExtensionObject(Literal* key, VariableProxy* value) |
| 957 : key_(key), value_(value) { | 971 : key_(key), value_(value) { |
| 958 } | 972 } |
| 959 | 973 |
| 960 virtual void Accept(AstVisitor* v); | 974 virtual void Accept(AstVisitor* v); |
| 961 | 975 |
| 976 virtual bool IsPrimitive(); |
| 977 |
| 962 Literal* key() const { return key_; } | 978 Literal* key() const { return key_; } |
| 963 VariableProxy* value() const { return value_; } | 979 VariableProxy* value() const { return value_; } |
| 964 | 980 |
| 965 private: | 981 private: |
| 966 Literal* key_; | 982 Literal* key_; |
| 967 VariableProxy* value_; | 983 VariableProxy* value_; |
| 968 }; | 984 }; |
| 969 | 985 |
| 970 | 986 |
| 971 class VariableProxy: public Expression { | 987 class VariableProxy: public Expression { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 988 | 1004 |
| 989 virtual bool IsLeaf() { | 1005 virtual bool IsLeaf() { |
| 990 ASSERT(var_ != NULL); // Variable must be resolved. | 1006 ASSERT(var_ != NULL); // Variable must be resolved. |
| 991 return var()->is_global() || var()->rewrite()->IsLeaf(); | 1007 return var()->is_global() || var()->rewrite()->IsLeaf(); |
| 992 } | 1008 } |
| 993 | 1009 |
| 994 // Reading from a mutable variable is a side effect, but 'this' is | 1010 // Reading from a mutable variable is a side effect, but 'this' is |
| 995 // immutable. | 1011 // immutable. |
| 996 virtual bool IsTrivial() { return is_trivial_; } | 1012 virtual bool IsTrivial() { return is_trivial_; } |
| 997 | 1013 |
| 1014 virtual bool IsPrimitive(); |
| 1015 |
| 998 bool IsVariable(Handle<String> n) { | 1016 bool IsVariable(Handle<String> n) { |
| 999 return !is_this() && name().is_identical_to(n); | 1017 return !is_this() && name().is_identical_to(n); |
| 1000 } | 1018 } |
| 1001 | 1019 |
| 1002 bool IsArguments() { | 1020 bool IsArguments() { |
| 1003 Variable* variable = AsVariable(); | 1021 Variable* variable = AsVariable(); |
| 1004 return (variable == NULL) ? false : variable->is_arguments(); | 1022 return (variable == NULL) ? false : variable->is_arguments(); |
| 1005 } | 1023 } |
| 1006 | 1024 |
| 1007 Handle<String> name() const { return name_; } | 1025 Handle<String> name() const { return name_; } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1029 | 1047 |
| 1030 | 1048 |
| 1031 class VariableProxySentinel: public VariableProxy { | 1049 class VariableProxySentinel: public VariableProxy { |
| 1032 public: | 1050 public: |
| 1033 virtual bool IsValidLeftHandSide() { return !is_this(); } | 1051 virtual bool IsValidLeftHandSide() { return !is_this(); } |
| 1034 static VariableProxySentinel* this_proxy() { return &this_proxy_; } | 1052 static VariableProxySentinel* this_proxy() { return &this_proxy_; } |
| 1035 static VariableProxySentinel* identifier_proxy() { | 1053 static VariableProxySentinel* identifier_proxy() { |
| 1036 return &identifier_proxy_; | 1054 return &identifier_proxy_; |
| 1037 } | 1055 } |
| 1038 | 1056 |
| 1057 virtual bool IsPrimitive() { UNREACHABLE(); return false; } |
| 1058 |
| 1039 private: | 1059 private: |
| 1040 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { } | 1060 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { } |
| 1041 static VariableProxySentinel this_proxy_; | 1061 static VariableProxySentinel this_proxy_; |
| 1042 static VariableProxySentinel identifier_proxy_; | 1062 static VariableProxySentinel identifier_proxy_; |
| 1043 }; | 1063 }; |
| 1044 | 1064 |
| 1045 | 1065 |
| 1046 class Slot: public Expression { | 1066 class Slot: public Expression { |
| 1047 public: | 1067 public: |
| 1048 enum Type { | 1068 enum Type { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1072 ASSERT(var != NULL); | 1092 ASSERT(var != NULL); |
| 1073 } | 1093 } |
| 1074 | 1094 |
| 1075 virtual void Accept(AstVisitor* v); | 1095 virtual void Accept(AstVisitor* v); |
| 1076 | 1096 |
| 1077 // Type testing & conversion | 1097 // Type testing & conversion |
| 1078 virtual Slot* AsSlot() { return this; } | 1098 virtual Slot* AsSlot() { return this; } |
| 1079 | 1099 |
| 1080 virtual bool IsLeaf() { return true; } | 1100 virtual bool IsLeaf() { return true; } |
| 1081 | 1101 |
| 1102 virtual bool IsPrimitive() { UNREACHABLE(); return false; } |
| 1103 |
| 1082 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } | 1104 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } |
| 1083 | 1105 |
| 1084 // Accessors | 1106 // Accessors |
| 1085 Variable* var() const { return var_; } | 1107 Variable* var() const { return var_; } |
| 1086 Type type() const { return type_; } | 1108 Type type() const { return type_; } |
| 1087 int index() const { return index_; } | 1109 int index() const { return index_; } |
| 1088 bool is_arguments() const { return var_->is_arguments(); } | 1110 bool is_arguments() const { return var_->is_arguments(); } |
| 1089 | 1111 |
| 1090 private: | 1112 private: |
| 1091 Variable* var_; | 1113 Variable* var_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1104 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) | 1126 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) |
| 1105 : obj_(obj), key_(key), pos_(pos), type_(type) { } | 1127 : obj_(obj), key_(key), pos_(pos), type_(type) { } |
| 1106 | 1128 |
| 1107 virtual void Accept(AstVisitor* v); | 1129 virtual void Accept(AstVisitor* v); |
| 1108 | 1130 |
| 1109 // Type testing & conversion | 1131 // Type testing & conversion |
| 1110 virtual Property* AsProperty() { return this; } | 1132 virtual Property* AsProperty() { return this; } |
| 1111 | 1133 |
| 1112 virtual bool IsValidLeftHandSide() { return true; } | 1134 virtual bool IsValidLeftHandSide() { return true; } |
| 1113 | 1135 |
| 1136 virtual bool IsPrimitive(); |
| 1137 |
| 1114 Expression* obj() const { return obj_; } | 1138 Expression* obj() const { return obj_; } |
| 1115 Expression* key() const { return key_; } | 1139 Expression* key() const { return key_; } |
| 1116 int position() const { return pos_; } | 1140 int position() const { return pos_; } |
| 1117 bool is_synthetic() const { return type_ == SYNTHETIC; } | 1141 bool is_synthetic() const { return type_ == SYNTHETIC; } |
| 1118 | 1142 |
| 1119 // Returns a property singleton property access on 'this'. Used | 1143 // Returns a property singleton property access on 'this'. Used |
| 1120 // during preparsing. | 1144 // during preparsing. |
| 1121 static Property* this_property() { return &this_property_; } | 1145 static Property* this_property() { return &this_property_; } |
| 1122 | 1146 |
| 1123 private: | 1147 private: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1134 class Call: public Expression { | 1158 class Call: public Expression { |
| 1135 public: | 1159 public: |
| 1136 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) | 1160 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) |
| 1137 : expression_(expression), arguments_(arguments), pos_(pos) { } | 1161 : expression_(expression), arguments_(arguments), pos_(pos) { } |
| 1138 | 1162 |
| 1139 virtual void Accept(AstVisitor* v); | 1163 virtual void Accept(AstVisitor* v); |
| 1140 | 1164 |
| 1141 // Type testing and conversion. | 1165 // Type testing and conversion. |
| 1142 virtual Call* AsCall() { return this; } | 1166 virtual Call* AsCall() { return this; } |
| 1143 | 1167 |
| 1168 virtual bool IsPrimitive(); |
| 1169 |
| 1144 Expression* expression() const { return expression_; } | 1170 Expression* expression() const { return expression_; } |
| 1145 ZoneList<Expression*>* arguments() const { return arguments_; } | 1171 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1146 int position() { return pos_; } | 1172 int position() { return pos_; } |
| 1147 | 1173 |
| 1148 static Call* sentinel() { return &sentinel_; } | 1174 static Call* sentinel() { return &sentinel_; } |
| 1149 | 1175 |
| 1150 private: | 1176 private: |
| 1151 Expression* expression_; | 1177 Expression* expression_; |
| 1152 ZoneList<Expression*>* arguments_; | 1178 ZoneList<Expression*>* arguments_; |
| 1153 int pos_; | 1179 int pos_; |
| 1154 | 1180 |
| 1155 static Call sentinel_; | 1181 static Call sentinel_; |
| 1156 }; | 1182 }; |
| 1157 | 1183 |
| 1158 | 1184 |
| 1159 class CallNew: public Expression { | 1185 class CallNew: public Expression { |
| 1160 public: | 1186 public: |
| 1161 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) | 1187 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) |
| 1162 : expression_(expression), arguments_(arguments), pos_(pos) { } | 1188 : expression_(expression), arguments_(arguments), pos_(pos) { } |
| 1163 | 1189 |
| 1164 virtual void Accept(AstVisitor* v); | 1190 virtual void Accept(AstVisitor* v); |
| 1165 | 1191 |
| 1192 virtual bool IsPrimitive(); |
| 1193 |
| 1166 Expression* expression() const { return expression_; } | 1194 Expression* expression() const { return expression_; } |
| 1167 ZoneList<Expression*>* arguments() const { return arguments_; } | 1195 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1168 int position() { return pos_; } | 1196 int position() { return pos_; } |
| 1169 | 1197 |
| 1170 private: | 1198 private: |
| 1171 Expression* expression_; | 1199 Expression* expression_; |
| 1172 ZoneList<Expression*>* arguments_; | 1200 ZoneList<Expression*>* arguments_; |
| 1173 int pos_; | 1201 int pos_; |
| 1174 }; | 1202 }; |
| 1175 | 1203 |
| 1176 | 1204 |
| 1177 // The CallRuntime class does not represent any official JavaScript | 1205 // The CallRuntime class does not represent any official JavaScript |
| 1178 // language construct. Instead it is used to call a C or JS function | 1206 // language construct. Instead it is used to call a C or JS function |
| 1179 // with a set of arguments. This is used from the builtins that are | 1207 // with a set of arguments. This is used from the builtins that are |
| 1180 // implemented in JavaScript (see "v8natives.js"). | 1208 // implemented in JavaScript (see "v8natives.js"). |
| 1181 class CallRuntime: public Expression { | 1209 class CallRuntime: public Expression { |
| 1182 public: | 1210 public: |
| 1183 CallRuntime(Handle<String> name, | 1211 CallRuntime(Handle<String> name, |
| 1184 Runtime::Function* function, | 1212 Runtime::Function* function, |
| 1185 ZoneList<Expression*>* arguments) | 1213 ZoneList<Expression*>* arguments) |
| 1186 : name_(name), function_(function), arguments_(arguments) { } | 1214 : name_(name), function_(function), arguments_(arguments) { } |
| 1187 | 1215 |
| 1188 virtual void Accept(AstVisitor* v); | 1216 virtual void Accept(AstVisitor* v); |
| 1189 | 1217 |
| 1218 virtual bool IsPrimitive(); |
| 1219 |
| 1190 Handle<String> name() const { return name_; } | 1220 Handle<String> name() const { return name_; } |
| 1191 Runtime::Function* function() const { return function_; } | 1221 Runtime::Function* function() const { return function_; } |
| 1192 ZoneList<Expression*>* arguments() const { return arguments_; } | 1222 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1193 bool is_jsruntime() const { return function_ == NULL; } | 1223 bool is_jsruntime() const { return function_ == NULL; } |
| 1194 | 1224 |
| 1195 private: | 1225 private: |
| 1196 Handle<String> name_; | 1226 Handle<String> name_; |
| 1197 Runtime::Function* function_; | 1227 Runtime::Function* function_; |
| 1198 ZoneList<Expression*>* arguments_; | 1228 ZoneList<Expression*>* arguments_; |
| 1199 }; | 1229 }; |
| 1200 | 1230 |
| 1201 | 1231 |
| 1202 class UnaryOperation: public Expression { | 1232 class UnaryOperation: public Expression { |
| 1203 public: | 1233 public: |
| 1204 UnaryOperation(Token::Value op, Expression* expression) | 1234 UnaryOperation(Token::Value op, Expression* expression) |
| 1205 : op_(op), expression_(expression) { | 1235 : op_(op), expression_(expression) { |
| 1206 ASSERT(Token::IsUnaryOp(op)); | 1236 ASSERT(Token::IsUnaryOp(op)); |
| 1207 } | 1237 } |
| 1208 | 1238 |
| 1209 virtual void Accept(AstVisitor* v); | 1239 virtual void Accept(AstVisitor* v); |
| 1210 | 1240 |
| 1211 // Type testing & conversion | 1241 // Type testing & conversion |
| 1212 virtual UnaryOperation* AsUnaryOperation() { return this; } | 1242 virtual UnaryOperation* AsUnaryOperation() { return this; } |
| 1213 | 1243 |
| 1244 virtual bool IsPrimitive(); |
| 1245 |
| 1214 Token::Value op() const { return op_; } | 1246 Token::Value op() const { return op_; } |
| 1215 Expression* expression() const { return expression_; } | 1247 Expression* expression() const { return expression_; } |
| 1216 | 1248 |
| 1217 private: | 1249 private: |
| 1218 Token::Value op_; | 1250 Token::Value op_; |
| 1219 Expression* expression_; | 1251 Expression* expression_; |
| 1220 }; | 1252 }; |
| 1221 | 1253 |
| 1222 | 1254 |
| 1223 class BinaryOperation: public Expression { | 1255 class BinaryOperation: public Expression { |
| 1224 public: | 1256 public: |
| 1225 BinaryOperation(Token::Value op, Expression* left, Expression* right) | 1257 BinaryOperation(Token::Value op, Expression* left, Expression* right) |
| 1226 : op_(op), left_(left), right_(right) { | 1258 : op_(op), left_(left), right_(right) { |
| 1227 ASSERT(Token::IsBinaryOp(op)); | 1259 ASSERT(Token::IsBinaryOp(op)); |
| 1228 } | 1260 } |
| 1229 | 1261 |
| 1230 virtual void Accept(AstVisitor* v); | 1262 virtual void Accept(AstVisitor* v); |
| 1231 | 1263 |
| 1232 // Type testing & conversion | 1264 // Type testing & conversion |
| 1233 virtual BinaryOperation* AsBinaryOperation() { return this; } | 1265 virtual BinaryOperation* AsBinaryOperation() { return this; } |
| 1234 | 1266 |
| 1267 virtual bool IsPrimitive(); |
| 1268 |
| 1235 // True iff the result can be safely overwritten (to avoid allocation). | 1269 // True iff the result can be safely overwritten (to avoid allocation). |
| 1236 // False for operations that can return one of their operands. | 1270 // False for operations that can return one of their operands. |
| 1237 bool ResultOverwriteAllowed() { | 1271 bool ResultOverwriteAllowed() { |
| 1238 switch (op_) { | 1272 switch (op_) { |
| 1239 case Token::COMMA: | 1273 case Token::COMMA: |
| 1240 case Token::OR: | 1274 case Token::OR: |
| 1241 case Token::AND: | 1275 case Token::AND: |
| 1242 return false; | 1276 return false; |
| 1243 case Token::BIT_OR: | 1277 case Token::BIT_OR: |
| 1244 case Token::BIT_XOR: | 1278 case Token::BIT_XOR: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 } | 1311 } |
| 1278 | 1312 |
| 1279 virtual void Accept(AstVisitor* v); | 1313 virtual void Accept(AstVisitor* v); |
| 1280 | 1314 |
| 1281 virtual CountOperation* AsCountOperation() { return this; } | 1315 virtual CountOperation* AsCountOperation() { return this; } |
| 1282 | 1316 |
| 1283 virtual Variable* AssignedVar() { | 1317 virtual Variable* AssignedVar() { |
| 1284 return expression()->AsVariableProxy()->AsVariable(); | 1318 return expression()->AsVariableProxy()->AsVariable(); |
| 1285 } | 1319 } |
| 1286 | 1320 |
| 1321 virtual bool IsPrimitive(); |
| 1322 |
| 1287 bool is_prefix() const { return is_prefix_; } | 1323 bool is_prefix() const { return is_prefix_; } |
| 1288 bool is_postfix() const { return !is_prefix_; } | 1324 bool is_postfix() const { return !is_prefix_; } |
| 1289 Token::Value op() const { return op_; } | 1325 Token::Value op() const { return op_; } |
| 1290 Token::Value binary_op() { | 1326 Token::Value binary_op() { |
| 1291 return op_ == Token::INC ? Token::ADD : Token::SUB; | 1327 return op_ == Token::INC ? Token::ADD : Token::SUB; |
| 1292 } | 1328 } |
| 1293 Expression* expression() const { return expression_; } | 1329 Expression* expression() const { return expression_; } |
| 1294 | 1330 |
| 1295 virtual void MarkAsStatement() { is_prefix_ = true; } | 1331 virtual void MarkAsStatement() { is_prefix_ = true; } |
| 1296 | 1332 |
| 1297 private: | 1333 private: |
| 1298 bool is_prefix_; | 1334 bool is_prefix_; |
| 1299 Token::Value op_; | 1335 Token::Value op_; |
| 1300 Expression* expression_; | 1336 Expression* expression_; |
| 1301 }; | 1337 }; |
| 1302 | 1338 |
| 1303 | 1339 |
| 1304 class CompareOperation: public Expression { | 1340 class CompareOperation: public Expression { |
| 1305 public: | 1341 public: |
| 1306 CompareOperation(Token::Value op, Expression* left, Expression* right) | 1342 CompareOperation(Token::Value op, Expression* left, Expression* right) |
| 1307 : op_(op), left_(left), right_(right), is_for_loop_condition_(false) { | 1343 : op_(op), left_(left), right_(right), is_for_loop_condition_(false) { |
| 1308 ASSERT(Token::IsCompareOp(op)); | 1344 ASSERT(Token::IsCompareOp(op)); |
| 1309 } | 1345 } |
| 1310 | 1346 |
| 1311 virtual void Accept(AstVisitor* v); | 1347 virtual void Accept(AstVisitor* v); |
| 1312 | 1348 |
| 1349 virtual bool IsPrimitive(); |
| 1350 |
| 1313 Token::Value op() const { return op_; } | 1351 Token::Value op() const { return op_; } |
| 1314 Expression* left() const { return left_; } | 1352 Expression* left() const { return left_; } |
| 1315 Expression* right() const { return right_; } | 1353 Expression* right() const { return right_; } |
| 1316 | 1354 |
| 1317 // Accessors for flag whether this compare operation is hanging of a for loop. | 1355 // Accessors for flag whether this compare operation is hanging of a for loop. |
| 1318 bool is_for_loop_condition() const { return is_for_loop_condition_; } | 1356 bool is_for_loop_condition() const { return is_for_loop_condition_; } |
| 1319 void set_is_for_loop_condition() { is_for_loop_condition_ = true; } | 1357 void set_is_for_loop_condition() { is_for_loop_condition_ = true; } |
| 1320 | 1358 |
| 1321 // Type testing & conversion | 1359 // Type testing & conversion |
| 1322 virtual CompareOperation* AsCompareOperation() { return this; } | 1360 virtual CompareOperation* AsCompareOperation() { return this; } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1333 public: | 1371 public: |
| 1334 Conditional(Expression* condition, | 1372 Conditional(Expression* condition, |
| 1335 Expression* then_expression, | 1373 Expression* then_expression, |
| 1336 Expression* else_expression) | 1374 Expression* else_expression) |
| 1337 : condition_(condition), | 1375 : condition_(condition), |
| 1338 then_expression_(then_expression), | 1376 then_expression_(then_expression), |
| 1339 else_expression_(else_expression) { } | 1377 else_expression_(else_expression) { } |
| 1340 | 1378 |
| 1341 virtual void Accept(AstVisitor* v); | 1379 virtual void Accept(AstVisitor* v); |
| 1342 | 1380 |
| 1381 virtual bool IsPrimitive(); |
| 1382 |
| 1343 Expression* condition() const { return condition_; } | 1383 Expression* condition() const { return condition_; } |
| 1344 Expression* then_expression() const { return then_expression_; } | 1384 Expression* then_expression() const { return then_expression_; } |
| 1345 Expression* else_expression() const { return else_expression_; } | 1385 Expression* else_expression() const { return else_expression_; } |
| 1346 | 1386 |
| 1347 private: | 1387 private: |
| 1348 Expression* condition_; | 1388 Expression* condition_; |
| 1349 Expression* then_expression_; | 1389 Expression* then_expression_; |
| 1350 Expression* else_expression_; | 1390 Expression* else_expression_; |
| 1351 }; | 1391 }; |
| 1352 | 1392 |
| 1353 | 1393 |
| 1354 class Assignment: public Expression { | 1394 class Assignment: public Expression { |
| 1355 public: | 1395 public: |
| 1356 Assignment(Token::Value op, Expression* target, Expression* value, int pos) | 1396 Assignment(Token::Value op, Expression* target, Expression* value, int pos) |
| 1357 : op_(op), target_(target), value_(value), pos_(pos), | 1397 : op_(op), target_(target), value_(value), pos_(pos), |
| 1358 block_start_(false), block_end_(false) { | 1398 block_start_(false), block_end_(false) { |
| 1359 ASSERT(Token::IsAssignmentOp(op)); | 1399 ASSERT(Token::IsAssignmentOp(op)); |
| 1360 } | 1400 } |
| 1361 | 1401 |
| 1362 virtual void Accept(AstVisitor* v); | 1402 virtual void Accept(AstVisitor* v); |
| 1363 virtual Assignment* AsAssignment() { return this; } | 1403 virtual Assignment* AsAssignment() { return this; } |
| 1364 | 1404 |
| 1405 virtual bool IsPrimitive(); |
| 1406 |
| 1365 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 1407 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| 1366 | 1408 |
| 1367 virtual Variable* AssignedVar() { | 1409 virtual Variable* AssignedVar() { |
| 1368 return target()->AsVariableProxy()->AsVariable(); | 1410 return target()->AsVariableProxy()->AsVariable(); |
| 1369 } | 1411 } |
| 1370 | 1412 |
| 1371 Token::Value binary_op() const; | 1413 Token::Value binary_op() const; |
| 1372 | 1414 |
| 1373 Token::Value op() const { return op_; } | 1415 Token::Value op() const { return op_; } |
| 1374 Expression* target() const { return target_; } | 1416 Expression* target() const { return target_; } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1395 bool block_end_; | 1437 bool block_end_; |
| 1396 }; | 1438 }; |
| 1397 | 1439 |
| 1398 | 1440 |
| 1399 class Throw: public Expression { | 1441 class Throw: public Expression { |
| 1400 public: | 1442 public: |
| 1401 Throw(Expression* exception, int pos) | 1443 Throw(Expression* exception, int pos) |
| 1402 : exception_(exception), pos_(pos) {} | 1444 : exception_(exception), pos_(pos) {} |
| 1403 | 1445 |
| 1404 virtual void Accept(AstVisitor* v); | 1446 virtual void Accept(AstVisitor* v); |
| 1447 |
| 1448 virtual bool IsPrimitive(); |
| 1449 |
| 1405 Expression* exception() const { return exception_; } | 1450 Expression* exception() const { return exception_; } |
| 1406 int position() const { return pos_; } | 1451 int position() const { return pos_; } |
| 1407 | 1452 |
| 1408 private: | 1453 private: |
| 1409 Expression* exception_; | 1454 Expression* exception_; |
| 1410 int pos_; | 1455 int pos_; |
| 1411 }; | 1456 }; |
| 1412 | 1457 |
| 1413 | 1458 |
| 1414 class FunctionLiteral: public Expression { | 1459 class FunctionLiteral: public Expression { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1444 #endif | 1489 #endif |
| 1445 } | 1490 } |
| 1446 | 1491 |
| 1447 virtual void Accept(AstVisitor* v); | 1492 virtual void Accept(AstVisitor* v); |
| 1448 | 1493 |
| 1449 // Type testing & conversion | 1494 // Type testing & conversion |
| 1450 virtual FunctionLiteral* AsFunctionLiteral() { return this; } | 1495 virtual FunctionLiteral* AsFunctionLiteral() { return this; } |
| 1451 | 1496 |
| 1452 virtual bool IsLeaf() { return true; } | 1497 virtual bool IsLeaf() { return true; } |
| 1453 | 1498 |
| 1499 virtual bool IsPrimitive(); |
| 1500 |
| 1454 Handle<String> name() const { return name_; } | 1501 Handle<String> name() const { return name_; } |
| 1455 Scope* scope() const { return scope_; } | 1502 Scope* scope() const { return scope_; } |
| 1456 ZoneList<Statement*>* body() const { return body_; } | 1503 ZoneList<Statement*>* body() const { return body_; } |
| 1457 void set_function_token_position(int pos) { function_token_position_ = pos; } | 1504 void set_function_token_position(int pos) { function_token_position_ = pos; } |
| 1458 int function_token_position() const { return function_token_position_; } | 1505 int function_token_position() const { return function_token_position_; } |
| 1459 int start_position() const { return start_position_; } | 1506 int start_position() const { return start_position_; } |
| 1460 int end_position() const { return end_position_; } | 1507 int end_position() const { return end_position_; } |
| 1461 bool is_expression() const { return is_expression_; } | 1508 bool is_expression() const { return is_expression_; } |
| 1462 | 1509 |
| 1463 int materialized_literal_count() { return materialized_literal_count_; } | 1510 int materialized_literal_count() { return materialized_literal_count_; } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 : boilerplate_(boilerplate) { | 1561 : boilerplate_(boilerplate) { |
| 1515 ASSERT(boilerplate->IsBoilerplate()); | 1562 ASSERT(boilerplate->IsBoilerplate()); |
| 1516 } | 1563 } |
| 1517 | 1564 |
| 1518 Handle<JSFunction> boilerplate() const { return boilerplate_; } | 1565 Handle<JSFunction> boilerplate() const { return boilerplate_; } |
| 1519 | 1566 |
| 1520 virtual bool IsLeaf() { return true; } | 1567 virtual bool IsLeaf() { return true; } |
| 1521 | 1568 |
| 1522 virtual void Accept(AstVisitor* v); | 1569 virtual void Accept(AstVisitor* v); |
| 1523 | 1570 |
| 1571 virtual bool IsPrimitive(); |
| 1572 |
| 1524 private: | 1573 private: |
| 1525 Handle<JSFunction> boilerplate_; | 1574 Handle<JSFunction> boilerplate_; |
| 1526 }; | 1575 }; |
| 1527 | 1576 |
| 1528 | 1577 |
| 1529 class ThisFunction: public Expression { | 1578 class ThisFunction: public Expression { |
| 1530 public: | 1579 public: |
| 1531 virtual void Accept(AstVisitor* v); | 1580 virtual void Accept(AstVisitor* v); |
| 1532 virtual bool IsLeaf() { return true; } | 1581 virtual bool IsLeaf() { return true; } |
| 1582 virtual bool IsPrimitive(); |
| 1533 }; | 1583 }; |
| 1534 | 1584 |
| 1535 | 1585 |
| 1536 // ---------------------------------------------------------------------------- | 1586 // ---------------------------------------------------------------------------- |
| 1537 // Regular expressions | 1587 // Regular expressions |
| 1538 | 1588 |
| 1539 | 1589 |
| 1540 class RegExpVisitor BASE_EMBEDDED { | 1590 class RegExpVisitor BASE_EMBEDDED { |
| 1541 public: | 1591 public: |
| 1542 virtual ~RegExpVisitor() { } | 1592 virtual ~RegExpVisitor() { } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 #undef DEF_VISIT | 1970 #undef DEF_VISIT |
| 1921 | 1971 |
| 1922 private: | 1972 private: |
| 1923 bool stack_overflow_; | 1973 bool stack_overflow_; |
| 1924 }; | 1974 }; |
| 1925 | 1975 |
| 1926 | 1976 |
| 1927 } } // namespace v8::internal | 1977 } } // namespace v8::internal |
| 1928 | 1978 |
| 1929 #endif // V8_AST_H_ | 1979 #endif // V8_AST_H_ |
| OLD | NEW |