Skip to content

Commit

Permalink
Apply tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
vla5924 committed Apr 1, 2024
1 parent 9973680 commit 5870d68
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 85 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Checks: >
bugprone-throw-keyword-missing,
bugprone-unused-raii,
bugprone-unused-return-value,
cppcoreguidelines-macro-usage,
llvm-include-order,
llvm-namespace-comment,
misc-confusable-identifiers,
Expand Down
51 changes: 28 additions & 23 deletions compiler/include/compiler/optree/adaptors.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#pragma once

#include <concepts>
#include <string_view>
#include <cstdint>
#include <string>
#include <vector>

#include "compiler/optree/base_adaptor.hpp"
#include "compiler/optree/definitions.hpp"
#include "compiler/optree/operation.hpp"
#include "compiler/optree/types.hpp"
#include "compiler/optree/value.hpp"

namespace optree {

Expand Down Expand Up @@ -40,7 +45,7 @@ struct ModuleOp : Adaptor {
struct FunctionOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Function", specId)

void init(const std::string &name, Type::Ptr funcType);
void init(const std::string &name, const Type::Ptr &funcType);

OPTREE_ADAPTOR_ATTRIBUTE(name, setName, std::string, 0)
OPTREE_ADAPTOR_ATTRIBUTE_TYPE(type, FunctionType, 1)
Expand All @@ -51,7 +56,7 @@ struct FunctionOp : Adaptor {
struct FunctionCallOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "FunctionCall", specId)

void init(const std::string &name, Type::Ptr resultType, const std::vector<Value::Ptr> &arguments);
void init(const std::string &name, const Type::Ptr &resultType, const std::vector<Value::Ptr> &arguments);
void init(const FunctionOp &callee, const std::vector<Value::Ptr> &arguments);

OPTREE_ADAPTOR_ATTRIBUTE(name, setName, std::string, 0)
Expand All @@ -64,7 +69,7 @@ struct ReturnOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Return", specId)

void init();
void init(Value::Ptr value);
void init(const Value::Ptr &value);

OPTREE_ADAPTOR_OPERAND(value, setValue, 0)

Expand All @@ -74,9 +79,9 @@ struct ReturnOp : Adaptor {
struct ConstantOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Constant", specId)

void init(Type::Ptr type, int64_t value);
void init(Type::Ptr type, double value);
void init(Type::Ptr type, const std::string &value);
void init(const Type::Ptr &type, int64_t value);
void init(const Type::Ptr &type, double value);
void init(const Type::Ptr &type, const std::string &value);

OPTREE_ADAPTOR_ATTRIBUTE_OPAQUE(value, 0)
OPTREE_ADAPTOR_RESULT(result, 0)
Expand All @@ -98,7 +103,7 @@ struct LogicUnaryOp;
struct BinaryOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Binary", specId)

void init(Type::Ptr resultType, Value::Ptr lhs, Value::Ptr rhs);
void init(const Type::Ptr &resultType, const Value::Ptr &lhs, const Value::Ptr &rhs);

OPTREE_ADAPTOR_OPERAND(lhs, setLhs, 0)
OPTREE_ADAPTOR_OPERAND(rhs, setRhs, 1)
Expand All @@ -110,8 +115,8 @@ struct BinaryOp : Adaptor {
struct ArithBinaryOp : BinaryOp {
OPTREE_ADAPTOR_HELPER(BinaryOp, "ArithBinary", specId)

void init(ArithBinOpKind kind, Type::Ptr resultType, Value::Ptr lhs, Value::Ptr rhs);
void init(ArithBinOpKind kind, Value::Ptr lhs, Value::Ptr rhs);
void init(ArithBinOpKind kind, const Type::Ptr &resultType, const Value::Ptr &lhs, const Value::Ptr &rhs);
void init(ArithBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs);

OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, ArithBinOpKind, 0)

Expand All @@ -121,7 +126,7 @@ struct ArithBinaryOp : BinaryOp {
struct LogicBinaryOp : BinaryOp {
OPTREE_ADAPTOR_HELPER(BinaryOp, "LogicBinary", specId)

void init(LogicBinOpKind kind, Value::Ptr lhs, Value::Ptr rhs);
void init(LogicBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs);

OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, LogicBinOpKind, 0)

Expand All @@ -131,7 +136,7 @@ struct LogicBinaryOp : BinaryOp {
struct UnaryOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Unary", specId)

void init(Type::Ptr resultType, Value::Ptr value);
void init(const Type::Ptr &resultType, const Value::Ptr &value);

OPTREE_ADAPTOR_OPERAND(value, setValue, 0)
OPTREE_ADAPTOR_RESULT(result, 0)
Expand All @@ -142,7 +147,7 @@ struct UnaryOp : Adaptor {
struct ArithCastOp : UnaryOp {
OPTREE_ADAPTOR_HELPER(UnaryOp, "ArithCast", specId)

void init(ArithCastOpKind kind, Type::Ptr resultType, Value::Ptr value);
void init(ArithCastOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value);

OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, ArithCastOpKind, 0)

Expand All @@ -152,7 +157,7 @@ struct ArithCastOp : UnaryOp {
struct LogicUnaryOp : UnaryOp {
OPTREE_ADAPTOR_HELPER(UnaryOp, "LogicUnary", specId)

void init(LogicUnaryOpKind kind, Type::Ptr resultType, Value::Ptr value);
void init(LogicUnaryOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value);

OPTREE_ADAPTOR_ATTRIBUTE(kind, setKind, LogicUnaryOpKind, 0)

Expand All @@ -170,7 +175,7 @@ struct StoreOp;
struct AllocateOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Allocate", specId)

void init(Type::Ptr type);
void init(const Type::Ptr &type);

OPTREE_ADAPTOR_RESULT(result, 0)

Expand All @@ -180,8 +185,8 @@ struct AllocateOp : Adaptor {
struct LoadOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Load", specId)

void init(Type::Ptr resultType, Value::Ptr src);
void init(Value::Ptr src);
void init(const Type::Ptr &resultType, const Value::Ptr &src);
void init(const Value::Ptr &src);

OPTREE_ADAPTOR_OPERAND(src, setSrc, 0)
OPTREE_ADAPTOR_RESULT(result, 0)
Expand All @@ -192,7 +197,7 @@ struct LoadOp : Adaptor {
struct StoreOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Store", specId)

void init(Value::Ptr dst, Value::Ptr valueToStore);
void init(const Value::Ptr &dst, const Value::Ptr &valueToStore);

OPTREE_ADAPTOR_OPERAND(dst, setDst, 0)
OPTREE_ADAPTOR_OPERAND(valueToStore, setValueToStore, 1)
Expand All @@ -214,7 +219,7 @@ struct ForOp;
struct IfOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "If", specId)

void init(Value::Ptr cond, bool withElse = false);
void init(const Value::Ptr &cond, bool withElse = false);

OPTREE_ADAPTOR_OPERAND(cond, setCond, 0);

Expand Down Expand Up @@ -263,7 +268,7 @@ struct ConditionOp : Adaptor {
struct ForOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "For", specId)

void init(Type::Ptr iteratorType, Value::Ptr start, Value::Ptr stop, Value::Ptr step);
void init(const Type::Ptr &iteratorType, const Value::Ptr &start, const Value::Ptr &stop, const Value::Ptr &step);

OPTREE_ADAPTOR_OPERAND(start, setStart, 0)
OPTREE_ADAPTOR_OPERAND(stop, setStop, 1)
Expand All @@ -283,7 +288,7 @@ struct PrintOp;
struct InputOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Input", specId)

void init(Type::Ptr inputType);
void init(const Type::Ptr &inputType);

OPTREE_ADAPTOR_RESULT(value, 0)

Expand All @@ -293,7 +298,7 @@ struct InputOp : Adaptor {
struct PrintOp : Adaptor {
OPTREE_ADAPTOR_HELPER(Adaptor, "Print", specId)

void init(Value::Ptr valueToPrint);
void init(const Value::Ptr &valueToPrint);

OPTREE_ADAPTOR_OPERAND(value, setValue, 0)

Expand Down
5 changes: 3 additions & 2 deletions compiler/include/compiler/optree/attribute.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <concepts>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <ostream>
#include <string>
#include <variant>

Expand Down
5 changes: 3 additions & 2 deletions compiler/include/compiler/optree/base_adaptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string_view>

#include "compiler/optree/operation.hpp"
#include "compiler/utils/source_ref.hpp"

#define OPTREE_ADAPTOR_HELPER(BASE_ADAPTOR_CLASS, OPERATION_NAME, SPECID_MEMBER_NAME) \
public: \
Expand All @@ -12,11 +13,11 @@
return (OPERATION_NAME); \
} \
static Operation::SpecId getSpecId() { \
return &SPECID_MEMBER_NAME; \
return &(SPECID_MEMBER_NAME); \
} \
\
private: \
static inline char SPECID_MEMBER_NAME; \
static inline char(SPECID_MEMBER_NAME); \
\
public:

Expand Down
6 changes: 4 additions & 2 deletions compiler/include/compiler/optree/builder.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "compiler/optree/operation.hpp"
#include "compiler/utils/source_ref.hpp"

#include "compiler/optree/operation.hpp"

namespace optree {

class Builder {
Expand All @@ -11,7 +12,8 @@ class Builder {
Operation::Ptr currentOp;
InsertPoint insertPoint;

Builder(Operation::Ptr currentOp, InsertPoint insertPoint) : currentOp(currentOp), insertPoint(insertPoint){};
Builder(const Operation::Ptr &currentOp, const InsertPoint &insertPoint)
: currentOp(currentOp), insertPoint(insertPoint){};

public:
Builder() = default;
Expand Down
24 changes: 12 additions & 12 deletions compiler/include/compiler/optree/operation.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include <algorithm>
#include <cstddef>
#include <functional>
#include <list>
#include <memory>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "compiler/utils/source_ref.hpp"
Expand Down Expand Up @@ -41,10 +41,10 @@ struct Operation {
Operation(Operation &&) = default;
~Operation() = default;

explicit Operation(Ptr parent = {}, Body::iterator position = {})
explicit Operation(const Ptr &parent = {}, const Body::iterator &position = {})
: parent(parent), position(position), specId(nullptr), verifier([](const Operation *) { return true; }){};
Operation(SpecId specId, const Verifier &verifier, std::string_view name = "Unknown", Ptr parent = Ptr(),
Body::iterator position = {})
Operation(SpecId specId, const Verifier &verifier, std::string_view name = "Unknown", const Ptr &parent = {},
const Body::iterator &position = {})
: parent(parent), position(position), specId(specId), verifier(verifier), name(name){};

const Value::Ptr &operand(size_t index) const {
Expand Down Expand Up @@ -84,7 +84,7 @@ struct Operation {
for (const auto &a : attributes)
if (a.is<VariantType>())
return a.as<VariantType>();
throw std::exception("There are no attributes with a given type");
throw std::logic_error("There are no attributes with a given type");
}

operator bool() const {
Expand Down Expand Up @@ -133,11 +133,11 @@ struct Operation {
return attributes.emplace_back(value);
}

void addOperand(Value::Ptr value);
void addOperand(const Value::Ptr &value);
void eraseOperand(size_t operandNumber);
Value::Ptr addResult(Type::Ptr type);
Value::Ptr addInward(Type::Ptr type);
Body::iterator addToBody(Operation::Ptr op);
Value::Ptr addResult(const Type::Ptr &type);
Value::Ptr addInward(const Type::Ptr &type);
Body::iterator addToBody(const Operation::Ptr &op);
void erase();

bool verify() const;
Expand All @@ -146,7 +146,7 @@ struct Operation {
void dump(std::ostream &stream) const;

template <typename AdaptorType>
static AdaptorType make(Ptr parent = {}, Body::iterator position = {}) {
static AdaptorType make(const Ptr &parent = {}, const Body::iterator &position = {}) {
auto op = std::make_shared<Operation>(AdaptorType::getSpecId(), AdaptorType::verify,
AdaptorType::getOperationName(), parent, position);
return {op};
Expand Down
2 changes: 0 additions & 2 deletions compiler/include/compiler/optree/program.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <list>

#include "compiler/optree/operation.hpp"

namespace optree {
Expand Down
3 changes: 3 additions & 0 deletions compiler/include/compiler/optree/traits.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once

#include <algorithm>
#include <cstddef>

#include "compiler/optree/operation.hpp"
#include "compiler/optree/types.hpp"
#include "compiler/optree/value.hpp"

namespace optree {

Expand Down
6 changes: 2 additions & 4 deletions compiler/include/compiler/optree/types.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <concepts>
#include <functional>
#include <memory>
#include <ostream>
#include <type_traits>
Expand Down Expand Up @@ -123,7 +121,7 @@ struct FunctionType : public Type {
const PtrVector arguments;
const Type::Ptr result;

FunctionType(const PtrVector &arguments, Type::Ptr result) : arguments(arguments), result(result){};
FunctionType(const PtrVector &arguments, const Type::Ptr &result) : arguments(arguments), result(result){};

bool operator==(const Type &other) const override;
using Type::operator!=;
Expand All @@ -136,7 +134,7 @@ struct PointerType : public Type {

const Type::Ptr pointee;

PointerType(Type::Ptr pointee) : pointee(pointee){};
PointerType(const Type::Ptr &pointee) : pointee(pointee){};

bool operator==(const Type &other) const override;
using Type::operator!=;
Expand Down
5 changes: 3 additions & 2 deletions compiler/include/compiler/optree/value.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstddef>
#include <forward_list>
#include <memory>

Expand Down Expand Up @@ -35,8 +36,8 @@ struct Value {
Value(Value &&) = default;
~Value() = default;

Value(Type::Ptr type, Operation *owner) : type(type), owner(owner){};
Value(Type::Ptr type, std::shared_ptr<Operation> owner) : Value(type, owner.get()){};
Value(const Type::Ptr &type, Operation *owner) : type(type), owner(owner){};
Value(const Type::Ptr &type, const std::shared_ptr<Operation> &owner) : Value(type, owner.get()){};

operator bool() const {
return type.operator bool();
Expand Down
1 change: 1 addition & 0 deletions compiler/include/compiler/utils/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iterator>
#include <ostream>
#include <type_traits>

namespace utils {

Expand Down
Loading

0 comments on commit 5870d68

Please sign in to comment.