clang-tidy

This commit is contained in:
Thomas Krijnen
2024-08-21 11:22:18 +02:00
parent 2e27ff64b4
commit fac13f1e1f
12 changed files with 66 additions and 70 deletions
+19 -19
View File
@@ -44,7 +44,7 @@
#define ARBITRARY (1 << 7)
#define EXTENDED2 (1 << 8)
#define EXTENDED4 (1 << 9)
#define HEX(N) (1 << (9 + N))
#define HEX(N) (1 << (9 + (N)))
#define THIRD_SOLIDUS (1 << 18)
#define ENDEXTENDED_X (1 << 19)
#define ENDEXTENDED_0 (1 << 20)
@@ -52,22 +52,22 @@
#define ENCOUNTERED_HEX (1 << 23)
// FIXME: These probably need to be less forgiving in terms of wrongly defined sequences
#define EXPECTS_ALPHABET(S) (S & FIRST_SOLIDUS)
#define EXPECTS_PAGE(S) (S & FIRST_SOLIDUS)
#define EXPECTS_ARBITRARY(S) (S & FIRST_SOLIDUS)
#define EXPECTS_N_OR_F(S) (S & FIRST_SOLIDUS && !(S & ARBITRARY))
#define EXPECTS_ARBITRARY2(S) (S & ARBITRARY && !(S & SECOND_SOLIDUS))
#define EXPECTS_ALPHABET_DEFINITION(S) (S & FIRST_SOLIDUS && S & ALPHABET)
#define EXPECTS_SOLIDUS(S) (S & ALPHABET_DEFINITION || S & PAGE || S & ARBITRARY || S & EXTENDED2 || S & EXTENDED4 || S & ENDEXTENDED_0 || S & IGNORED_DIRECTIVE || (S & EXTENDED4 && S & HEX(8)) || (S & EXTENDED2 && S & HEX(4)))
#define EXPECTS_CHARACTER(S) (S & PAGE && S & SECOND_SOLIDUS)
#define EXPECTS_HEX(S) (S & HEX(1) || S & HEX(3) || S & HEX(5) || S & HEX(6) || S & HEX(7) || (S & ARBITRARY && S & SECOND_SOLIDUS) || (S & EXTENDED2 && S & HEX(2)) || (S & EXTENDED4 && S & HEX(4)))
#define EXPECTS_ENDEXTENDED_X(S) (S & THIRD_SOLIDUS)
#define EXPECTS_ENDEXTENDED_0(S) (S & ENDEXTENDED_X)
#define EXPECTS_ALPHABET(S) ((S) & FIRST_SOLIDUS)
#define EXPECTS_PAGE(S) ((S) & FIRST_SOLIDUS)
#define EXPECTS_ARBITRARY(S) ((S) & FIRST_SOLIDUS)
#define EXPECTS_N_OR_F(S) ((S) & FIRST_SOLIDUS && !((S) & ARBITRARY))
#define EXPECTS_ARBITRARY2(S) ((S) & ARBITRARY && !((S) & SECOND_SOLIDUS))
#define EXPECTS_ALPHABET_DEFINITION(S) ((S) & FIRST_SOLIDUS && (S) & ALPHABET)
#define EXPECTS_SOLIDUS(S) ((S) & ALPHABET_DEFINITION || (S) & PAGE || (S) & ARBITRARY || (S) & EXTENDED2 || (S) & EXTENDED4 || (S) & ENDEXTENDED_0 || (S) & IGNORED_DIRECTIVE || ((S) & EXTENDED4 && (S) & HEX(8)) || ((S) & EXTENDED2 && (S) & HEX(4)))
#define EXPECTS_CHARACTER(S) ((S) & PAGE && (S) & SECOND_SOLIDUS)
#define EXPECTS_HEX(S) ((S) & HEX(1) || (S) & HEX(3) || (S) & HEX(5) || (S) & HEX(6) || (S) & HEX(7) || ((S) & ARBITRARY && (S) & SECOND_SOLIDUS) || ((S) & EXTENDED2 && (S) & HEX(2)) || ((S) & EXTENDED4 && (S) & HEX(4)))
#define EXPECTS_ENDEXTENDED_X(S) ((S) & THIRD_SOLIDUS)
#define EXPECTS_ENDEXTENDED_0(S) ((S) & ENDEXTENDED_X)
#define IS_VALID_ALPHABET_DEFINITION(C) (C >= 0x41 && C <= 0x49)
#define IS_HEXADECIMAL(C) ((C >= 0x30 && C <= 0x39) || (C >= 0x41 && C <= 0x46))
#define HEX_TO_INT(C) ((C >= 0x30 && C <= 0x39) ? C - 0x30 : (C + 10) - 0x41)
#define CLEAR_HEX(C) (C &= ~(HEX(1) | HEX(2) | HEX(3) | HEX(4) | HEX(5) | HEX(6) | HEX(7) | HEX(8)))
#define IS_VALID_ALPHABET_DEFINITION(C) ((C) >= 0x41 && (C) <= 0x49)
#define IS_HEXADECIMAL(C) (((C) >= 0x30 && (C) <= 0x39) || ((C) >= 0x41 && (C) <= 0x46))
#define HEX_TO_INT(C) (((C) >= 0x30 && (C) <= 0x39) ? (C) - 0x30 : ((C) + 10) - 0x41)
#define CLEAR_HEX(C) ((C) &= ~(HEX(1) | HEX(2) | HEX(3) | HEX(4) | HEX(5) | HEX(6) | HEX(7) | HEX(8)))
using namespace IfcParse;
@@ -80,7 +80,7 @@ IfcCharacterDecoder::~IfcCharacterDecoder() {
}
namespace {
static unsigned int reference_helper = 0;
unsigned int reference_helper = 0;
class pure_impure_helper {
private:
@@ -446,9 +446,9 @@ std::u32string IfcUtil::convert_utf8_to_utf32(const std::string& s) {
}
if (is_ascii) {
return std::u32string(s.begin(), s.end());
} else {
}
return std::wstring_convert<std::codecvt_utf8<std::u32string::value_type>, std::u32string::value_type>().from_bytes(s);
}
}
#endif
+2 -2
View File
@@ -14,8 +14,8 @@ public:
int operator()(const double& /*i*/) const { return -1; }
int operator()(const std::string& /*i*/) const { return -1; }
int operator()(const boost::dynamic_bitset<>& /*i*/) const { return -1; }
int operator()(const empty_aggregate_t&) const { return 0; }
int operator()(const empty_aggregate_of_aggregate_t&) const { return 0; }
int operator()(const empty_aggregate_t& /*unused*/) const { return 0; }
int operator()(const empty_aggregate_of_aggregate_t& /*unused*/) const { return 0; }
int operator()(const std::vector<int>& i) const { return (int)i.size(); }
int operator()(const std::vector<double>& i) const { return (int)i.size(); }
int operator()(const std::vector<std::vector<int>>& i) const { return (int)i.size(); }
+11 -11
View File
@@ -80,7 +80,7 @@ namespace {
target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_INT ||
target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_DOUBLE ||
target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE;
} else if (source == IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE) {
} if (source == IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE) {
return target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_INT ||
target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_DOUBLE ||
target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE;
@@ -237,9 +237,9 @@ namespace {
IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_references& references_to_resolve, const IfcParse::declaration* decl) {
std::vector<const IfcParse::parameter_type*> parameter_types;
if (decl && decl->as_type_declaration()) {
if ((decl != nullptr) && (decl->as_type_declaration() != nullptr)) {
parameter_types = { decl->as_type_declaration()->declared_type() };
} else if (decl && decl->as_entity()) {
} else if ((decl != nullptr) && (decl->as_entity() != nullptr)) {
auto entity_attrs = decl->as_entity()->all_attributes();
std::transform(
entity_attrs.begin(),
@@ -251,32 +251,32 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re
);
}
if (decl && (tokens_.size() != parameter_types.size())) {
if ((decl != nullptr) && (tokens_.size() != parameter_types.size())) {
// warning
}
if (tokens_.size() == 0) {
if (tokens_.empty()) {
return IfcEntityInstanceData(storage_t(0));
}
storage_t storage(decl
storage_t storage(decl != nullptr
? (std::min)(parameter_types.size(), tokens_.size())
: tokens_.size()
);
auto it = tokens_.begin();
auto kt = parameter_types.begin();
for (; it != tokens_.end() && (!decl || kt != parameter_types.end()); ++it) {
for (; it != tokens_.end() && ((decl == nullptr) || kt != parameter_types.end()); ++it) {
auto& token = *it;
// @todo coerce to expected type, e.g empty -> std::vector<int>, bool -> logical
const IfcParse::parameter_type* param_type = nullptr;
if (decl) {
if (decl != nullptr) {
param_type = *kt;
}
auto index = (uint8_t) std::distance(tokens_.begin(), it);
boost::apply_visitor([this, &storage, name, &references_to_resolve, index, it, param_type](auto& v) {
boost::apply_visitor([this, &storage, name, &references_to_resolve, index, param_type](auto& v) {
if constexpr (std::is_same_v<std::decay_t<decltype(v)>, IfcParse::Token>) {
dispatch_token(v, param_type && param_type->as_named_type() ? param_type->as_named_type()->declared_type() : nullptr, [this, &storage, name, &references_to_resolve, index](auto v) {
if constexpr (std::is_same_v<std::decay_t<decltype(v)>, IfcParse::reference_or_simple_type>) {
@@ -292,7 +292,7 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re
}
});
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, IfcParse::parse_context*>) {
auto pt = param_type;
const auto *pt = param_type;
if (pt) {
while (pt->as_named_type()) {
pt = pt->as_named_type()->declared_type()->as_type_declaration()->declared_type();
@@ -312,7 +312,7 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re
}
}, token);
if (decl) {
if (decl != nullptr) {
++kt;
}
}
+4 -4
View File
@@ -274,11 +274,11 @@ class IFC_PARSE_API IfcFile {
/// Performs a depth-first traversal, returning all entity instance
/// attributes as a flat list. NB: includes the root instance specified
/// in the first function argument.
aggregate_of_instance::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level = -1);
static aggregate_of_instance::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level = -1);
/// Same as traverse() but maintains topological order by using a
/// breadth-first search
aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level = -1);
static aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level = -1);
/// Get the attribute indices corresponding to the list of entity instances
/// returned by getInverse().
@@ -324,10 +324,10 @@ class IFC_PARSE_API IfcFile {
const IfcSpfHeader& header() const { return _header; }
IfcSpfHeader& header() { return _header; }
std::string createTimestamp() const;
static std::string createTimestamp() ;
void load(unsigned entity_instance_name, const IfcParse::entity* entity, parse_context&, int attribute_index = -1);
void try_read_semicolon();
void try_read_semicolon() const;
void register_inverse(unsigned, const IfcParse::entity* from_entity, Token, int attribute_index);
void register_inverse(unsigned, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass*, int attribute_index);
+1 -1
View File
@@ -94,7 +94,7 @@ IfcParse::IfcGlobalId::IfcGlobalId() {
uuid_data_ = gen();
std::vector<unsigned char> v(uuid_data_.size());
std::copy(uuid_data_.begin(), uuid_data_.end(), v.begin());
string_data_ = compress(&v[0]);
string_data_ = compress(v.data());
#if BOOST_VERSION < 104400
formatted_string = boost::lexical_cast<std::string>(uuid_data);
#else
-2
View File
@@ -17,8 +17,6 @@
* *
********************************************************************************/
#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
#include "IfcLogger.h"
#include "Argument.h"
+21 -21
View File
@@ -245,7 +245,7 @@ char IfcSpfStream::Read(unsigned int offset) {
//
// Returns the cursor position
//
unsigned int IfcSpfStream::Tell() {
unsigned int IfcSpfStream::Tell() const {
return ptr_;
}
@@ -274,7 +274,7 @@ IfcSpfLexer::~IfcSpfLexer() {
delete decoder_;
}
unsigned int IfcSpfLexer::skipWhitespace() {
unsigned int IfcSpfLexer::skipWhitespace() const {
unsigned int index = 0;
while (!stream->eof) {
char character = stream->Peek();
@@ -288,7 +288,7 @@ unsigned int IfcSpfLexer::skipWhitespace() {
return index;
}
unsigned int IfcSpfLexer::skipComment() {
unsigned int IfcSpfLexer::skipComment() const {
char character = stream->Peek();
if (character != '/') {
return 0;
@@ -376,7 +376,7 @@ Token IfcSpfLexer::Next() {
return t;
}
bool IfcSpfStream::is_eof_at(unsigned int local_ptr) {
bool IfcSpfStream::is_eof_at(unsigned int local_ptr) const {
return local_ptr >= len_;
}
@@ -646,7 +646,7 @@ std::string TokenFunc::asString(const Token& token) {
boost::dynamic_bitset<> TokenFunc::asBinary(const Token& token) {
const std::string& str = asStringRef(token);
if (str.size() < 1) {
if (str.empty()) {
throw IfcException("Token is not a valid binary sequence");
}
@@ -716,7 +716,7 @@ void IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::enti
try {
parse_context ps;
load(0, nullptr, ps, -1);
auto decl = schema_->declaration_by_name(TokenFunc::asStringRef(next));
const auto *decl = schema_->declaration_by_name(TokenFunc::asStringRef(next));
auto* simple_type_instance = schema_->instantiate(decl, ps.construct(-1, references_to_resolve, decl));
//@todo decide addEntity(((IfcUtil::IfcBaseClass*)*entity));
context.push(simple_type_instance);
@@ -748,7 +748,7 @@ IfcEntityInstanceData IfcParse::read(unsigned int i, IfcFile* f) {
return IfcEntityInstanceData(pc.construct(i, f->references_to_resolve, ty));
}
void IfcParse::IfcFile::try_read_semicolon() {
void IfcParse::IfcFile::try_read_semicolon() const {
unsigned int old_offset = tokens->stream->Tell();
Token semilocon = tokens->Next();
if (!TokenFunc::isOperator(semilocon, ';')) {
@@ -799,7 +799,7 @@ namespace {
// The REAL token definition from the IFC SPF standard does not necessarily match
// the output of the C++ ostream formatting operation.
// REAL = [ SIGN ] DIGIT { DIGIT } "." { DIGIT } [ "E" [ SIGN ] DIGIT { DIGIT } ] .
std::string format_double(const double& d) {
static std::string format_double(const double& d) {
std::ostringstream oss;
oss.imbue(std::locale::classic());
oss << std::setprecision(std::numeric_limits<double>::digits10) << d;
@@ -821,7 +821,7 @@ namespace {
return oss.str();
}
std::string format_binary(const boost::dynamic_bitset<>& b) {
static std::string format_binary(const boost::dynamic_bitset<>& b) {
std::ostringstream oss;
oss.imbue(std::locale::classic());
oss.put('"');
@@ -906,8 +906,8 @@ namespace {
}
data_ << ")";
}
void operator()(const empty_aggregate_t&) const { data_ << "()"; }
void operator()(const empty_aggregate_of_aggregate_t&) const { data_ << "()"; }
void operator()(const empty_aggregate_t& /*unused*/) const { data_ << "()"; }
void operator()(const empty_aggregate_of_aggregate_t& /*unused*/) const { data_ << "()"; }
};
template <>
@@ -1428,8 +1428,6 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
}
references_to_resolve.clear();
return;
}
void IfcFile::recalculate_id_counter() {
@@ -1969,7 +1967,7 @@ namespace {
template <typename Fn>
void visit_subtypes(const IfcParse::entity* ent, Fn fn) {
fn(ent);
for (auto& st : ent->subtypes()) {
for (const auto& st : ent->subtypes()) {
visit_subtypes(st, fn);
}
}
@@ -1985,7 +1983,7 @@ namespace {
aggregate_of_instance::ptr IfcFile::instances_by_type(const IfcParse::declaration* t) {
aggregate_of_instance::ptr insts(new aggregate_of_instance);
if (t->as_entity()) {
if (t->as_entity() != nullptr) {
visit_subtypes(t->as_entity(), [this, &insts](const IfcParse::entity* ent) {
auto it = bytype_excl_.find(ent);
if (it != bytype_excl_.end()) {
@@ -2096,7 +2094,7 @@ std::ostream& operator<<(std::ostream& out, const IfcParse::IfcFile& file) {
return out;
}
std::string IfcFile::createTimestamp() const {
std::string IfcFile::createTimestamp() {
char buf[255];
time_t t;
@@ -2104,7 +2102,7 @@ std::string IfcFile::createTimestamp() const {
struct tm* ti = localtime(&t);
std::string result = "";
std::string result;
if (strftime(buf, 255, "%Y-%m-%dT%H:%M:%S", ti) != 0U) {
result = std::string(buf);
}
@@ -2194,8 +2192,10 @@ size_t IfcFile::getTotalInverses(int instance_id) {
}
void IfcFile::setDefaultHeaderValues() {
const std::string empty_string = "";
std::vector<std::string> file_description, schema_identifiers, empty_vector;
const std::string empty_string;
std::vector<std::string> file_description;
std::vector<std::string> schema_identifiers;
std::vector<std::string> empty_vector;
file_description.push_back("ViewDefinition [CoordinationView]");
if (schema() != nullptr) {
@@ -2311,8 +2311,8 @@ void IfcUtil::IfcBaseClass::unset_attribute_value(size_t index) {
void IfcUtil::IfcBaseClass::toString(std::ostream& out, bool upper) const
{
auto ent = declaration().as_entity();
if (ent) {
const auto *ent = declaration().as_entity();
if (ent != nullptr) {
out << "#" << as<IfcUtil::IfcBaseEntity>()->id() << "=";
}
if (upper) {
+2 -2
View File
@@ -148,8 +148,8 @@ Token NoneTokenPtr();
class IFC_PARSE_API IfcSpfLexer {
private:
IfcCharacterDecoder* decoder_;
unsigned int skipWhitespace();
unsigned int skipComment();
unsigned int skipWhitespace() const;
unsigned int skipComment() const;
public:
std::string& GetTempString() const {
+2 -2
View File
@@ -50,9 +50,9 @@ namespace {
}
HeaderEntity::HeaderEntity(const char* const datatype, size_t size, IfcFile* file)
: data_(file ? read_from_file(file, size) : IfcEntityInstanceData(storage_t(size)))
, datatype_(datatype)
: datatype_(datatype)
, file_(file)
, data_(file ? read_from_file(file, size) : IfcEntityInstanceData(storage_t(size)))
{}
HeaderEntity::~HeaderEntity() {
+2 -2
View File
@@ -71,9 +71,9 @@ class IFC_PARSE_API IfcSpfStream {
/// Moves the file cursor to an arbitrary offset in the file
void Seek(unsigned int offset);
/// Returns the cursor position
unsigned int Tell();
unsigned int Tell() const;
bool is_eof_at(unsigned int);
bool is_eof_at(unsigned int) const;
void increment_at(unsigned int&);
char peek_at(unsigned int);
};
+2 -2
View File
@@ -459,7 +459,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
};
// Create or reference an instance from the file and set attributes based on XML attributes.
auto create_instance = [&state, &attributes, &id](const IfcParse::declaration* decl) {
auto create_instance = [&state, &attributes](const IfcParse::declaration* decl) {
boost::optional<std::string> id;
boost::variant<std::string, IfcUtil::IfcBaseClass*> rv;
@@ -479,7 +479,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs)
}
}
auto untyped = IfcEntityInstanceData(storage_t(decl->as_entity() ? decl->as_entity()->attribute_count() : 1));
auto untyped = IfcEntityInstanceData(storage_t(decl->as_entity() != nullptr ? decl->as_entity()->attribute_count() : 1));
const IfcParse::entity* entity = decl->as_entity();
if (entity != nullptr) {