Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions compiler/array-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ArraySizeResolver::ResolveRank(int rank, Expr* init)
// analysis.
return;
}
SetRankSize(expr, rank, expr->text()->length() + 1);
SetRankSize(expr, rank, (int)expr->text()->length() + 1);
return;
}

Expand All @@ -213,7 +213,7 @@ ArraySizeResolver::ResolveRank(int rank, Expr* init)
if (!type_->dim[rank] && expr->ellipses())
report(expr->pos(), 41);

SetRankSize(expr, rank, expr->exprs().size());
SetRankSize(expr, rank, (int)expr->exprs().size());

for (const auto& child : expr->exprs())
ResolveRank(rank + 1, child);
Expand Down Expand Up @@ -411,7 +411,7 @@ class FixedArrayValidator final
token_pos_t pos_;
Expr* init_;
const typeinfo_t& type_;
unsigned total_cells_ = 0;
size_t total_cells_ = 0;
Type* es_;
};

Expand Down Expand Up @@ -579,7 +579,7 @@ FixedArrayValidator::ValidateRank(int rank, Expr* init)
return false;
}

auto cells = char_array_cells(str->text()->length() + 1);
auto cells = char_array_cells((cell)str->text()->length() + 1);
if (!AddCells(cells))
return false;

Expand Down Expand Up @@ -651,7 +651,7 @@ FixedArrayValidator::ValidateRank(int rank, Expr* init)
prev1 = ke::Some(v.constval());
}

cell ncells = rank_size ? rank_size : array->exprs().size();
cell ncells = rank_size ? rank_size : (cell)array->exprs().size();
if (!AddCells(ncells))
return false;

Expand Down Expand Up @@ -733,7 +733,7 @@ FixedArrayValidator::ValidateEnumStruct(Expr* init)
bool
FixedArrayValidator::AddCells(size_t ncells)
{
if (!ke::IsUintAddSafe<uint32_t>(total_cells_, ncells)) {
if (!ke::IsUintAddSafe<size_t>(total_cells_, ncells)) {
report(pos_, 52);
return false;
}
Expand Down Expand Up @@ -891,7 +891,7 @@ class ArrayEmitter final

size_t AddString(StringExpr* expr);
void AddInlineArray(symbol* field, ArrayExpr* expr);
void EmitPadding(size_t rank_size, int tag, size_t emitted, bool ellipses,
void EmitPadding(int rank_size, int tag, size_t emitted, bool ellipses,
const ke::Maybe<cell> prev1, const ke::Maybe<cell> prev2);

private:
Expand Down Expand Up @@ -942,7 +942,7 @@ ArrayEmitter::Emit(int rank, Expr* init)
cell addr = Emit(rank + 1, child);
iv_[start + i] = addr;
}
return start * sizeof(cell);
return (cell)start * sizeof(cell);
}

size_t start = data_size();
Expand Down Expand Up @@ -1002,7 +1002,7 @@ ArrayEmitter::Emit(int rank, Expr* init)

EmitPadding(type_.dim[rank], type_.tag(), emitted, ellipses, prev1, prev2);

return (start * sizeof(cell)) | kDataFlag;
return (cell)(start * sizeof(cell)) | kDataFlag;
}

void
Expand All @@ -1022,7 +1022,7 @@ ArrayEmitter::AddInlineArray(symbol* field, ArrayExpr* array)
}

void
ArrayEmitter::EmitPadding(size_t rank_size, int tag, size_t emitted, bool ellipses,
ArrayEmitter::EmitPadding(int rank_size, int tag, size_t emitted, bool ellipses,
const ke::Maybe<cell> prev1, const ke::Maybe<cell> prev2)
{
// Pad remainder to zeroes if the array was explicitly sized.
Expand Down Expand Up @@ -1082,7 +1082,7 @@ BuildArrayInitializer(const typeinfo_t& type, Expr* init, ArrayData* array)

array->iv = std::move(emitter.iv());
array->data = std::move(emitter.data());
array->zeroes = emitter.pending_zeroes();
array->zeroes = (uint32_t)emitter.pending_zeroes();
}

void
Expand Down
26 changes: 13 additions & 13 deletions compiler/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ RttiBuilder::build_debuginfo()
});

