Skip to content

Commit

Permalink
Fix clang formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Dodd authored and ChrisDodd committed Jan 17, 2023
1 parent 6c8e85c commit f1181a0
Show file tree
Hide file tree
Showing 706 changed files with 16,364 additions and 16,342 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ AccessModifierOffset: -3
IncludeBlocks: Regroup
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
PointerAlignment: Right
Standard: c++17
IncludeCategories:
# Matches common headers first and sorts them before project includes
Expand Down
72 changes: 36 additions & 36 deletions backends/bmv2/common/JsonObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ JsonObjects::JsonObjects() {
field_aliases = insert_array_field(toplevel, "field_aliases");
}

Util::JsonArray* JsonObjects::get_field_list_contents(unsigned id) const {
Util::JsonArray *JsonObjects::get_field_list_contents(unsigned id) const {
for (auto e : *field_lists) {
auto obj = e->to<Util::JsonObject>();
auto val = obj->get("id")->to<Util::JsonValue>();
Expand All @@ -63,7 +63,7 @@ Util::JsonArray* JsonObjects::get_field_list_contents(unsigned id) const {
return nullptr;
}

Util::JsonObject* JsonObjects::find_object_by_name(Util::JsonArray* array, const cstring& name) {
Util::JsonObject *JsonObjects::find_object_by_name(Util::JsonArray *array, const cstring &name) {
for (auto e : *array) {
auto obj = e->to<Util::JsonObject>();
auto val = obj->get("name")->to<Util::JsonValue>();
Expand All @@ -75,25 +75,25 @@ Util::JsonObject* JsonObjects::find_object_by_name(Util::JsonArray* array, const
}

/// Insert a json array to a parent object under key 'name'.
Util::JsonArray* JsonObjects::insert_array_field(Util::JsonObject* parent, cstring name) {
Util::JsonArray *JsonObjects::insert_array_field(Util::JsonObject *parent, cstring name) {
auto result = new Util::JsonArray();
parent->emplace(name, result);
return result;
}

/// Append a json array to a parent json array.
Util::JsonArray* JsonObjects::append_array(Util::JsonArray* parent) {
Util::JsonArray *JsonObjects::append_array(Util::JsonArray *parent) {
auto result = new Util::JsonArray();
parent->append(result);
return result;
}

/// Insert a json array named 'parameters' in a parent json object.
Util::JsonArray* JsonObjects::create_parameters(Util::JsonObject* object) {
Util::JsonArray *JsonObjects::create_parameters(Util::JsonObject *object) {
return insert_array_field(object, "parameters");
}

void JsonObjects::add_program_info(const cstring& name) { toplevel->emplace("program", name); }
void JsonObjects::add_program_info(const cstring &name) { toplevel->emplace("program", name); }

void JsonObjects::add_meta_info() {
static constexpr int version_major = JSON_MAJOR_VERSION;
Expand All @@ -113,7 +113,7 @@ void JsonObjects::add_meta_info() {
* if 0 header does not contain varbit fields
* @param fields a JsonArray for the fields in the header
*/
unsigned JsonObjects::add_header_type(const cstring& name, Util::JsonArray*& fields,
unsigned JsonObjects::add_header_type(const cstring &name, Util::JsonArray *&fields,
unsigned max_length) {
std::string sname(name, name.size());
auto header_type_id_it = header_type_id.find(sname);
Expand All @@ -136,7 +136,7 @@ unsigned JsonObjects::add_header_type(const cstring& name, Util::JsonArray*& fie
return id;
}

unsigned JsonObjects::add_union_type(const cstring& name, Util::JsonArray*& fields) {
unsigned JsonObjects::add_union_type(const cstring &name, Util::JsonArray *&fields) {
std::string sname(name, name.size());
auto it = union_type_id.find(sname);
if (it != union_type_id.end()) return it->second;
Expand All @@ -156,7 +156,7 @@ unsigned JsonObjects::add_union_type(const cstring& name, Util::JsonArray*& fiel
}

/// Create a header type with empty field list.
unsigned JsonObjects::add_header_type(const cstring& name) {
unsigned JsonObjects::add_header_type(const cstring &name) {
std::string sname(name, name.size());
auto header_type_id_it = header_type_id.find(sname);
if (header_type_id_it != header_type_id.end()) {
Expand All @@ -175,16 +175,16 @@ unsigned JsonObjects::add_header_type(const cstring& name) {

/// Create a set of fields to an existing header type.
/// The header type is decribed by the name.
void JsonObjects::add_header_field(const cstring& name, Util::JsonArray*& field) {
void JsonObjects::add_header_field(const cstring &name, Util::JsonArray *&field) {
CHECK_NULL(field);
Util::JsonObject* headerType = find_object_by_name(header_types, name);
Util::JsonArray* fields = headerType->get("fields")->to<Util::JsonArray>();
Util::JsonObject *headerType = find_object_by_name(header_types, name);
Util::JsonArray *fields = headerType->get("fields")->to<Util::JsonArray>();
BUG_CHECK(fields != nullptr, "header '%1%' not found", name);
fields->append(field);
}

/// Create a header instance in json.
unsigned JsonObjects::add_header(const cstring& type, const cstring& name) {
unsigned JsonObjects::add_header(const cstring &type, const cstring &name) {
auto header = new Util::JsonObject();
unsigned id = BMV2::nextId("headers");
LOG1("add header id " << id);
Expand All @@ -198,8 +198,8 @@ unsigned JsonObjects::add_header(const cstring& type, const cstring& name) {
}

/// Create a header_union instance in json.
unsigned JsonObjects::add_union(const cstring& type, Util::JsonArray*& headers,
const cstring& name) {
unsigned JsonObjects::add_union(const cstring &type, Util::JsonArray *&headers,
const cstring &name) {
auto u = new Util::JsonObject();
unsigned id = BMV2::nextId("header_unions");
LOG3("add header_union id " << id);
Expand All @@ -212,7 +212,7 @@ unsigned JsonObjects::add_union(const cstring& type, Util::JsonArray*& headers,
return id;
}

unsigned JsonObjects::add_metadata(const cstring& type, const cstring& name) {
unsigned JsonObjects::add_metadata(const cstring &type, const cstring &name) {
auto header = new Util::JsonObject();
unsigned id = BMV2::nextId("headers");
LOG3("add metadata header id " << id);
Expand All @@ -225,8 +225,8 @@ unsigned JsonObjects::add_metadata(const cstring& type, const cstring& name) {
return id;
}

void JsonObjects::add_header_stack(const cstring& type, const cstring& name, const unsigned size,
const std::vector<unsigned>& ids) {
void JsonObjects::add_header_stack(const cstring &type, const cstring &name, const unsigned size,
const std::vector<unsigned> &ids) {
auto stack = new Util::JsonObject();
unsigned id = BMV2::nextId("stack");
stack->emplace("name", name);
Expand All @@ -241,8 +241,8 @@ void JsonObjects::add_header_stack(const cstring& type, const cstring& name, con
header_stacks->append(stack);
}

void JsonObjects::add_header_union_stack(const cstring& type, const cstring& name,
const unsigned size, const std::vector<unsigned>& ids) {
void JsonObjects::add_header_union_stack(const cstring &type, const cstring &name,
const unsigned size, const std::vector<unsigned> &ids) {
auto stack = new Util::JsonObject();
unsigned id = BMV2::nextId("union_stack");
stack->emplace("name", name);
Expand All @@ -258,18 +258,18 @@ void JsonObjects::add_header_union_stack(const cstring& type, const cstring& nam
}

/// Add an error to json.
void JsonObjects::add_error(const cstring& name, const unsigned type) {
void JsonObjects::add_error(const cstring &name, const unsigned type) {
auto arr = append_array(errors);
arr->append(name);
arr->append(type);
}

/// Add a single enum entry to json.
/// A enum entry is identified with { enum_name, entry_name, entry_value }
void JsonObjects::add_enum(const cstring& enum_name, const cstring& entry_name,
void JsonObjects::add_enum(const cstring &enum_name, const cstring &entry_name,
const unsigned entry_value) {
// look up enum in json by name
Util::JsonObject* enum_json = find_object_by_name(enums, enum_name);
Util::JsonObject *enum_json = find_object_by_name(enums, enum_name);
if (enum_json == nullptr) { // first entry in a new enum
enum_json = new Util::JsonObject();
enum_json->emplace("name", enum_name);
Expand All @@ -290,7 +290,7 @@ void JsonObjects::add_enum(const cstring& enum_name, const cstring& entry_name,
}
}

unsigned JsonObjects::add_parser(const cstring& name) {
unsigned JsonObjects::add_parser(const cstring &name) {
auto parser = new Util::JsonObject();
unsigned id = BMV2::nextId("parser");
parser->emplace("name", name);
Expand All @@ -306,7 +306,7 @@ unsigned JsonObjects::add_parser(const cstring& name) {

/// insert parser state into a parser identified by parser_id
/// return the id of the parser state
unsigned JsonObjects::add_parser_state(const unsigned parser_id, const cstring& state_name) {
unsigned JsonObjects::add_parser_state(const unsigned parser_id, const cstring &state_name) {
if (map_parser.find(parser_id) == map_parser.end()) BUG("parser %1% not found.", parser_id);
auto parser = map_parser[parser_id];
auto states = parser->get("parse_states")->to<Util::JsonArray>();
Expand All @@ -326,7 +326,7 @@ unsigned JsonObjects::add_parser_state(const unsigned parser_id, const cstring&
return state_id;
}

void JsonObjects::add_parser_transition(const unsigned state_id, Util::IJson* transition) {
void JsonObjects::add_parser_transition(const unsigned state_id, Util::IJson *transition) {
if (map_parser_state.find(state_id) == map_parser_state.end())
BUG("parser state %1% not found.", state_id);
auto state = map_parser_state[state_id];
Expand All @@ -337,7 +337,7 @@ void JsonObjects::add_parser_transition(const unsigned state_id, Util::IJson* tr
transitions->append(trans);
}

void JsonObjects::add_parser_op(const unsigned state_id, Util::IJson* op) {
void JsonObjects::add_parser_op(const unsigned state_id, Util::IJson *op) {
if (map_parser_state.find(state_id) == map_parser_state.end())
BUG("parser state %1% not found.", state_id);
auto state = map_parser_state[state_id];
Expand All @@ -346,7 +346,7 @@ void JsonObjects::add_parser_op(const unsigned state_id, Util::IJson* op) {
statements->append(op);
}

void JsonObjects::add_parser_transition_key(const unsigned state_id, Util::IJson* newKey) {
void JsonObjects::add_parser_transition_key(const unsigned state_id, Util::IJson *newKey) {
if (map_parser_state.find(state_id) != map_parser_state.end()) {
auto state = map_parser_state[state_id];
auto keys = state->get("transition_key")->to<Util::JsonArray>();
Expand All @@ -358,8 +358,8 @@ void JsonObjects::add_parser_transition_key(const unsigned state_id, Util::IJson
}
}

void JsonObjects::add_parse_vset(const cstring& name, const unsigned bitwidth,
const big_int& size) {
void JsonObjects::add_parse_vset(const cstring &name, const unsigned bitwidth,
const big_int &size) {
auto parse_vset = new Util::JsonObject();
unsigned id = BMV2::nextId("parse_vsets");
parse_vset->emplace("name", name);
Expand All @@ -369,8 +369,8 @@ void JsonObjects::add_parse_vset(const cstring& name, const unsigned bitwidth,
parse_vsets->append(parse_vset);
}

unsigned JsonObjects::add_action(const cstring& name, Util::JsonArray*& params,
Util::JsonArray*& body) {
unsigned JsonObjects::add_action(const cstring &name, Util::JsonArray *&params,
Util::JsonArray *&body) {
CHECK_NULL(params);
CHECK_NULL(body);
auto action = new Util::JsonObject();
Expand All @@ -383,17 +383,17 @@ unsigned JsonObjects::add_action(const cstring& name, Util::JsonArray*& params,
return id;
}

void JsonObjects::add_extern_attribute(const cstring& name, const cstring& type,
const cstring& value, Util::JsonArray* attributes) {
void JsonObjects::add_extern_attribute(const cstring &name, const cstring &type,
const cstring &value, Util::JsonArray *attributes) {
auto attr = new Util::JsonObject();
attr->emplace("name", name);
attr->emplace("type", type);
attr->emplace("value", value);
attributes->append(attr);
}

void JsonObjects::add_extern(const cstring& name, const cstring& type,
Util::JsonArray* attributes) {
void JsonObjects::add_extern(const cstring &name, const cstring &type,
Util::JsonArray *attributes) {
auto extn = new Util::JsonObject();
unsigned id = BMV2::nextId("extern_instances");
extn->emplace("name", name);
Expand Down
114 changes: 57 additions & 57 deletions backends/bmv2/common/JsonObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,71 +26,71 @@ namespace BMV2 {

class JsonObjects {
public:
static Util::JsonObject* find_object_by_name(Util::JsonArray* array, const cstring& name);
static Util::JsonObject *find_object_by_name(Util::JsonArray *array, const cstring &name);

void add_program_info(const cstring& name);
void add_program_info(const cstring &name);
void add_meta_info();
unsigned add_header_type(const cstring& name, Util::JsonArray*& fields, unsigned max_length);
unsigned add_union_type(const cstring& name, Util::JsonArray*& fields);
unsigned add_union(const cstring& type, Util::JsonArray*& fields, const cstring& name);
unsigned add_header_type(const cstring& name);
void add_header_field(const cstring& name, Util::JsonArray*& field);
unsigned add_header(const cstring& type, const cstring& name);
unsigned add_metadata(const cstring& type, const cstring& name);
void add_header_stack(const cstring& type, const cstring& name, const unsigned size,
const std::vector<unsigned>& header_ids);
void add_header_union_stack(const cstring& type, const cstring& name, const unsigned size,
const std::vector<unsigned>& header_ids);
void add_error(const cstring& name, const unsigned type);
void add_enum(const cstring& enum_name, const cstring& entry_name, const unsigned entry_value);
unsigned add_parser(const cstring& name);
unsigned add_parser_state(const unsigned id, const cstring& state_name);
void add_parser_transition(const unsigned id, Util::IJson* transition);
void add_parser_op(const unsigned id, Util::IJson* op);
void add_parser_transition_key(const unsigned id, Util::IJson* key);
void add_parse_vset(const cstring& name, const unsigned bitwidth, const big_int& size);
unsigned add_action(const cstring& name, Util::JsonArray*& params, Util::JsonArray*& body);
void add_extern_attribute(const cstring& name, const cstring& type, const cstring& value,
Util::JsonArray* attributes);
void add_extern(const cstring& name, const cstring& type, Util::JsonArray* attributes);
unsigned add_header_type(const cstring &name, Util::JsonArray *&fields, unsigned max_length);
unsigned add_union_type(const cstring &name, Util::JsonArray *&fields);
unsigned add_union(const cstring &type, Util::JsonArray *&fields, const cstring &name);
unsigned add_header_type(const cstring &name);
void add_header_field(const cstring &name, Util::JsonArray *&field);
unsigned add_header(const cstring &type, const cstring &name);
unsigned add_metadata(const cstring &type, const cstring &name);
void add_header_stack(const cstring &type, const cstring &name, const unsigned size,
const std::vector<unsigned> &header_ids);
void add_header_union_stack(const cstring &type, const cstring &name, const unsigned size,
const std::vector<unsigned> &header_ids);
void add_error(const cstring &name, const unsigned type);
void add_enum(const cstring &enum_name, const cstring &entry_name, const unsigned entry_value);
unsigned add_parser(const cstring &name);
unsigned add_parser_state(const unsigned id, const cstring &state_name);
void add_parser_transition(const unsigned id, Util::IJson *transition);
void add_parser_op(const unsigned id, Util::IJson *op);
void add_parser_transition_key(const unsigned id, Util::IJson *key);
void add_parse_vset(const cstring &name, const unsigned bitwidth, const big_int &size);
unsigned add_action(const cstring &name, Util::JsonArray *&params, Util::JsonArray *&body);
void add_extern_attribute(const cstring &name, const cstring &type, const cstring &value,
Util::JsonArray *attributes);
void add_extern(const cstring &name, const cstring &type, Util::JsonArray *attributes);
JsonObjects();
Util::JsonArray* insert_array_field(Util::JsonObject* parent, cstring name);
Util::JsonArray* append_array(Util::JsonArray* parent);
Util::JsonArray* create_parameters(Util::JsonObject* object);
Util::JsonObject* create_primitive(Util::JsonArray* parent, cstring name);
Util::JsonArray *insert_array_field(Util::JsonObject *parent, cstring name);
Util::JsonArray *append_array(Util::JsonArray *parent);
Util::JsonArray *create_parameters(Util::JsonObject *object);
Util::JsonObject *create_primitive(Util::JsonArray *parent, cstring name);
// Given a field list id returns the array of values called "elements"
Util::JsonArray* get_field_list_contents(unsigned id) const;
Util::JsonArray *get_field_list_contents(unsigned id) const;

std::map<unsigned, Util::JsonObject*> map_parser;
std::map<unsigned, Util::JsonObject*> map_parser_state;
std::map<unsigned, Util::JsonObject *> map_parser;
std::map<unsigned, Util::JsonObject *> map_parser_state;

Util::JsonObject* toplevel;
Util::JsonObject* meta;
Util::JsonArray* actions;
Util::JsonArray* calculations;
Util::JsonArray* checksums;
Util::JsonArray* counters;
Util::JsonArray* deparsers;
Util::JsonArray* enums;
Util::JsonArray* errors;
Util::JsonArray* externs;
Util::JsonArray* field_lists;
Util::JsonArray* headers;
Util::JsonArray* header_stacks;
Util::JsonArray* header_types;
Util::JsonArray* header_union_types;
Util::JsonArray* header_unions;
Util::JsonArray* header_union_stacks;
Util::JsonObject *toplevel;
Util::JsonObject *meta;
Util::JsonArray *actions;
Util::JsonArray *calculations;
Util::JsonArray *checksums;
Util::JsonArray *counters;
Util::JsonArray *deparsers;
Util::JsonArray *enums;
Util::JsonArray *errors;
Util::JsonArray *externs;
Util::JsonArray *field_lists;
Util::JsonArray *headers;
Util::JsonArray *header_stacks;
Util::JsonArray *header_types;
Util::JsonArray *header_union_types;
Util::JsonArray *header_unions;
Util::JsonArray *header_union_stacks;
ordered_map<std::string, unsigned> header_type_id;
ordered_map<std::string, unsigned> union_type_id;
Util::JsonArray* learn_lists;
Util::JsonArray* meter_arrays;
Util::JsonArray* parsers;
Util::JsonArray* parse_vsets;
Util::JsonArray* pipelines;
Util::JsonArray* register_arrays;
Util::JsonArray* force_arith;
Util::JsonArray* field_aliases;
Util::JsonArray *learn_lists;
Util::JsonArray *meter_arrays;
Util::JsonArray *parsers;
Util::JsonArray *parse_vsets;
Util::JsonArray *pipelines;
Util::JsonArray *register_arrays;
Util::JsonArray *force_arith;
Util::JsonArray *field_aliases;
};

} // namespace BMV2
Expand Down
Loading

0 comments on commit f1181a0

Please sign in to comment.