}
+#define GENERATE_VALUE_GETTER(value, initializer) \
+ if (!value) { \
+ value = new (zone_) AstValue(initializer); \
+ if (isolate_) { \
+ value->Internalize(isolate_); \
+ } \
+ values_.Add(value); \
+ } \
+ return value;
+
+
const AstValue* AstValueFactory::NewBoolean(bool b) {
- AstValue* value = new (zone_) AstValue(b);
- if (isolate_) {
- value->Internalize(isolate_);
+ if (b) {
+ GENERATE_VALUE_GETTER(true_value_, true);
+ } else {
+ GENERATE_VALUE_GETTER(false_value_, false);
}
- values_.Add(value);
- return value;
}
const AstValue* AstValueFactory::NewNull() {
- AstValue* value = new (zone_) AstValue(AstValue::NULL_TYPE);
- if (isolate_) {
- value->Internalize(isolate_);
- }
- values_.Add(value);
- return value;
+ GENERATE_VALUE_GETTER(null_value_, AstValue::NULL_TYPE);
}
const AstValue* AstValueFactory::NewUndefined() {
- AstValue* value = new (zone_) AstValue(AstValue::UNDEFINED);
- if (isolate_) {
- value->Internalize(isolate_);
- }
- values_.Add(value);
- return value;
+ GENERATE_VALUE_GETTER(undefined_value_, AstValue::UNDEFINED);
}
const AstValue* AstValueFactory::NewTheHole() {
- AstValue* value = new (zone_) AstValue(AstValue::THE_HOLE);
- if (isolate_) {
- value->Internalize(isolate_);
- }
- values_.Add(value);
- return value;
+ GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE);
}
+#undef GENERATE_VALUE_GETTER
+
const AstRawString* AstValueFactory::GetString(
uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) {
// literal_bytes here points to whatever the user passed, and this is OK
};
-// For generating string constants.
+// For generating constants.
#define STRING_CONSTANTS(F) \
F(anonymous_function, "(anonymous function)") \
F(arguments, "arguments") \
F(use_strict, "use strict") \
F(value, "value")
+#define OTHER_CONSTANTS(F) \
+ F(true_value) \
+ F(false_value) \
+ F(null_value) \
+ F(undefined_value) \
+ F(the_hole_value)
class AstValueFactory {
public:
zone_(zone),
isolate_(NULL),
hash_seed_(hash_seed) {
-#define F(name, str) \
- name##_string_ = NULL;
+#define F(name, str) name##_string_ = NULL;
STRING_CONSTANTS(F)
+#undef F
+#define F(name) name##_ = NULL;
+ OTHER_CONSTANTS(F)
#undef F
}
return isolate_ != NULL;
}
-#define F(name, str) \
- const AstRawString* name##_string() { \
- if (name##_string_ == NULL) { \
- const char* data = str; \
- name##_string_ = GetOneByteString( \
+#define F(name, str) \
+ const AstRawString* name##_string() { \
+ if (name##_string_ == NULL) { \
+ const char* data = str; \
+ name##_string_ = GetOneByteString( \
Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \
- static_cast<int>(strlen(data)))); \
- } \
- return name##_string_; \
+ static_cast<int>(strlen(data)))); \
+ } \
+ return name##_string_; \
}
STRING_CONSTANTS(F)
#undef F
uint32_t hash_seed_;
-#define F(name, str) \
- const AstRawString* name##_string_;
+#define F(name, str) const AstRawString* name##_string_;
STRING_CONSTANTS(F)
#undef F
+
+#define F(name) AstValue* name##_;
+ OTHER_CONSTANTS(F)
+#undef F
};
} } // namespace v8::internal
#undef STRING_CONSTANTS
+#undef OTHER_CONSTANTS
#endif // V8_AST_VALUE_FACTORY_H_