// Finish up debug header statistics.
dbg_info_->header().num_files = dbg_files_->count();
dbg_info_->header().num_lines = dbg_lines_->count();
dbg_info_->header().num_files = (uint32_t)dbg_files_->count();
dbg_info_->header().num_lines = (uint32_t)dbg_lines_->count();
dbg_info_->header().num_syms = 0;
dbg_info_->header().num_arrays = 0;
}
Expand Down Expand Up @@ -410,7 +410,7 @@ RttiBuilder::add_method(symbol* sym)
{
assert(!sym->unused());

uint32_t index = methods_->count();
uint32_t index = (uint32_t)methods_->count();
smx_rtti_method& method = methods_->add();
method.name = names_->add(sym->nameAtom());
method.pcode_start = sym->addr();
Expand All @@ -422,7 +422,7 @@ RttiBuilder::add_method(symbol* sym)

smx_rtti_debug_method debug;
debug.method_index = index;
debug.first_local = dbg_locals_->count();
debug.first_local = (uint32_t)dbg_locals_->count();

for (auto& iter : *sym->function()->dbgstrs) {
const char* chars = iter.c_str();
Expand Down Expand Up @@ -457,12 +457,12 @@ RttiBuilder::add_enumstruct(Type* type)
return p->value;

symbol* sym = type->asEnumStruct();
uint32_t es_index = enumstructs_->count();
uint32_t es_index = (uint32_t)enumstructs_->count();
typeid_cache_.add(p, type, es_index);

smx_rtti_enumstruct es = {};
es.name = names_->add(*cc_.atoms(), type->name());
es.first_field = es_fields_->count();
es.first_field = (uint32_t)es_fields_->count();
es.size = sym->addr();
enumstructs_->add(es);

Expand Down Expand Up @@ -502,7 +502,7 @@ RttiBuilder::add_struct(Type* type)
if (p.found())
return p->value;

uint32_t struct_index = classdefs_->count();
uint32_t struct_index = (uint32_t)classdefs_->count();
typeid_cache_.add(p, type, struct_index);

pstruct_t* ps = type->as<pstruct_t>();
Expand All @@ -511,7 +511,7 @@ RttiBuilder::add_struct(Type* type)
memset(&classdef, 0, sizeof(classdef));
classdef.flags = kClassDefType_Struct;
classdef.name = names_->add(*cc_.atoms(), ps->name());
classdef.first_field = fields_->count();
classdef.first_field = (uint32_t)fields_->count();
classdefs_->add(classdef);

// Pre-reserve space in case we recursively add structs.
Expand Down Expand Up @@ -610,7 +610,7 @@ RttiBuilder::add_enum(Type* type)
if (p.found())
return p->value;

uint32_t index = enums_->count();
uint32_t index = (uint32_t)enums_->count();
typeid_cache_.add(p, type, index);

smx_rtti_enum entry;
Expand All @@ -628,7 +628,7 @@ RttiBuilder::add_funcenum(Type* type, funcenum_t* fe)
return p->value;

// Reserve slot beforehand in case the type is recursive.
uint32_t index = typedefs_->count();
uint32_t index = (uint32_t)typedefs_->count();
typeid_cache_.add(p, type, index);
typedefs_->add();

Expand All @@ -650,7 +650,7 @@ RttiBuilder::add_typeset(Type* type, funcenum_t* fe)
return p->value;

// Reserve slot beforehand in case the type is recursive.
uint32_t index = typesets_->count();
uint32_t index = (uint32_t)typesets_->count();
typeid_cache_.add(p, type, index);
typesets_->add();

Expand Down Expand Up @@ -1009,8 +1009,8 @@ assemble(CompileContext& cc, CodeGenerator& cg, const char* binfname, int compre
sp_file_hdr_t* header = (sp_file_hdr_t*)buffer.bytes();

if (compression_level) {
size_t region_size = header->imagesize - header->dataoffs;
size_t zbuf_max = compressBound(region_size);
uLong region_size = header->imagesize - header->dataoffs;
uLong zbuf_max = compressBound(region_size);
std::unique_ptr<Bytef[]> zbuf = std::make_unique<Bytef[]>(zbuf_max);

uLong new_disksize = zbuf_max;
Expand Down
6 changes: 5 additions & 1 deletion compiler/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ static void parseoptions(CompileContext& cc, int argc, char** argv) {

#if defined __WIN32__ || defined _WIN32 || defined _Windows
if (opt_hwnd.hasValue()) {
hwndFinish = (HWND)atoi(opt_hwnd.value().c_str());
#if defined _WIN64
hwndFinish = (HWND)std::stoull(opt_hwnd.value().c_str());
#else
hwndFinish = (HWND)std::stoi(opt_hwnd.value().c_str());
#endif
if (!IsWindow(hwndFinish))
hwndFinish = (HWND)0;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ int Lexer::LexInjectedToken() {
}

void Lexer::FillTokenPos(token_pos_t* pos) {
uint32_t offset = state_.pos - state_.start;
uint32_t offset = (uint32_t)(state_.pos - state_.start);
if (!state_.macro)
*pos = token_pos_t(state_.loc_range.FilePos(offset), state_.tokline);
else
Expand Down
2 changes: 2 additions & 0 deletions compiler/sci18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
#include "errors.h"
#include "sc.h"

#ifndef _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#endif

#if defined(__clang__)
# pragma clang diagnostic push
Expand Down
2 changes: 1 addition & 1 deletion compiler/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ bool Semantics::CheckArrayExpr(ArrayExpr* array) {
}

auto& val = array->val();
val.set_array(iARRAY, array->exprs().size());
val.set_array(iARRAY, (int)array->exprs().size());
val.tag = lasttag;
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/source-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ bool SourceFile::OffsetToLineAndCol(uint32_t offset, uint32_t* line, uint32_t* c
ComputeLineExtents();

if (offset == data_.size()) {
*line = line_extents_.size();
*line = (uint32_t)line_extents_.size();
if (col)
*col = 0;
return true;
}

uint32_t lower = 0;
uint32_t upper = line_extents_.size();
uint32_t upper = (uint32_t)line_extents_.size();
while (lower < upper) {
uint32_t index = (lower + upper) / 2;
uint32_t line_start = line_extents_[index];
Expand All @@ -168,7 +168,7 @@ bool SourceFile::OffsetToLineAndCol(uint32_t offset, uint32_t* line, uint32_t* c
// The range should be (start, end].
uint32_t line_end = (index < line_extents_.size() - 1)
? line_extents_[index + 1]
: data_.size();
: (uint32_t)data_.size();
if (offset >= line_end) {
lower = index + 1;
continue;
Expand Down Expand Up @@ -196,7 +196,7 @@ bool SourceFile::OffsetOfLine(uint32_t line, uint32_t* offset) {
return false;

if (line_index == line_extents_.size())
*offset = data_.size();
*offset = (uint32_t)data_.size();
else
*offset = line_extents_[line_index];
return true;
Expand All @@ -211,7 +211,7 @@ tr::string SourceFile::GetLine(uint32_t line) {

uint32_t end;
if (!OffsetOfLine(line + 1, &end))
end = data_.size();
end = (uint32_t)data_.size();

return data_.substr(offset, end - offset);
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/source-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool SourceManager::Open(const token_pos_t& from, std::shared_ptr<SourceFile> fi
return {};
}

file->set_sources_index(opened_files_.size());
file->set_sources_index((uint32_t)opened_files_.size());
opened_files_.emplace_back(file);
return true;
}
Expand All @@ -69,7 +69,7 @@ std::shared_ptr<SourceFile> SourceManager::Open(const std::string& name, tr::str

LocationRange SourceManager::EnterFile(std::shared_ptr<SourceFile> file, const token_pos_t& from) {
size_t loc_index;
if (!TrackExtents(file->size(), &loc_index)) {
if (!TrackExtents((uint32_t)file->size(), &loc_index)) {
report(from, 422);
return {};
}
Expand All @@ -84,7 +84,7 @@ LocationRange SourceManager::EnterMacro(const token_pos_t& from, SourceLocation
assert(expansion_loc.valid());

size_t lr_index;
if (!TrackExtents(text->length(), &lr_index)) {
if (!TrackExtents((uint32_t)text->length(), &lr_index)) {
report(from, 422);
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/source-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ struct LocationRange
if (!valid())
return 0;
if (is_macro())
return text_->length();
return file_->size();
return (uint32_t)text_->length();
return (uint32_t)file_->size();
}

bool owns(const SourceLocation& loc) const {
Expand Down
2 changes: 1 addition & 1 deletion compiler/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct structarg_t : public PoolObject

typeinfo_t type;
Atom* name;
unsigned int offs;
size_t offs;
int index;
};

Expand Down
4 changes: 2 additions & 2 deletions include/sp_vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ICallable
* @param flags Whether or not changes should be copied back to the input array.
* @return Error code, if any.
*/
virtual int PushArray(cell_t* inarray, unsigned int cells, int flags = 0) = 0;
virtual int PushArray(cell_t* inarray, size_t cells, int flags = 0) = 0;

/**
* @brief Pushes a string onto the current call.
Expand Down Expand Up @@ -740,7 +740,7 @@ class IPluginContext
* @param local_addr Will be filled with data offset to heap.
* @param phys_addr Physical address to heap memory.
*/
virtual int HeapAlloc(unsigned int cells, cell_t* local_addr, cell_t** phys_addr) = 0;
virtual int HeapAlloc(size_t cells, cell_t* local_addr, cell_t** phys_addr) = 0;

/**
* @brief Pops a heap address off the heap stack. Use this to free memory allocated with
Expand Down
20 changes: 10 additions & 10 deletions libsmx/smx-builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ SmxBuilder::write(ISmxBuffer* buf)
header.version = SmxConsts::SP1_VERSION_1_1;
header.compression = SmxConsts::FILE_COMPRESSION_NONE;

header.disksize = sizeof(header) +
sizeof(sp_file_section_t) * sections_.size();
header.disksize = (uint32_t)(sizeof(header) +
sizeof(sp_file_section_t) * sections_.size());

// Note that |dataoffs| here is just to mimic what it would be in earlier
// versions of Pawn. Its value does not actually matter per the SMX spec,
Expand All @@ -46,17 +46,17 @@ SmxBuilder::write(ISmxBuffer* buf)
size_t current_string_offset = 0;
for (size_t i = 0; i < sections_.size(); i++) {
RefPtr<SmxSection> section = sections_[i];
header.disksize += section->length();
header.disksize += (uint32_t)section->length();
current_string_offset += section->name().size() + 1;
}
header.disksize += current_string_offset;
header.dataoffs += current_string_offset;
header.disksize += (uint32_t)current_string_offset;
header.dataoffs += (uint32_t)current_string_offset;

header.imagesize = header.disksize;
header.sections = sections_.size();
header.sections = (uint8_t)sections_.size();

// We put the string table after the sections table.
header.stringtab = sizeof(header) + sizeof(sp_file_section_t) * sections_.size();
header.stringtab = (uint32_t)(sizeof(header) + sizeof(sp_file_section_t) * sections_.size());

if (!buf->write(&header, sizeof(header)))
return false;
Expand All @@ -68,9 +68,9 @@ SmxBuilder::write(ISmxBuffer* buf)
current_string_offset = 0;
for (size_t i = 0; i < sections_.size(); i++) {
sp_file_section_t s;
s.nameoffs = current_string_offset;
s.dataoffs = current_data_offset;
s.size = sections_[i]->length();
s.nameoffs = (uint32_t)current_string_offset;
s.dataoffs = (uint32_t)current_data_offset;
s.size = (uint32_t)sections_[i]->length();
if (!buf->write(&s, sizeof(s)))
return false;

Expand Down
Loading