| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 int nreads_; | 59 int nreads_; |
| 60 int nwrites_; | 60 int nwrites_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 | 63 |
| 64 // Variables and AST expression nodes can track their "type" to enable | 64 // Variables and AST expression nodes can track their "type" to enable |
| 65 // optimizations and removal of redundant checks when generating code. | 65 // optimizations and removal of redundant checks when generating code. |
| 66 | 66 |
| 67 class StaticType BASE_EMBEDDED { | 67 class SmiAnalysis { |
| 68 public: | 68 public: |
| 69 enum Kind { | 69 enum Kind { |
| 70 UNKNOWN, | 70 UNKNOWN, |
| 71 LIKELY_SMI | 71 LIKELY_SMI |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 StaticType() : kind_(UNKNOWN) {} | 74 SmiAnalysis() : kind_(UNKNOWN) {} |
| 75 | 75 |
| 76 bool Is(Kind kind) const { return kind_ == kind; } | 76 bool Is(Kind kind) const { return kind_ == kind; } |
| 77 | 77 |
| 78 bool IsKnown() const { return !Is(UNKNOWN); } | 78 bool IsKnown() const { return !Is(UNKNOWN); } |
| 79 bool IsUnknown() const { return Is(UNKNOWN); } | 79 bool IsUnknown() const { return Is(UNKNOWN); } |
| 80 bool IsLikelySmi() const { return Is(LIKELY_SMI); } | 80 bool IsLikelySmi() const { return Is(LIKELY_SMI); } |
| 81 | 81 |
| 82 void CopyFrom(StaticType* other) { | 82 void CopyFrom(SmiAnalysis* other) { |
| 83 kind_ = other->kind_; | 83 kind_ = other->kind_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 static const char* Type2String(StaticType* type); | 86 static const char* Type2String(SmiAnalysis* type); |
| 87 | 87 |
| 88 // LIKELY_SMI accessors | 88 // LIKELY_SMI accessors |
| 89 void SetAsLikelySmi() { | 89 void SetAsLikelySmi() { |
| 90 kind_ = LIKELY_SMI; | 90 kind_ = LIKELY_SMI; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void SetAsLikelySmiIfUnknown() { | 93 void SetAsLikelySmiIfUnknown() { |
| 94 if (IsUnknown()) { | 94 if (IsUnknown()) { |
| 95 SetAsLikelySmi(); | 95 SetAsLikelySmi(); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 Kind kind_; | 100 Kind kind_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(StaticType); | 102 DISALLOW_COPY_AND_ASSIGN(SmiAnalysis); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 | 105 |
| 106 // The AST refers to variables via VariableProxies - placeholders for the actual | 106 // The AST refers to variables via VariableProxies - placeholders for the actual |
| 107 // variables. Variables themselves are never directly referred to from the AST, | 107 // variables. Variables themselves are never directly referred to from the AST, |
| 108 // they are maintained by scopes, and referred to from VariableProxies and Slots | 108 // they are maintained by scopes, and referred to from VariableProxies and Slots |
| 109 // after binding and variable allocation. | 109 // after binding and variable allocation. |
| 110 | 110 |
| 111 class Variable: public ZoneObject { | 111 class Variable: public ZoneObject { |
| 112 public: | 112 public: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return local_if_not_shadowed_; | 178 return local_if_not_shadowed_; |
| 179 } | 179 } |
| 180 | 180 |
| 181 void set_local_if_not_shadowed(Variable* local) { | 181 void set_local_if_not_shadowed(Variable* local) { |
| 182 local_if_not_shadowed_ = local; | 182 local_if_not_shadowed_ = local; |
| 183 } | 183 } |
| 184 | 184 |
| 185 Expression* rewrite() const { return rewrite_; } | 185 Expression* rewrite() const { return rewrite_; } |
| 186 Slot* slot() const; | 186 Slot* slot() const; |
| 187 | 187 |
| 188 StaticType* type() { return &type_; } | 188 SmiAnalysis* type() { return &type_; } |
| 189 | 189 |
| 190 private: | 190 private: |
| 191 Variable(Scope* scope, Handle<String> name, Mode mode, bool is_valid_LHS, | 191 Variable(Scope* scope, Handle<String> name, Mode mode, bool is_valid_LHS, |
| 192 bool is_this); | 192 bool is_this); |
| 193 | 193 |
| 194 Scope* scope_; | 194 Scope* scope_; |
| 195 Handle<String> name_; | 195 Handle<String> name_; |
| 196 Mode mode_; | 196 Mode mode_; |
| 197 bool is_valid_LHS_; | 197 bool is_valid_LHS_; |
| 198 bool is_this_; | 198 bool is_this_; |
| 199 | 199 |
| 200 Variable* local_if_not_shadowed_; | 200 Variable* local_if_not_shadowed_; |
| 201 | 201 |
| 202 // Usage info. | 202 // Usage info. |
| 203 bool is_accessed_from_inner_scope_; // set by variable resolver | 203 bool is_accessed_from_inner_scope_; // set by variable resolver |
| 204 UseCount var_uses_; // uses of the variable value | 204 UseCount var_uses_; // uses of the variable value |
| 205 UseCount obj_uses_; // uses of the object the variable points to | 205 UseCount obj_uses_; // uses of the object the variable points to |
| 206 | 206 |
| 207 // Static type information | 207 // Static type information |
| 208 StaticType type_; | 208 SmiAnalysis type_; |
| 209 | 209 |
| 210 // Code generation. | 210 // Code generation. |
| 211 // rewrite_ is usually a Slot or a Property, but maybe any expression. | 211 // rewrite_ is usually a Slot or a Property, but maybe any expression. |
| 212 Expression* rewrite_; | 212 Expression* rewrite_; |
| 213 | 213 |
| 214 friend class VariableProxy; | 214 friend class VariableProxy; |
| 215 friend class Scope; | 215 friend class Scope; |
| 216 friend class LocalsMap; | 216 friend class LocalsMap; |
| 217 friend class AstBuildingParser; | 217 friend class AstBuildingParser; |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 | 220 |
| 221 } } // namespace v8::internal | 221 } } // namespace v8::internal |
| 222 | 222 |
| 223 #endif // V8_VARIABLES_H_ | 223 #endif // V8_VARIABLES_H_ |
| OLD | NEW |