| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 int nreads_; | 60 int nreads_; |
| 61 int nwrites_; | 61 int nwrites_; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 | 64 |
| 65 // Variables and AST expression nodes can track their "type" to enable | 65 // Variables and AST expression nodes can track their "type" to enable |
| 66 // optimizations and removal of redundant checks when generating code. | 66 // optimizations and removal of redundant checks when generating code. |
| 67 | 67 |
| 68 class SmiAnalysis { | 68 class StaticType { |
| 69 public: | 69 public: |
| 70 enum Kind { | 70 enum Kind { |
| 71 UNKNOWN, | 71 UNKNOWN, |
| 72 LIKELY_SMI | 72 LIKELY_SMI |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 SmiAnalysis() : kind_(UNKNOWN) {} | 75 StaticType() : kind_(UNKNOWN) {} |
| 76 | 76 |
| 77 bool Is(Kind kind) const { return kind_ == kind; } | 77 bool Is(Kind kind) const { return kind_ == kind; } |
| 78 | 78 |
| 79 bool IsKnown() const { return !Is(UNKNOWN); } | 79 bool IsKnown() const { return !Is(UNKNOWN); } |
| 80 bool IsUnknown() const { return Is(UNKNOWN); } | 80 bool IsUnknown() const { return Is(UNKNOWN); } |
| 81 bool IsLikelySmi() const { return Is(LIKELY_SMI); } | 81 bool IsLikelySmi() const { return Is(LIKELY_SMI); } |
| 82 | 82 |
| 83 void CopyFrom(SmiAnalysis* other) { | 83 void CopyFrom(StaticType* other) { |
| 84 kind_ = other->kind_; | 84 kind_ = other->kind_; |
| 85 } | 85 } |
| 86 | 86 |
| 87 static const char* Type2String(SmiAnalysis* type); | 87 static const char* Type2String(StaticType* type); |
| 88 | 88 |
| 89 // LIKELY_SMI accessors | 89 // LIKELY_SMI accessors |
| 90 void SetAsLikelySmi() { | 90 void SetAsLikelySmi() { |
| 91 kind_ = LIKELY_SMI; | 91 kind_ = LIKELY_SMI; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SetAsLikelySmiIfUnknown() { | 94 void SetAsLikelySmiIfUnknown() { |
| 95 if (IsUnknown()) { | 95 if (IsUnknown()) { |
| 96 SetAsLikelySmi(); | 96 SetAsLikelySmi(); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 Kind kind_; | 101 Kind kind_; |
| 102 | 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(SmiAnalysis); | 103 DISALLOW_COPY_AND_ASSIGN(StaticType); |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 | 106 |
| 107 // The AST refers to variables via VariableProxies - placeholders for the actual | 107 // The AST refers to variables via VariableProxies - placeholders for the actual |
| 108 // variables. Variables themselves are never directly referred to from the AST, | 108 // variables. Variables themselves are never directly referred to from the AST, |
| 109 // they are maintained by scopes, and referred to from VariableProxies and Slots | 109 // they are maintained by scopes, and referred to from VariableProxies and Slots |
| 110 // after binding and variable allocation. | 110 // after binding and variable allocation. |
| 111 | 111 |
| 112 class Variable: public ZoneObject { | 112 class Variable: public ZoneObject { |
| 113 public: | 113 public: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return local_if_not_shadowed_; | 196 return local_if_not_shadowed_; |
| 197 } | 197 } |
| 198 | 198 |
| 199 void set_local_if_not_shadowed(Variable* local) { | 199 void set_local_if_not_shadowed(Variable* local) { |
| 200 local_if_not_shadowed_ = local; | 200 local_if_not_shadowed_ = local; |
| 201 } | 201 } |
| 202 | 202 |
| 203 Expression* rewrite() const { return rewrite_; } | 203 Expression* rewrite() const { return rewrite_; } |
| 204 Slot* slot() const; | 204 Slot* slot() const; |
| 205 | 205 |
| 206 SmiAnalysis* type() { return &type_; } | 206 StaticType* type() { return &type_; } |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 Scope* scope_; | 209 Scope* scope_; |
| 210 Handle<String> name_; | 210 Handle<String> name_; |
| 211 Mode mode_; | 211 Mode mode_; |
| 212 bool is_valid_LHS_; | 212 bool is_valid_LHS_; |
| 213 Kind kind_; | 213 Kind kind_; |
| 214 | 214 |
| 215 Variable* local_if_not_shadowed_; | 215 Variable* local_if_not_shadowed_; |
| 216 | 216 |
| 217 // Usage info. | 217 // Usage info. |
| 218 bool is_accessed_from_inner_scope_; // set by variable resolver | 218 bool is_accessed_from_inner_scope_; // set by variable resolver |
| 219 UseCount var_uses_; // uses of the variable value | 219 UseCount var_uses_; // uses of the variable value |
| 220 UseCount obj_uses_; // uses of the object the variable points to | 220 UseCount obj_uses_; // uses of the object the variable points to |
| 221 | 221 |
| 222 // Static type information | 222 // Static type information |
| 223 SmiAnalysis type_; | 223 StaticType type_; |
| 224 | 224 |
| 225 // Code generation. | 225 // Code generation. |
| 226 // rewrite_ is usually a Slot or a Property, but may be any expression. | 226 // rewrite_ is usually a Slot or a Property, but may be any expression. |
| 227 Expression* rewrite_; | 227 Expression* rewrite_; |
| 228 | 228 |
| 229 friend class Scope; // Has explicit access to rewrite_. | 229 friend class Scope; // Has explicit access to rewrite_. |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 | 232 |
| 233 } } // namespace v8::internal | 233 } } // namespace v8::internal |
| 234 | 234 |
| 235 #endif // V8_VARIABLES_H_ | 235 #endif // V8_VARIABLES_H_ |
| OLD | NEW |