Skip to content

Commit

Permalink
AK: Rename the common integer typedefs to make it obvious what they are.
Browse files Browse the repository at this point in the history
These types can be picked up by including <AK/Types.h>:

* u8, u16, u32, u64 (unsigned)
* i8, i16, i32, i64 (signed)
  • Loading branch information
awesomekling committed Jul 3, 2019
1 parent c4c4bbc commit 27f699e
Show file tree
Hide file tree
Showing 208 changed files with 1,605 additions and 1,623 deletions.
18 changes: 9 additions & 9 deletions AK/Bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace AK {
class Bitmap {
public:
// NOTE: A wrapping Bitmap won't try to free the wrapped data.
static Bitmap wrap(byte* data, int size)
static Bitmap wrap(u8* data, int size)
{
return Bitmap(data, size);
}
Expand Down Expand Up @@ -42,13 +42,13 @@ class Bitmap {
{
ASSERT(index < m_size);
if (value)
m_data[index / 8] |= static_cast<byte>((1u << (index % 8)));
m_data[index / 8] |= static_cast<u8>((1u << (index % 8)));
else
m_data[index / 8] &= static_cast<byte>(~(1u << (index % 8)));
m_data[index / 8] &= static_cast<u8>(~(1u << (index % 8)));
}

byte* data() { return m_data; }
const byte* data() const { return m_data; }
u8* data() { return m_data; }
const u8* data() const { return m_data; }

void grow(int size, bool default_value)
{
Expand All @@ -59,7 +59,7 @@ class Bitmap {
auto previous_data = m_data;

m_size = size;
m_data = reinterpret_cast<byte*>(kmalloc(size_in_bytes()));
m_data = reinterpret_cast<u8*>(kmalloc(size_in_bytes()));

fill(default_value);

Expand Down Expand Up @@ -123,11 +123,11 @@ class Bitmap {
, m_owned(true)
{
ASSERT(m_size != 0);
m_data = reinterpret_cast<byte*>(kmalloc(size_in_bytes()));
m_data = reinterpret_cast<u8*>(kmalloc(size_in_bytes()));
fill(default_value);
}

Bitmap(byte* data, int size)
Bitmap(u8* data, int size)
: m_data(data)
, m_size(size)
, m_owned(false)
Expand All @@ -136,7 +136,7 @@ class Bitmap {

int size_in_bytes() const { return ceil_div(m_size, 8); }

byte* m_data { nullptr };
u8* m_data { nullptr };
int m_size { 0 };
bool m_owned { false };
};
Expand Down
18 changes: 9 additions & 9 deletions AK/BufferStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ class BufferStream {
{
}

void operator<<(byte value)
void operator<<(u8 value)
{
m_buffer[m_offset++] = value & 0xffu;
}

void operator<<(char value)
{
m_buffer[m_offset++] = (byte)value;
m_buffer[m_offset++] = (u8)value;
}

void operator<<(word value)
void operator<<(u16 value)
{
m_buffer[m_offset++] = value & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu;
m_buffer[m_offset++] = (u8)(value >> 8) & 0xffu;
}

void operator<<(dword value)
void operator<<(u32 value)
{
m_buffer[m_offset++] = value & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 8) & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 16) & 0xffu;
m_buffer[m_offset++] = (byte)(value >> 24) & 0xffu;
m_buffer[m_offset++] = (u8)(value >> 8) & 0xffu;
m_buffer[m_offset++] = (u8)(value >> 16) & 0xffu;
m_buffer[m_offset++] = (u8)(value >> 24) & 0xffu;
}

void operator<<(const StringView& value)
Expand All @@ -53,7 +53,7 @@ class BufferStream {
return m_offset == m_buffer.size();
}

void fill_to_end(byte ch)
void fill_to_end(u8 ch)
{
while (!at_end())
m_buffer[m_offset++] = ch;
Expand Down
40 changes: 20 additions & 20 deletions AK/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ class ByteBufferImpl : public RefCounted<ByteBufferImpl> {
m_data = nullptr;
}

byte& operator[](int i)
u8& operator[](int i)
{
ASSERT(i < m_size);
return m_data[i];
}
const byte& operator[](int i) const
const u8& operator[](int i) const
{
ASSERT(i < m_size);
return m_data[i];
}
bool is_empty() const { return !m_size; }
int size() const { return m_size; }

byte* pointer() { return m_data; }
const byte* pointer() const { return m_data; }
u8* pointer() { return m_data; }
const u8* pointer() const { return m_data; }

byte* offset_pointer(int offset) { return m_data + offset; }
const byte* offset_pointer(int offset) const { return m_data + offset; }
u8* offset_pointer(int offset) { return m_data + offset; }
const u8* offset_pointer(int offset) const { return m_data + offset; }

void* end_pointer() { return m_data + m_size; }
const void* end_pointer() const { return m_data + m_size; }
Expand All @@ -71,7 +71,7 @@ class ByteBufferImpl : public RefCounted<ByteBufferImpl> {
ByteBufferImpl(void*, int, ConstructionMode); // For ConstructionMode=Wrap/Adopt
ByteBufferImpl() {}

byte* m_data { nullptr };
u8* m_data { nullptr };
int m_size { 0 };
bool m_owned { false };
};
Expand Down Expand Up @@ -114,27 +114,27 @@ class ByteBuffer {
bool operator!() const { return is_null(); }
bool is_null() const { return m_impl == nullptr; }

byte& operator[](int i)
u8& operator[](int i)
{
ASSERT(m_impl);
return (*m_impl)[i];
}
byte operator[](int i) const
u8 operator[](int i) const
{
ASSERT(m_impl);
return (*m_impl)[i];
}
bool is_empty() const { return !m_impl || m_impl->is_empty(); }
int size() const { return m_impl ? m_impl->size() : 0; }

byte* data() { return pointer(); }
const byte* data() const { return pointer(); }
u8* data() { return pointer(); }
const u8* data() const { return pointer(); }

byte* pointer() { return m_impl ? m_impl->pointer() : nullptr; }
const byte* pointer() const { return m_impl ? m_impl->pointer() : nullptr; }
u8* pointer() { return m_impl ? m_impl->pointer() : nullptr; }
const u8* pointer() const { return m_impl ? m_impl->pointer() : nullptr; }

byte* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const byte* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }
const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; }

void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; }
const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; }
Expand Down Expand Up @@ -191,21 +191,21 @@ class ByteBuffer {
inline ByteBufferImpl::ByteBufferImpl(int size)
: m_size(size)
{
m_data = static_cast<byte*>(kmalloc(size));
m_data = static_cast<u8*>(kmalloc(size));
m_owned = true;
}

inline ByteBufferImpl::ByteBufferImpl(const void* data, int size, ConstructionMode mode)
: m_size(size)
{
ASSERT(mode == Copy);
m_data = static_cast<byte*>(kmalloc(size));
m_data = static_cast<u8*>(kmalloc(size));
memcpy(m_data, data, size);
m_owned = true;
}

inline ByteBufferImpl::ByteBufferImpl(void* data, int size, ConstructionMode mode)
: m_data(static_cast<byte*>(data))
: m_data(static_cast<u8*>(data))
, m_size(size)
{
if (mode == Adopt) {
Expand All @@ -219,9 +219,9 @@ inline void ByteBufferImpl::grow(int size)
{
ASSERT(size > m_size);
ASSERT(m_owned);
byte* new_data = static_cast<byte*>(kmalloc(size));
u8* new_data = static_cast<u8*>(kmalloc(size));
memcpy(new_data, m_data, m_size);
byte* old_data = m_data;
u8* old_data = m_data;
m_data = new_data;
m_size = size;
kfree(old_data);
Expand Down
2 changes: 1 addition & 1 deletion AK/ELF/ELFImage.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ELFImage.h"
#include <AK/kstdio.h>

ELFImage::ELFImage(const byte* buffer)
ELFImage::ELFImage(const u8* buffer)
: m_buffer(buffer)
{
m_valid = parse();
Expand Down
20 changes: 10 additions & 10 deletions AK/ELF/ELFImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ELFImage {
public:
explicit ELFImage(const byte*);
explicit ELFImage(const u8*);
~ELFImage();
void dump();
bool is_valid() const { return m_valid; }
Expand Down Expand Up @@ -54,13 +54,13 @@ class ELFImage {
~ProgramHeader() {}

unsigned index() const { return m_program_header_index; }
dword type() const { return m_program_header.p_type; }
dword flags() const { return m_program_header.p_flags; }
dword offset() const { return m_program_header.p_offset; }
u32 type() const { return m_program_header.p_type; }
u32 flags() const { return m_program_header.p_flags; }
u32 offset() const { return m_program_header.p_offset; }
VirtualAddress vaddr() const { return VirtualAddress(m_program_header.p_vaddr); }
dword size_in_memory() const { return m_program_header.p_memsz; }
dword size_in_image() const { return m_program_header.p_filesz; }
dword alignment() const { return m_program_header.p_align; }
u32 size_in_memory() const { return m_program_header.p_memsz; }
u32 size_in_image() const { return m_program_header.p_filesz; }
u32 alignment() const { return m_program_header.p_align; }
bool is_readable() const { return flags() & PF_R; }
bool is_writable() const { return flags() & PF_W; }
bool is_executable() const { return flags() & PF_X; }
Expand Down Expand Up @@ -88,10 +88,10 @@ class ELFImage {
unsigned size() const { return m_section_header.sh_size; }
unsigned entry_size() const { return m_section_header.sh_entsize; }
unsigned entry_count() const { return !entry_size() ? 0 : size() / entry_size(); }
dword address() const { return m_section_header.sh_addr; }
u32 address() const { return m_section_header.sh_addr; }
const char* raw_data() const { return m_image.raw_data(m_section_header.sh_offset); }
bool is_undefined() const { return m_section_index == SHN_UNDEF; }
dword flags() const { return m_section_header.sh_flags; }
u32 flags() const { return m_section_header.sh_flags; }
bool is_writable() const { return flags() & SHF_WRITE; }
bool is_executable() const { return flags() & PF_X; }

Expand Down Expand Up @@ -134,7 +134,7 @@ class ELFImage {
const char* section_header_table_string(unsigned offset) const;
const char* section_index_to_string(unsigned index);

const byte* m_buffer { nullptr };
const u8* m_buffer { nullptr };
bool m_valid { false };
unsigned m_symbol_table_section_index { 0 };
unsigned m_string_table_section_index { 0 };
Expand Down
4 changes: 2 additions & 2 deletions AK/ELF/ELFLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

//#define ELFLOADER_DEBUG

ELFLoader::ELFLoader(const byte* buffer)
ELFLoader::ELFLoader(const u8* buffer)
: m_image(buffer)
{
}
Expand Down Expand Up @@ -81,7 +81,7 @@ char* ELFLoader::symbol_ptr(const char* name)
return found_ptr;
}

String ELFLoader::symbolicate(dword address) const
String ELFLoader::symbolicate(u32 address) const
{
SortedSymbol* sorted_symbols = nullptr;
#ifdef KERNEL
Expand Down
6 changes: 3 additions & 3 deletions AK/ELF/ELFLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Region;

class ELFLoader {
public:
explicit ELFLoader(const byte*);
explicit ELFLoader(const u8*);
~ELFLoader();

bool load();
Expand All @@ -26,7 +26,7 @@ class ELFLoader {

bool has_symbols() const { return m_image.symbol_count(); }

String symbolicate(dword address) const;
String symbolicate(u32 address) const;

private:
bool layout();
Expand All @@ -49,7 +49,7 @@ class ELFLoader {
ELFImage m_image;

struct SortedSymbol {
dword address;
u32 address;
const char* name;
};
#ifdef KERNEL
Expand Down
4 changes: 2 additions & 2 deletions AK/HashFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Types.h"

inline unsigned int_hash(dword key)
inline unsigned int_hash(u32 key)
{
key += ~(key << 15);
key ^= (key >> 10);
Expand All @@ -13,7 +13,7 @@ inline unsigned int_hash(dword key)
return key;
}

inline unsigned pair_int_hash(dword key1, dword key2)
inline unsigned pair_int_hash(u32 key1, u32 key2)
{
return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
}
18 changes: 9 additions & 9 deletions AK/IPv4Address.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ class [[gnu::packed]] IPv4Address
{
public:
IPv4Address() {}
IPv4Address(const byte data[4])
IPv4Address(const u8 data[4])
{
m_data[0] = data[0];
m_data[1] = data[1];
m_data[2] = data[2];
m_data[3] = data[3];
}
IPv4Address(byte a, byte b, byte c, byte d)
IPv4Address(u8 a, u8 b, u8 c, u8 d)
{
m_data[0] = a;
m_data[1] = b;
m_data[2] = c;
m_data[3] = d;
}
IPv4Address(NetworkOrdered<dword> address)
: m_data_as_dword(address)
IPv4Address(NetworkOrdered<u32> address)
: m_data_as_u32(address)
{
}

byte operator[](int i) const
u8 operator[](int i) const
{
ASSERT(i >= 0 && i < 4);
return m_data[i];
Expand All @@ -39,13 +39,13 @@ class [[gnu::packed]] IPv4Address
return String::format("%u.%u.%u.%u", m_data[0], m_data[1], m_data[2], m_data[3]);
}

bool operator==(const IPv4Address& other) const { return m_data_as_dword == other.m_data_as_dword; }
bool operator!=(const IPv4Address& other) const { return m_data_as_dword != other.m_data_as_dword; }
bool operator==(const IPv4Address& other) const { return m_data_as_u32 == other.m_data_as_u32; }
bool operator!=(const IPv4Address& other) const { return m_data_as_u32 != other.m_data_as_u32; }

private:
union {
byte m_data[4];
dword m_data_as_dword { 0 };
u8 m_data[4];
u32 m_data_as_u32 { 0 };
};
};

Expand Down
Loading

0 comments on commit 27f699e

Please sign in to comment.