説明を見る。00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "v8.h"
00029
00030 #include "ast.h"
00031 #include "scopes.h"
00032 #include "variables.h"
00033
00034 namespace v8 { namespace internal {
00035
00036
00037
00038
00039 UseCount::UseCount()
00040 : nreads_(0),
00041 nwrites_(0) {
00042 }
00043
00044
00045 void UseCount::RecordRead(int weight) {
00046 ASSERT(weight > 0);
00047 nreads_ += weight;
00048
00049
00050
00051 if (nreads_ <= 0) nreads_ = 1000000;
00052 ASSERT(is_read() & is_used());
00053 }
00054
00055
00056 void UseCount::RecordWrite(int weight) {
00057 ASSERT(weight > 0);
00058 nwrites_ += weight;
00059
00060
00061
00062 if (nwrites_ <= 0) nwrites_ = 1000000;
00063 ASSERT(is_written() && is_used());
00064 }
00065
00066
00067 void UseCount::RecordAccess(int weight) {
00068 RecordRead(weight);
00069 RecordWrite(weight);
00070 }
00071
00072
00073 void UseCount::RecordUses(UseCount* uses) {
00074 if (uses->nreads() > 0) RecordRead(uses->nreads());
00075 if (uses->nwrites() > 0) RecordWrite(uses->nwrites());
00076 }
00077
00078
00079 #ifdef DEBUG
00080 void UseCount::Print() {
00081
00082 PrintF("%du = %dr + %dw", nuses(), nreads(), nwrites());
00083 }
00084 #endif
00085
00086
00087
00088
00089
00090
00091 const char* StaticType::Type2String(StaticType* type) {
00092 switch (type->kind_) {
00093 case UNKNOWN:
00094 return "UNKNOWN";
00095 case LIKELY_SMI:
00096 return "LIKELY_SMI";
00097 default:
00098 UNREACHABLE();
00099 }
00100 return "UNREACHABLE";
00101 }
00102
00103
00104
00105
00106
00107
00108 const char* Variable::Mode2String(Mode mode) {
00109 switch (mode) {
00110 case VAR: return "VAR";
00111 case CONST: return "CONST";
00112 case DYNAMIC: return "DYNAMIC";
00113 case INTERNAL: return "INTERNAL";
00114 case TEMPORARY: return "TEMPORARY";
00115 }
00116 UNREACHABLE();
00117 return NULL;
00118 }
00119
00120
00121 Property* Variable::AsProperty() {
00122 return rewrite_ == NULL ? NULL : rewrite_->AsProperty();
00123 }
00124
00125
00126 Variable* Variable::AsVariable() {
00127 return rewrite_ == NULL || rewrite_->AsSlot() != NULL ? this : NULL;
00128 }
00129
00130
00131 Slot* Variable::slot() const {
00132 return rewrite_ != NULL ? rewrite_->AsSlot() : NULL;
00133 }
00134
00135
00136 Variable::Variable(Scope* scope,
00137 Handle<String> name,
00138 Mode mode,
00139 bool is_valid_LHS,
00140 bool is_this)
00141 : scope_(scope),
00142 name_(name),
00143 mode_(mode),
00144 is_valid_LHS_(is_valid_LHS),
00145 is_this_(is_this),
00146 is_accessed_from_inner_scope_(false),
00147 rewrite_(NULL) {
00148
00149 ASSERT(name->IsSymbol());
00150 }
00151
00152
00153 bool Variable::is_global() const {
00154
00155
00156 return mode_ != TEMPORARY && scope_ != NULL && scope_->is_global_scope();
00157 }
00158
00159
00160 } }