Switch to size_t for sizes

This commit is contained in:
Duncan Ogilvie 2023-04-06 10:29:53 +02:00
parent 07a7b308e8
commit 74474b8dd6
2 changed files with 15 additions and 15 deletions

View File

@ -11,7 +11,7 @@ using namespace Types;
TypeManager::TypeManager(size_t pointerSize)
{
auto p = [this](const std::string & n, Primitive p, int size)
auto p = [this](const std::string & n, Primitive p, size_t size)
{
primitivesizes[p] = size;
auto splits = StringUtils::Split(n, ',');
@ -96,7 +96,7 @@ bool TypeManager::AddUnion(const std::string & owner, const std::string & name)
return addStructUnion(u);
}
bool TypeManager::AddMember(const std::string & parent, const QualifiedType& type, const std::string & name, int arrsize, int offset)
bool TypeManager::AddMember(const std::string & parent, const QualifiedType& type, const std::string & name, size_t arrsize, int offset)
{
if(!isDefined(type.name))
return false;
@ -129,7 +129,7 @@ bool TypeManager::AddMember(const std::string & parent, const QualifiedType& typ
pad.type = QualifiedType("char");
pad.arrsize = offset - s.size;
char padname[32] = "";
sprintf_s(padname, "padding%d", pad.arrsize);
sprintf_s(padname, "padding%zu", pad.arrsize);
pad.name = padname;
s.members.push_back(pad);
s.size += pad.arrsize;
@ -150,7 +150,7 @@ bool TypeManager::AddMember(const std::string & parent, const QualifiedType& typ
return true;
}
bool TypeManager::AppendMember(const QualifiedType& type, const std::string & name, int arrsize, int offset)
bool TypeManager::AppendMember(const QualifiedType& type, const std::string & name, size_t arrsize, int offset)
{
return AddMember(laststruct, type, name, arrsize, offset);
}
@ -213,7 +213,7 @@ bool TypeManager::AppendArg(const QualifiedType& type, const std::string & name)
return AddArg(lastfunction, type, name);
}
int TypeManager::Sizeof(const std::string& type) const
size_t TypeManager::Sizeof(const std::string& type) const
{
auto foundT = types.find(type);
if(foundT != types.end())
@ -227,7 +227,7 @@ int TypeManager::Sizeof(const std::string& type) const
return 0;
}
int TypeManager::Sizeof(const QualifiedType& type) const
size_t TypeManager::Sizeof(const QualifiedType& type) const
{
if (type.isPointer())
return primitivesizes.at(Pointer);

View File

@ -32,7 +32,7 @@ namespace Types
std::string owner; //Type owner
std::string name; //Type identifier.
Primitive primitive = Void; //Primitive type.
int size = 0; //Size in bytes.
size_t size = 0; //Size in bytes.
};
struct QualifiedType
@ -91,7 +91,7 @@ namespace Types
{
std::string name; //Member identifier
QualifiedType type; // Qualified Type
int arrsize = 0; //Number of elements if Member is an array (unused for function arguments)
size_t arrsize = 0; //Number of elements if Member is an array (unused for function arguments)
int offset = -1; //Member offset (only stored for reference)
};
@ -122,7 +122,7 @@ namespace Types
std::vector<Member> members; //StructUnion members
std::vector<Function> vtable;
bool isunion = false; //Is this a union?
int size = 0;
size_t size = 0;
};
struct EnumValue
@ -164,7 +164,7 @@ namespace Types
std::string kind;
std::string name;
std::string owner;
int size = 0;
size_t size = 0;
};
explicit TypeManager(size_t pointerSize);
@ -173,14 +173,14 @@ namespace Types
bool AddEnum(const std::string& owner, const std::string& name, const std::string & type);
bool AddStruct(const std::string & owner, const std::string & name);
bool AddUnion(const std::string & owner, const std::string & name);
bool AddMember(const std::string & parent, const QualifiedType & type, const std::string & name, int arrsize = 0, int offset = -1);
bool AppendMember(const QualifiedType & type, const std::string & name, int arrsize = 0, int offset = -1);
bool AddMember(const std::string & parent, const QualifiedType & type, const std::string & name, size_t arrsize = 0, int offset = -1);
bool AppendMember(const QualifiedType & type, const std::string & name, size_t arrsize = 0, int offset = -1);
bool AddFunction(const std::string & owner, const std::string & name, const QualifiedType& rettype, CallingConvention callconv = Cdecl, bool noreturn = false, bool typeonly = false);
bool AddEnumerator(const std::string& enumType, const std::string& name, uint64_t value);
bool AddArg(const std::string & function, const QualifiedType & type, const std::string & name);
bool AppendArg(const QualifiedType& type, const std::string & name);
int Sizeof(const QualifiedType& type) const;
int Sizeof(const std::string& type) const;
size_t Sizeof(const QualifiedType& type) const;
size_t Sizeof(const std::string& type) const;
bool Visit(const std::string & type, const std::string & name, Visitor & visitor) const;
void Clear(const std::string & owner = "");
bool RemoveType(const std::string & type);
@ -191,7 +191,7 @@ namespace Types
bool GenerateStubs() const;
private:
std::unordered_map<Primitive, int> primitivesizes;
std::unordered_map<Primitive, size_t> primitivesizes;
std::unordered_map<Primitive, std::string> primitivenames;
std::unordered_map<std::string, Type> types;
std::unordered_map<std::string, Types::Enum> enums;