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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #ifdef DEBUG | 54 #ifdef DEBUG |
55 void Print(); | 55 void Print(); |
56 #endif | 56 #endif |
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 |
| 65 // optimizations and removal of redundant checks when generating code. |
| 66 |
| 67 class StaticType BASE_EMBEDDED { |
| 68 public: |
| 69 enum Kind { |
| 70 UNKNOWN, |
| 71 LIKELY_SMI |
| 72 }; |
| 73 |
| 74 StaticType() : kind_(UNKNOWN) {} |
| 75 |
| 76 bool Is(Kind kind) const { return kind_ == kind; } |
| 77 |
| 78 bool IsKnown() const { return !Is(UNKNOWN); } |
| 79 bool IsUnknown() const { return Is(UNKNOWN); } |
| 80 bool IsLikelySmi() const { return Is(LIKELY_SMI); } |
| 81 |
| 82 void CopyFrom(StaticType* other) { |
| 83 kind_ = other->kind_; |
| 84 } |
| 85 |
| 86 static char* Type2String(StaticType* type); |
| 87 |
| 88 // LIKELY_SMI accessors |
| 89 void SetAsLikelySmi() { |
| 90 kind_ = LIKELY_SMI; |
| 91 } |
| 92 |
| 93 void SetAsLikelySmiIfUnknown() { |
| 94 if (IsUnknown()) { |
| 95 SetAsLikelySmi(); |
| 96 } |
| 97 } |
| 98 |
| 99 private: |
| 100 Kind kind_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(StaticType); |
| 103 }; |
| 104 |
| 105 |
64 // The AST refers to variables via VariableProxies - placeholders for the actual | 106 // The AST refers to variables via VariableProxies - placeholders for the actual |
65 // variables. Variables themselves are never directly referred to from the AST, | 107 // variables. Variables themselves are never directly referred to from the AST, |
66 // 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 |
67 // after binding and variable allocation. | 109 // after binding and variable allocation. |
68 | 110 |
69 class Variable: public ZoneObject { | 111 class Variable: public ZoneObject { |
70 public: | 112 public: |
71 enum Mode { | 113 enum Mode { |
72 // User declared variables: | 114 // User declared variables: |
73 VAR, // declared via 'var', and 'function' declarations | 115 VAR, // declared via 'var', and 'function' declarations |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 bool IsVariable(Handle<String> n) { | 149 bool IsVariable(Handle<String> n) { |
108 return !is_this() && name().is_identical_to(n); | 150 return !is_this() && name().is_identical_to(n); |
109 } | 151 } |
110 | 152 |
111 bool is_global() const; | 153 bool is_global() const; |
112 bool is_this() const { return is_this_; } | 154 bool is_this() const { return is_this_; } |
113 | 155 |
114 Expression* rewrite() const { return rewrite_; } | 156 Expression* rewrite() const { return rewrite_; } |
115 Slot* slot() const; | 157 Slot* slot() const; |
116 | 158 |
| 159 StaticType* type() { return &type_; } |
| 160 |
117 private: | 161 private: |
118 Variable(Scope* scope, Handle<String> name, Mode mode, bool is_valid_LHS, | 162 Variable(Scope* scope, Handle<String> name, Mode mode, bool is_valid_LHS, |
119 bool is_this); | 163 bool is_this); |
120 | 164 |
121 Scope* scope_; | 165 Scope* scope_; |
122 Handle<String> name_; | 166 Handle<String> name_; |
123 Mode mode_; | 167 Mode mode_; |
124 bool is_valid_LHS_; | 168 bool is_valid_LHS_; |
125 bool is_this_; | 169 bool is_this_; |
126 | 170 |
127 // Usage info. | 171 // Usage info. |
128 bool is_accessed_from_inner_scope_; // set by variable resolver | 172 bool is_accessed_from_inner_scope_; // set by variable resolver |
129 UseCount var_uses_; // uses of the variable value | 173 UseCount var_uses_; // uses of the variable value |
130 UseCount obj_uses_; // uses of the object the variable points to | 174 UseCount obj_uses_; // uses of the object the variable points to |
131 | 175 |
| 176 // Static type information |
| 177 StaticType type_; |
| 178 |
132 // Code generation. | 179 // Code generation. |
133 // rewrite_ is usually a Slot or a Property, but maybe any expression. | 180 // rewrite_ is usually a Slot or a Property, but maybe any expression. |
134 Expression* rewrite_; | 181 Expression* rewrite_; |
135 | 182 |
136 friend class VariableProxy; | 183 friend class VariableProxy; |
137 friend class Scope; | 184 friend class Scope; |
138 friend class LocalsMap; | 185 friend class LocalsMap; |
139 friend class AstBuildingParser; | 186 friend class AstBuildingParser; |
140 }; | 187 }; |
141 | 188 |
142 | 189 |
143 } } // namespace v8::internal | 190 } } // namespace v8::internal |
144 | 191 |
145 #endif // V8_VARIABLES_H_ | 192 #endif // V8_VARIABLES_H_ |
OLD | NEW |