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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: 'v17.0.3'
rev: 'v20.1.7'
hooks:
- id: clang-format
types_or:
Expand All @@ -12,7 +12,7 @@ repos:
- "json"

- repo: https://github.com/maxwinterstein/shfmt-py
rev: v3.7.0.1
rev: v3.11.0.2
hooks:
- id: shfmt
args: ["-w", "-i", "4", "-ci"]
Expand Down
4 changes: 2 additions & 2 deletions lib/binpac_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void FlowBuffer::ExpandBuffer(int length) {

// Allocate a new buffer and copy the existing contents
buffer_length_ = length;
unsigned char* new_buf = (unsigned char*)realloc(buffer_, buffer_length_);
unsigned char* new_buf = reinterpret_cast<unsigned char*>(realloc(buffer_, buffer_length_));

if ( ! new_buf )
throw ExceptionFlowBufferAlloc("expand realloc OOM");
Expand All @@ -114,7 +114,7 @@ void FlowBuffer::ContractBuffer() {
return;

buffer_length_ = policy.min_capacity;
unsigned char* new_buf = (unsigned char*)realloc(buffer_, buffer_length_);
unsigned char* new_buf = reinterpret_cast<unsigned char*>(realloc(buffer_, buffer_length_));

if ( ! new_buf )
throw ExceptionFlowBufferAlloc("contract realloc OOM");
Expand Down
8 changes: 5 additions & 3 deletions lib/binpac_bytestring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

namespace binpac {

std::string std_string(bytestring const* s) { return std::string((const char*)s->begin(), (const char*)s->end()); }
std::string std_string(bytestring const* s) {
return std::string(reinterpret_cast<const char*>(s->begin()), reinterpret_cast<const char*>(s->end()));
}

int bytestring_to_int(bytestring const* s) { return atoi((const char*)s->begin()); }
int bytestring_to_int(bytestring const* s) { return atoi(reinterpret_cast<const char*>(s->begin())); }

double bytestring_to_double(bytestring const* s) { return atof((const char*)s->begin()); }
double bytestring_to_double(bytestring const* s) { return atof(reinterpret_cast<const char*>(s->begin())); }

} // namespace binpac
13 changes: 7 additions & 6 deletions src/pac_analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "pac_action.h"
#include "pac_context.h"
#include "pac_dataunit.h"
#include "pac_embedded.h"
#include "pac_exception.h"
#include "pac_expr.h"
Expand Down Expand Up @@ -49,16 +50,16 @@ void AnalyzerDecl::AddElements(AnalyzerElementList* elemlist) {
switch ( elem->type() ) {
case AnalyzerElement::STATE: {
ASSERT(0);
AnalyzerState* state_elem = (AnalyzerState*)elem;
AnalyzerState* state_elem = dynamic_cast<AnalyzerState*>(elem);
statevars_->insert(statevars_->end(), state_elem->statevars()->begin(), state_elem->statevars()->end());
} break;
case AnalyzerElement::ACTION: {
ASSERT(0);
AnalyzerAction* action_elem = (AnalyzerAction*)elem;
AnalyzerAction* action_elem = dynamic_cast<AnalyzerAction*>(elem);
actions_->push_back(action_elem);
} break;
case AnalyzerElement::HELPER: {
AnalyzerHelper* helper_elem = (AnalyzerHelper*)elem;
AnalyzerHelper* helper_elem = dynamic_cast<AnalyzerHelper*>(elem);

switch ( helper_elem->helper_type() ) {
case AnalyzerHelper::INIT_CODE: constructor_helpers_->push_back(helper_elem); break;
Expand All @@ -68,17 +69,17 @@ void AnalyzerDecl::AddElements(AnalyzerElementList* elemlist) {
}
} break;
case AnalyzerElement::FUNCTION: {
AnalyzerFunction* func_elem = (AnalyzerFunction*)elem;
AnalyzerFunction* func_elem = dynamic_cast<AnalyzerFunction*>(elem);
Function* func = func_elem->function();
func->set_analyzer_decl(this);
functions_->push_back(func);
} break;
case AnalyzerElement::FLOW: {
AnalyzerFlow* flow_elem = (AnalyzerFlow*)elem;
AnalyzerFlow* flow_elem = dynamic_cast<AnalyzerFlow*>(elem);
ProcessFlowElement(flow_elem);
} break;
case AnalyzerElement::DATAUNIT: {
AnalyzerDataUnit* dataunit_elem = (AnalyzerDataUnit*)elem;
AnalyzerDataUnit* dataunit_elem = dynamic_cast<AnalyzerDataUnit*>(elem);
ProcessDataUnitElement(dataunit_elem);
} break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/pac_btype.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void BuiltInType::DoGenParseCode(Output* out_cc, Env* env, const DataPtr& data,

case INT8:
case UINT8:
out_cc->println("%s = *((%s const*)(%s));", lvalue(), DataTypeStr().c_str(), data.ptr_expr());
out_cc->println("%s = *(reinterpret_cast<%s const*>(%s));", lvalue(), DataTypeStr().c_str(),
data.ptr_expr());
break;
case INT16:
case UINT16:
Expand All @@ -109,8 +110,8 @@ void BuiltInType::DoGenParseCode(Output* out_cc, Env* env, const DataPtr& data,
data.ptr_expr(),
EvalByteOrder(out_cc, env).c_str());
#else
out_cc->println("%s = FixByteOrder(%s, *((%s const*)(%s)));", lvalue(), EvalByteOrder(out_cc, env).c_str(),
DataTypeStr().c_str(), data.ptr_expr());
out_cc->println("%s = FixByteOrder(%s, *(reinterpret_cast<%s const*>(%s)));", lvalue(),
EvalByteOrder(out_cc, env).c_str(), DataTypeStr().c_str(), data.ptr_expr());
#endif
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/pac_case.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void GenCaseStr(ExprList* index_list, Output* out_cc, Env* env, Type* switch_typ
case_type_width = case_type->StaticSize(env);

if ( case_type_width > switch_type_width ) {
BuiltInType* st = (BuiltInType*)switch_type;
BuiltInType* st = dynamic_cast<BuiltInType*>(switch_type);

if ( switch_type_width == 1 ) {
if ( st->bit_type() == BuiltInType::INT8 ) {
Expand Down
6 changes: 2 additions & 4 deletions src/pac_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class Decl : public Object {
virtual void Prepare() = 0;

// Generate declarations out of the "binpac" namespace
virtual void GenExternDeclaration(Output* out_h) { /* do nothing */
}
virtual void GenExternDeclaration(Output* out_h) { /* do nothing */ }

// Generate declarations before definition of classes
virtual void GenForwardDeclaration(Output* out_h) = 0;
Expand Down Expand Up @@ -65,8 +64,7 @@ class HelperDecl : public Decl {

void Prepare() override;
void GenExternDeclaration(Output* out_h) override;
void GenForwardDeclaration(Output* out_h) override { /* do nothing */
}
void GenForwardDeclaration(Output* out_h) override { /* do nothing */ }
void GenCode(Output* out_h, Output* out_cc) override;

private:
Expand Down
12 changes: 4 additions & 8 deletions src/pac_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,11 @@ class RecordPaddingField : public RecordField {

void Prepare(Env* env) override;

void GenPubDecls(Output* out, Env* env) override { /* nothing */
}
void GenPrivDecls(Output* out, Env* env) override { /* nothing */
}
void GenPubDecls(Output* out, Env* env) override { /* nothing */ }
void GenPrivDecls(Output* out, Env* env) override { /* nothing */ }

void GenInitCode(Output* out, Env* env) override { /* nothing */
}
void GenCleanUpCode(Output* out, Env* env) override { /* nothing */
}
void GenInitCode(Output* out, Env* env) override { /* nothing */ }
void GenCleanUpCode(Output* out, Env* env) override { /* nothing */ }
void GenParseCode(Output* out, Env* env) override;

int StaticSize(Env* env, int offset) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/pac_strtype.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ void StringType::DoGenParseCode(Output* out_cc, Env* env, const DataPtr& data, i
}

void StringType::GenStringMismatch(Output* out_cc, Env* env, const DataPtr& data, string pattern) {
string tmp =
strfmt("string((const char *) (%s), (const char *) %s).c_str()", data.ptr_expr(), env->RValue(end_of_data));
string tmp = strfmt("string(reinterpret_cast<const char*>(%s), reinterpret_cast<const char*>(%s)).c_str()",
data.ptr_expr(), env->RValue(end_of_data));
out_cc->println("throw binpac::ExceptionStringMismatch(\"%s\", %s, %s);", Location(), pattern.c_str(), tmp.c_str());
}

Expand Down
3 changes: 1 addition & 2 deletions src/pac_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ class Type : public Object, public DataDepElement {

void AddField(Field* f);

void AddCheck(Expr* expr) { /* TODO */
}
void AddCheck(Expr* expr) { /* TODO */ }

virtual bool DefineValueVar() const = 0;

Expand Down
6 changes: 2 additions & 4 deletions src/pac_varfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class ParseVarField : public Field {
public:
ParseVarField(int is_class_member, ID* id, Type* type)
: Field(PARSE_VAR_FIELD, TYPE_TO_BE_PARSED | is_class_member | NOT_PUBLIC_READABLE, id, type) {}
void GenPubDecls(Output* out, Env* env) override { /* do nothing */
}
void GenPubDecls(Output* out, Env* env) override { /* do nothing */ }
};

// A public variable
Expand All @@ -27,8 +26,7 @@ class PrivVarField : public Field {
: Field(PRIV_VAR_FIELD, TYPE_NOT_TO_BE_PARSED | CLASS_MEMBER | NOT_PUBLIC_READABLE, id, type) {}
~PrivVarField() override {}

void GenPubDecls(Output* out, Env* env) override { /* do nothing */
}
void GenPubDecls(Output* out, Env* env) override { /* do nothing */ }
};

class TempVarField : public Field {
Expand Down
Loading