Make some foo.h headers usable without foo-inl.h header.

This CL us a pure refactoring that makes an empty compilation unit
including just "foo.h" but not "foo-inl.h" compile without warnings or
errors. This is needed to further reduce the header dependency tangle.

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/1290743005

Cr-Commit-Position: refs/heads/master@{#30158}
This commit is contained in:
mstarzinger 2015-08-13 07:02:22 -07:00 committed by Commit bot
parent 2477b8f38d
commit 8e634eaa0b
6 changed files with 85 additions and 79 deletions

View File

@ -18,6 +18,7 @@
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/conversions.h" #include "src/conversions.h"
#include "src/double.h" #include "src/double.h"
#include "src/objects-inl.h"
#include "src/scanner.h" #include "src/scanner.h"
#include "src/strtod.h" #include "src/strtod.h"
@ -97,6 +98,68 @@ int32_t DoubleToInt32(double x) {
} }
bool IsSmiDouble(double value) {
return !IsMinusZero(value) && value >= Smi::kMinValue &&
value <= Smi::kMaxValue && value == FastI2D(FastD2I(value));
}
bool IsInt32Double(double value) {
return !IsMinusZero(value) && value >= kMinInt && value <= kMaxInt &&
value == FastI2D(FastD2I(value));
}
bool IsUint32Double(double value) {
return !IsMinusZero(value) && value >= 0 && value <= kMaxUInt32 &&
value == FastUI2D(FastD2UI(value));
}
int32_t NumberToInt32(Object* number) {
if (number->IsSmi()) return Smi::cast(number)->value();
return DoubleToInt32(number->Number());
}
uint32_t NumberToUint32(Object* number) {
if (number->IsSmi()) return Smi::cast(number)->value();
return DoubleToUint32(number->Number());
}
bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) {
SealHandleScope shs(isolate);
if (number->IsSmi()) {
int value = Smi::cast(number)->value();
DCHECK(static_cast<unsigned>(Smi::kMaxValue) <=
std::numeric_limits<size_t>::max());
if (value >= 0) {
*result = static_cast<size_t>(value);
return true;
}
return false;
} else {
DCHECK(number->IsHeapNumber());
double value = HeapNumber::cast(number)->value();
if (value >= 0 && value <= std::numeric_limits<size_t>::max()) {
*result = static_cast<size_t>(value);
return true;
} else {
return false;
}
}
}
size_t NumberToSize(Isolate* isolate, Object* number) {
size_t result = 0;
bool is_valid = TryNumberToSize(isolate, number, &result);
CHECK(is_valid);
return result;
}
template <class Iterator, class EndMark> template <class Iterator, class EndMark>
bool SubStringEquals(Iterator* current, bool SubStringEquals(Iterator* current,
EndMark end, EndMark end,

View File

@ -9,7 +9,6 @@
#include "src/base/logging.h" #include "src/base/logging.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/objects.h"
#include "src/utils.h" #include "src/utils.h"
namespace v8 { namespace v8 {
@ -157,88 +156,41 @@ static inline bool IsMinusZero(double value) {
} }
static inline bool IsSmiDouble(double value) { static inline bool IsSmiDouble(double value);
return !IsMinusZero(value) && value >= Smi::kMinValue &&
value <= Smi::kMaxValue && value == FastI2D(FastD2I(value));
}
// Integer32 is an integer that can be represented as a signed 32-bit // Integer32 is an integer that can be represented as a signed 32-bit
// integer. It has to be in the range [-2^31, 2^31 - 1]. // integer. It has to be in the range [-2^31, 2^31 - 1].
// We also have to check for negative 0 as it is not an Integer32. // We also have to check for negative 0 as it is not an Integer32.
static inline bool IsInt32Double(double value) { static inline bool IsInt32Double(double value);
return !IsMinusZero(value) &&
value >= kMinInt &&
value <= kMaxInt &&
value == FastI2D(FastD2I(value));
}
// UInteger32 is an integer that can be represented as an unsigned 32-bit // UInteger32 is an integer that can be represented as an unsigned 32-bit
// integer. It has to be in the range [0, 2^32 - 1]. // integer. It has to be in the range [0, 2^32 - 1].
// We also have to check for negative 0 as it is not a UInteger32. // We also have to check for negative 0 as it is not a UInteger32.
static inline bool IsUint32Double(double value) { static inline bool IsUint32Double(double value);
return !IsMinusZero(value) &&
value >= 0 &&
value <= kMaxUInt32 &&
value == FastUI2D(FastD2UI(value));
}
// Convert from Number object to C integer. // Convert from Number object to C integer.
inline int32_t NumberToInt32(Object* number) { inline int32_t NumberToInt32(Object* number);
if (number->IsSmi()) return Smi::cast(number)->value(); inline uint32_t NumberToUint32(Object* number);
return DoubleToInt32(number->Number());
}
inline uint32_t NumberToUint32(Object* number) {
if (number->IsSmi()) return Smi::cast(number)->value();
return DoubleToUint32(number->Number());
}
double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string, double StringToDouble(UnicodeCache* unicode_cache, Handle<String> string,
int flags, double empty_string_val = 0.0); int flags, double empty_string_val = 0.0);
inline bool TryNumberToSize(Isolate* isolate, inline bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result);
Object* number, size_t* result) {
SealHandleScope shs(isolate);
if (number->IsSmi()) {
int value = Smi::cast(number)->value();
DCHECK(static_cast<unsigned>(Smi::kMaxValue)
<= std::numeric_limits<size_t>::max());
if (value >= 0) {
*result = static_cast<size_t>(value);
return true;
}
return false;
} else {
DCHECK(number->IsHeapNumber());
double value = HeapNumber::cast(number)->value();
if (value >= 0 &&
value <= std::numeric_limits<size_t>::max()) {
*result = static_cast<size_t>(value);
return true;
} else {
return false;
}
}
}
// Converts a number into size_t. // Converts a number into size_t.
inline size_t NumberToSize(Isolate* isolate, inline size_t NumberToSize(Isolate* isolate, Object* number);
Object* number) {
size_t result = 0;
bool is_valid = TryNumberToSize(isolate, number, &result);
CHECK(is_valid);
return result;
}
// returns DoubleToString(StringToDouble(string)) == string // returns DoubleToString(StringToDouble(string)) == string
bool IsSpecialIndex(UnicodeCache* unicode_cache, String* string); bool IsSpecialIndex(UnicodeCache* unicode_cache, String* string);
} } // namespace v8::internal
} // namespace internal
} // namespace v8
#endif // V8_CONVERSIONS_H_ #endif // V8_CONVERSIONS_H_

