[vm] Update to constexpr in runtime/platform and lib.

TEST=build
Change-Id: I61ebb04f414d36813a99b424fb1bcdb440f68ad5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293801
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
Ryan Macnak 2023-04-11 17:43:58 +00:00 committed by Commit Queue
parent 96fd0b2208
commit 8b0f4a8c61
10 changed files with 60 additions and 59 deletions

View file

@ -173,8 +173,8 @@ DEFINE_NATIVE_ENTRY(Double_toString, 0, 1) {
DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 0, 2) {
// The boundaries are exclusive.
static const double kLowerBoundary = -1e21;
static const double kUpperBoundary = 1e21;
const double kLowerBoundary = -1e21;
const double kUpperBoundary = 1e21;
const Double& arg = Double::CheckedHandle(zone, arguments->NativeArgAt(0));
GET_NON_NULL_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->NativeArgAt(1));

View file

@ -16,7 +16,7 @@ namespace dart {
DECLARE_FLAG(bool, show_invisible_frames);
static const intptr_t kDefaultStackAllocation = 8;
static constexpr intptr_t kDefaultStackAllocation = 8;
static StackTracePtr CreateStackTraceObject(
Zone* zone,

View file

@ -121,8 +121,8 @@ static uint16_t CharacterLimit(const String& string,
return result;
}
static const intptr_t kLengthSize = 11;
static const intptr_t kLengthMask = (1 << kLengthSize) - 1;
static constexpr intptr_t kLengthSize = 11;
static constexpr intptr_t kLengthMask = (1 << kLengthSize) - 1;
static bool CheckSlicesOneByte(const String& base,
const Array& matches,

View file

@ -157,12 +157,12 @@ struct Note {
static constexpr intptr_t ELFCLASS32 = 1;
static constexpr intptr_t ELFCLASS64 = 2;
static const intptr_t EI_DATA = 5;
static const intptr_t ELFDATA2LSB = 1;
static constexpr intptr_t EI_DATA = 5;
static constexpr intptr_t ELFDATA2LSB = 1;
static const intptr_t ELFOSABI_SYSV = 0;
static constexpr intptr_t ELFOSABI_SYSV = 0;
static const intptr_t ET_DYN = 3;
static constexpr intptr_t ET_DYN = 3;
static constexpr intptr_t EF_ARM_ABI_FLOAT_HARD = 0x00000400;
static constexpr intptr_t EF_ARM_ABI_FLOAT_SOFT = 0x00000200;
@ -174,27 +174,27 @@ static constexpr intptr_t EM_X86_64 = 62;
static constexpr intptr_t EM_AARCH64 = 183;
static constexpr intptr_t EM_RISCV = 243;
static const intptr_t EV_CURRENT = 1;
static constexpr intptr_t EV_CURRENT = 1;
static const intptr_t PF_X = 1;
static const intptr_t PF_W = 2;
static const intptr_t PF_R = 4;
static constexpr intptr_t PF_X = 1;
static constexpr intptr_t PF_W = 2;
static constexpr intptr_t PF_R = 4;
static const intptr_t SHF_WRITE = 0x1;
static const intptr_t SHF_ALLOC = 0x2;
static const intptr_t SHF_EXECINSTR = 0x4;
static constexpr intptr_t SHF_WRITE = 0x1;
static constexpr intptr_t SHF_ALLOC = 0x2;
static constexpr intptr_t SHF_EXECINSTR = 0x4;
static const intptr_t SHN_UNDEF = 0;
static constexpr intptr_t SHN_UNDEF = 0;
static const intptr_t STN_UNDEF = 0;
static constexpr intptr_t STN_UNDEF = 0;
static const intptr_t STB_LOCAL = 0;
static const intptr_t STB_GLOBAL = 1;
static constexpr intptr_t STB_LOCAL = 0;
static constexpr intptr_t STB_GLOBAL = 1;
static const intptr_t STT_NOTYPE = 0;
static const intptr_t STT_OBJECT = 1; // I.e., data.
static const intptr_t STT_FUNC = 2;
static const intptr_t STT_SECTION = 3;
static constexpr intptr_t STT_NOTYPE = 0;
static constexpr intptr_t STT_OBJECT = 1; // I.e., data.
static constexpr intptr_t STT_FUNC = 2;
static constexpr intptr_t STT_SECTION = 3;
static constexpr const char ELF_NOTE_GNU[] = "GNU";

View file

@ -27,8 +27,8 @@ struct mach_header {
uint32_t flags;
};
static const uint32_t MH_MAGIC = 0xfeedface;
static const uint32_t MH_CIGAM = 0xcefaedfe;
static constexpr uint32_t MH_MAGIC = 0xfeedface;
static constexpr uint32_t MH_CIGAM = 0xcefaedfe;
struct mach_header_64 {
uint32_t magic;
@ -41,15 +41,15 @@ struct mach_header_64 {
uint32_t reserved;
};
static const uint32_t MH_MAGIC_64 = 0xfeedfacf;
static const uint32_t MH_CIGAM_64 = 0xcffaedfe;
static constexpr uint32_t MH_MAGIC_64 = 0xfeedfacf;
static constexpr uint32_t MH_CIGAM_64 = 0xcffaedfe;
struct load_command {
uint32_t cmd;
uint32_t cmdsize;
};
static const uint32_t LC_NOTE = 0x31;
static constexpr uint32_t LC_NOTE = 0x31;
struct note_command {
uint32_t cmd;
uint32_t cmdsize;

View file

@ -13,7 +13,7 @@ namespace pe {
#pragma pack(push, 1)
static const intptr_t kPEOffsetOffset = 0x3c;
static constexpr intptr_t kPEOffsetOffset = 0x3c;
static const char kPEMagic[] = {'P', 'E', '\0', '\0'};
struct coff_file_header {
@ -39,10 +39,10 @@ struct coff_optional_header {
uint32_t code_base_address;
};
static const uint16_t kPE32Magic = 0x10b;
static const uint16_t kPE32PlusMagic = 0x20b;
static constexpr uint16_t kPE32Magic = 0x10b;
static constexpr uint16_t kPE32PlusMagic = 0x20b;
static const intptr_t kCoffSectionNameSize = 8;
static constexpr intptr_t kCoffSectionNameSize = 8;
struct coff_section_header {
char name[kCoffSectionNameSize];

View file

@ -24,7 +24,7 @@ namespace dart {
template <typename P, typename V>
class PriorityQueue {
public:
static const intptr_t kMinimumSize = 16;
static constexpr intptr_t kMinimumSize = 16;
struct Entry {
P priority;

View file

@ -214,7 +214,7 @@ void BaseTextBuffer::EscapeAndAddCodeUnit(uint32_t codeunit) {
buffer_[length_++] = 't';
break;
default:
static constexpr int kMask = ~(1 << 6);
constexpr int kMask = ~(1 << 6);
if (codeunit < 0x20) {
ASSERT(remaining > 6);
buffer_[length_++] = '\\';

View file

@ -108,7 +108,7 @@ intptr_t Utf8::Length(int32_t ch) {
}
intptr_t Utf8::Encode(int32_t ch, char* dst) {
static const int kMask = ~(1 << 6);
constexpr int kMask = ~(1 << 6);
if (ch <= kMaxOneByteChar) {
dst[0] = ch;
return 1;

View file

@ -15,10 +15,10 @@ class String;
class Utf : AllStatic {
public:
static const int32_t kMaxCodePoint = 0x10FFFF;
static const int32_t kInvalidChar = 0xFFFFFFFF;
static constexpr int32_t kMaxCodePoint = 0x10FFFF;
static constexpr int32_t kInvalidChar = 0xFFFFFFFF;
static const int32_t kReplacementChar = 0xFFFD;
static constexpr int32_t kReplacementChar = 0xFFFD;
static bool IsLatin1(int32_t code_point) {
return (code_point >= 0) && (code_point <= 0xFF);
@ -83,10 +83,10 @@ class Utf8 : AllStatic {
intptr_t len);
static bool DecodeCStringToUTF32(const char* str, int32_t* dst, intptr_t len);
static const int32_t kMaxOneByteChar = 0x7F;
static const int32_t kMaxTwoByteChar = 0x7FF;
static const int32_t kMaxThreeByteChar = 0xFFFF;
static const int32_t kMaxFourByteChar = Utf::kMaxCodePoint;
static constexpr int32_t kMaxOneByteChar = 0x7F;
static constexpr int32_t kMaxTwoByteChar = 0x7FF;
static constexpr int32_t kMaxThreeByteChar = 0xFFFF;
static constexpr int32_t kMaxFourByteChar = Utf::kMaxCodePoint;
private:
static bool IsTrailByte(uint8_t code_unit) {
@ -155,16 +155,17 @@ class Utf16 : AllStatic {
// Encodes a single code point.
static void Encode(int32_t codepoint, uint16_t* dst);
static const int32_t kMaxCodeUnit = 0xFFFF;
static const int32_t kLeadSurrogateStart = 0xD800;
static const int32_t kLeadSurrogateEnd = 0xDBFF;
static const int32_t kTrailSurrogateStart = 0xDC00;
static const int32_t kTrailSurrogateEnd = 0xDFFF;
static constexpr int32_t kMaxCodeUnit = 0xFFFF;
static constexpr int32_t kLeadSurrogateStart = 0xD800;
static constexpr int32_t kLeadSurrogateEnd = 0xDBFF;
static constexpr int32_t kTrailSurrogateStart = 0xDC00;
static constexpr int32_t kTrailSurrogateEnd = 0xDFFF;
private:
static const int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10));
static constexpr int32_t kLeadSurrogateOffset = (0xD800 - (0x10000 >> 10));
static const int32_t kSurrogateOffset = (0x10000 - (0xD800 << 10) - 0xDC00);
static constexpr int32_t kSurrogateOffset =
(0x10000 - (0xD800 << 10) - 0xDC00);
};
class CaseMapping : AllStatic {
@ -181,25 +182,25 @@ class CaseMapping : AllStatic {
private:
// Property is a delta to the uppercase mapping.
static const int32_t kUppercase = 1;
static constexpr int32_t kUppercase = 1;
// Property is a delta to the uppercase mapping.
static const int32_t kLowercase = 2;
static constexpr int32_t kLowercase = 2;
// Property is an index into the exception table.
static const int32_t kException = 3;
static constexpr int32_t kException = 3;
// Type bit-field parameters
static const int32_t kTypeShift = 2;
static const int32_t kTypeMask = 3;
static constexpr int32_t kTypeShift = 2;
static constexpr int32_t kTypeMask = 3;
// The size of the stage 1 index.
// TODO(cshapiro): improve indexing so this value is unnecessary.
static const intptr_t kStage1Size = 261;
static constexpr intptr_t kStage1Size = 261;
// The size of a stage 2 block in bytes.
static const intptr_t kBlockSizeLog2 = 8;
static const intptr_t kBlockSize = 1 << kBlockSizeLog2;
static constexpr intptr_t kBlockSizeLog2 = 8;
static constexpr intptr_t kBlockSize = 1 << kBlockSizeLog2;
static int32_t Convert(int32_t ch, int32_t mapping) {
if (Utf::IsLatin1(ch)) {
@ -232,7 +233,7 @@ class CaseMapping : AllStatic {
class Latin1 {
public:
static const int32_t kMaxChar = 0xff;
static constexpr int32_t kMaxChar = 0xff;
// Convert the character to Latin-1 case equivalent if possible.
static inline uint16_t TryConvertToLatin1(uint16_t c) {
switch (c) {