The data contained in this repository can be downloaded to your computer using one of several clients.
Please see the documentation of your version control software client for more information.
Please select the desired protocol below to get the URL.
This URL has Read-Only access.
main_repo / deps / v8 / src / variables.cc @ 40c0f755
History | View | Annotate | Download (4.61 KB)
1 |
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
---|---|
2 |
// Redistribution and use in source and binary forms, with or without
|
3 |
// modification, are permitted provided that the following conditions are
|
4 |
// met:
|
5 |
//
|
6 |
// * Redistributions of source code must retain the above copyright
|
7 |
// notice, this list of conditions and the following disclaimer.
|
8 |
// * Redistributions in binary form must reproduce the above
|
9 |
// copyright notice, this list of conditions and the following
|
10 |
// disclaimer in the documentation and/or other materials provided
|
11 |
// with the distribution.
|
12 |
// * Neither the name of Google Inc. nor the names of its
|
13 |
// contributors may be used to endorse or promote products derived
|
14 |
// from this software without specific prior written permission.
|
15 |
//
|
16 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
20 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
26 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
28 |
#include "v8.h" |
29 |
|
30 |
#include "ast.h" |
31 |
#include "scopes.h" |
32 |
#include "variables.h" |
33 |
|
34 |
namespace v8 { namespace internal { |
35 |
|
36 |
// ----------------------------------------------------------------------------
|
37 |
// Implementation UseCount.
|
38 |
|
39 |
UseCount::UseCount() |
40 |
: nreads_(0),
|
41 |
nwrites_(0) {
|
42 |
} |
43 |
|
44 |
|
45 |
void UseCount::RecordRead(int weight) { |
46 |
ASSERT(weight > 0);
|
47 |
nreads_ += weight; |
48 |
// We must have a positive nreads_ here. Handle
|
49 |
// any kind of overflow by setting nreads_ to
|
50 |
// some large-ish value.
|
51 |
if (nreads_ <= 0) nreads_ = 1000000; |
52 |
ASSERT(is_read() & is_used()); |
53 |
} |
54 |
|
55 |
|
56 |
void UseCount::RecordWrite(int weight) { |
57 |
ASSERT(weight > 0);
|
58 |
nwrites_ += weight; |
59 |
// We must have a positive nwrites_ here. Handle
|
60 |
// any kind of overflow by setting nwrites_ to
|
61 |
// some large-ish value.
|
62 |
if (nwrites_ <= 0) nwrites_ = 1000000; |
63 |
ASSERT(is_written() && is_used()); |
64 |
} |
65 |
|
66 |
|
67 |
void UseCount::RecordAccess(int weight) { |
68 |
RecordRead(weight); |
69 |
RecordWrite(weight); |
70 |
} |
71 |
|
72 |
|
73 |
void UseCount::RecordUses(UseCount* uses) {
|
74 |
if (uses->nreads() > 0) RecordRead(uses->nreads()); |
75 |
if (uses->nwrites() > 0) RecordWrite(uses->nwrites()); |
76 |
} |
77 |
|
78 |
|
79 |
#ifdef DEBUG
|
80 |
void UseCount::Print() {
|
81 |
// PrintF("r = %d, w = %d", nreads_, nwrites_);
|
82 |
PrintF("%du = %dr + %dw", nuses(), nreads(), nwrites());
|
83 |
} |
84 |
#endif
|
85 |
|
86 |
|
87 |
// ----------------------------------------------------------------------------
|
88 |
// Implementation SmiAnalysis.
|
89 |
|
90 |
|
91 |
const char* SmiAnalysis::Type2String(SmiAnalysis* type) { |
92 |
switch (type->kind_) {
|
93 |
case UNKNOWN:
|
94 |
return "UNKNOWN"; |
95 |
case LIKELY_SMI:
|
96 |
return "LIKELY_SMI"; |
97 |
default:
|
98 |
UNREACHABLE(); |
99 |
} |
100 |
return "UNREACHABLE"; |
101 |
} |
102 |
|
103 |
|
104 |
// ----------------------------------------------------------------------------
|
105 |
// Implementation Variable.
|
106 |
|
107 |
|
108 |
const char* Variable::Mode2String(Mode mode) { |
109 |
switch (mode) {
|
110 |
case VAR: return "VAR"; |
111 |
case CONST: return "CONST"; |
112 |
case DYNAMIC: return "DYNAMIC"; |
113 |
case DYNAMIC_GLOBAL: return "DYNAMIC_GLOBAL"; |
114 |
case DYNAMIC_LOCAL: return "DYNAMIC_LOCAL"; |
115 |
case INTERNAL: return "INTERNAL"; |
116 |
case TEMPORARY: return "TEMPORARY"; |
117 |
} |
118 |
UNREACHABLE(); |
119 |
return NULL; |
120 |
} |
121 |
|
122 |
|
123 |
Property* Variable::AsProperty() { |
124 |
return rewrite_ == NULL ? NULL : rewrite_->AsProperty(); |
125 |
} |
126 |
|
127 |
|
128 |
Variable* Variable::AsVariable() { |
129 |
return rewrite_ == NULL || rewrite_->AsSlot() != NULL ? this : NULL; |
130 |
} |
131 |
|
132 |
|
133 |
Slot* Variable::slot() const {
|
134 |
return rewrite_ != NULL ? rewrite_->AsSlot() : NULL; |
135 |
} |
136 |
|
137 |
|
138 |
Variable::Variable(Scope* scope, |
139 |
Handle<String> name, |
140 |
Mode mode, |
141 |
bool is_valid_LHS,
|
142 |
bool is_this)
|
143 |
: scope_(scope), |
144 |
name_(name), |
145 |
mode_(mode), |
146 |
is_valid_LHS_(is_valid_LHS), |
147 |
is_this_(is_this), |
148 |
local_if_not_shadowed_(NULL),
|
149 |
is_accessed_from_inner_scope_(false),
|
150 |
rewrite_(NULL) {
|
151 |
// names must be canonicalized for fast equality checks
|
152 |
ASSERT(name->IsSymbol()); |
153 |
} |
154 |
|
155 |
|
156 |
bool Variable::is_global() const { |
157 |
// Temporaries are never global, they must always be allocated in the
|
158 |
// activation frame.
|
159 |
return mode_ != TEMPORARY && scope_ != NULL && scope_->is_global_scope(); |
160 |
} |
161 |
|
162 |
} } // namespace v8::internal
|