View File

@ -56,6 +56,11 @@ bool LayoutDescriptor::GetIndexes(int field_index, int* layout_word_index,
} }
LayoutDescriptor* LayoutDescriptor::SetRawData(int field_index) {
return SetTagged(field_index, false);
}
LayoutDescriptor* LayoutDescriptor::SetTagged(int field_index, bool tagged) { LayoutDescriptor* LayoutDescriptor::SetTagged(int field_index, bool tagged) {
int layout_word_index; int layout_word_index;
int layout_bit_index; int layout_bit_index;

View File

@ -124,9 +124,7 @@ class LayoutDescriptor : public FixedTypedArray<Uint32ArrayTraits> {
V8_INLINE bool GetIndexes(int field_index, int* layout_word_index, V8_INLINE bool GetIndexes(int field_index, int* layout_word_index,
int* layout_bit_index); int* layout_bit_index);
V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetRawData(int field_index) { V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetRawData(int field_index);
return SetTagged(field_index, false);
}
V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetTagged(int field_index, V8_INLINE MUST_USE_RESULT LayoutDescriptor* SetTagged(int field_index,
bool tagged); bool tagged);

View File

@ -67,13 +67,6 @@ bool TypeImpl<Config>::NowContains(i::Object* value) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ZoneTypeConfig // ZoneTypeConfig
// static
template<class T>
T* ZoneTypeConfig::null_handle() {
return NULL;
}
// static // static
template<class T> template<class T>
T* ZoneTypeConfig::handle(T* type) { T* ZoneTypeConfig::handle(T* type) {
@ -281,13 +274,6 @@ void ZoneTypeConfig::range_set_double(ZoneTypeConfig::Range* range, int index,
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// HeapTypeConfig // HeapTypeConfig
// static
template<class T>
i::Handle<T> HeapTypeConfig::null_handle() {
return i::Handle<T>();
}
// static // static
template<class T> template<class T>
i::Handle<T> HeapTypeConfig::handle(T* type) { i::Handle<T> HeapTypeConfig::handle(T* type) {

View File

@ -6,8 +6,8 @@
#define V8_TYPES_H_ #define V8_TYPES_H_
#include "src/conversions.h" #include "src/conversions.h"
#include "src/factory.h"
#include "src/handles.h" #include "src/handles.h"
#include "src/objects.h"
#include "src/ostreams.h" #include "src/ostreams.h"
namespace v8 { namespace v8 {
@ -1003,7 +1003,7 @@ struct ZoneTypeConfig {
static const int kRangeStructTag = 0x1000; static const int kRangeStructTag = 0x1000;
template<class T> static inline T* null_handle(); template<class T> static inline T* null_handle() { return nullptr; }
template<class T> static inline T* handle(T* type); template<class T> static inline T* handle(T* type);
template<class T> static inline T* cast(Type* type); template<class T> static inline T* cast(Type* type);
@ -1058,7 +1058,9 @@ struct HeapTypeConfig {
static const int kRangeStructTag = 0xffff; static const int kRangeStructTag = 0xffff;
template<class T> static inline i::Handle<T> null_handle(); template<class T> static inline i::Handle<T> null_handle() {
return i::Handle<T>();
}
template<class T> static inline i::Handle<T> handle(T* type); template<class T> static inline i::Handle<T> handle(T* type);
template<class T> static inline i::Handle<T> cast(i::Handle<Type> type); template<class T> static inline i::Handle<T> cast(i::Handle<Type> type);