Skip to content
Merged
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 .github/workflows/format-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
steps:
# Checks out the repository.
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v6

# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: '3.x'

Expand Down
42 changes: 22 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,15 @@ if(OASIS_BUILD_WITH_COVERAGE)
endif()
endif()

# Fetches dependencies and integrates them into the project.
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
FIND_PACKAGE_ARGS)

# Perhaps one day use Microsoft.GSL if
# https://github.com/microsoft/GSL/issues/991 gets addressed
# Fetches dependencies and integrates them into the project. Perhaps one day use
# Microsoft.GSL if https://github.com/microsoft/GSL/issues/991 gets addressed
FetchContent_Declare(
GSL
GIT_REPOSITORY "https://github.com/gsl-lite/gsl-lite.git"
GIT_TAG v0.42.0)
GIT_TAG v1.1.0
EXCLUDE_FROM_ALL FIND_PACKAGE_ARGS CONFIG)

FetchContent_MakeAvailable(Catch2 GSL)
FetchContent_MakeAvailable(GSL)

if(NOT OASIS_BUILD_JS)
include(cmake/FetchBoost.cmake)
Expand All @@ -72,28 +66,36 @@ include(cmake/FetchEigen.cmake)
add_subdirectory(include)
add_subdirectory(src)

if(OASIS_BUILD_TESTS)
FetchContent_Declare(
Catch2
GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
GIT_TAG v3.13.0
EXCLUDE_FROM_ALL FIND_PACKAGE_ARGS CONFIG)

FetchContent_MakeAvailable(Catch2)
add_subdirectory(tests)
endif()

if(OASIS_BUILD_IO)
include(cmake/FetchTinyxml2.cmake)
add_subdirectory(io)
endif()

if(OASIS_BUILD_TESTS)
add_subdirectory(tests)
endif()

if(OASIS_BUILD_CLI)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 11.1.3)
GIT_REPOSITORY "https://github.com/fmtlib/fmt"
GIT_TAG 12.1.0
EXCLUDE_FROM_ALL FIND_PACKAGE_ARGS CONFIG)

FetchContent_Declare(
Isocline
GIT_REPOSITORY https://github.com/daanx/isocline.git
GIT_TAG v1.0.9)
GIT_REPOSITORY "https://github.com/daanx/isocline.git"
GIT_TAG v1.0.9
EXCLUDE_FROM_ALL FIND_PACKAGE_ARGS CONFIG)

FetchContent_MakeAvailable(fmt Isocline)

add_subdirectory(cli)
endif()

Expand Down
2 changes: 1 addition & 1 deletion cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char** argv)

// Calling Oasis::FromInFix passed as template fails because defaulted parameters aren't represented in the type, so a wrapper is needed
auto result = (input | Oasis::PreProcessInFix | Parse)
.and_then([&simplifyVisitor](const std::unique_ptr<Oasis::Expression>& expr) -> std::expected<gsl::not_null<std::unique_ptr<Oasis::Expression>>, std::string> {
.and_then([&simplifyVisitor](const std::unique_ptr<Oasis::Expression>& expr) -> std::expected<gsl_lite::not_null<std::unique_ptr<Oasis::Expression>>, std::string> {
return expr->Accept(simplifyVisitor);
})
.and_then([&serializer](const std::unique_ptr<Oasis::Expression>& expr) -> std::expected<std::string, std::string> {
Expand Down
15 changes: 7 additions & 8 deletions cmake/FetchEigen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

# See https://stackoverflow.com/a/65899078.

# Fetches the "eigen" dependency and integrates it into the project.
# Fetches the "Eigen" dependency and integrates it into the project.
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG nightly)

# Disables some of eigen's build options.
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 5.0.1
EXCLUDE_FROM_ALL
FIND_PACKAGE_ARGS CONFIG)

set(EIGEN_BUILD_PKGCONFIG OFF)
set(EIGEN_BUILD_DOC OFF)
set(BUILD_TESTING OFF)

FetchContent_MakeAvailable(eigen)
FetchContent_MakeAvailable(Eigen)
6 changes: 3 additions & 3 deletions include/Oasis/MatchCast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/vector.hpp>

#include <gsl/gsl-lite.hpp>
#include <gsl-lite/gsl-lite.hpp>

#include <concepts>
#include <functional>
Expand All @@ -34,7 +34,7 @@ using lambda_argument_type = std::remove_cvref_t<std::tuple_element_t<0, boost::

template <typename CheckF, typename TransformerF, typename ArgumentT>
concept TransformerAcceptsCheckArg = requires(TransformerF f, const lambda_argument_type<CheckF>& t) {
{ f(t, nullptr) } -> std::same_as<std::expected<gsl::not_null<std::unique_ptr<ArgumentT>>, std::string_view>>;
{ f(t, nullptr) } -> std::same_as<std::expected<gsl_lite::not_null<std::unique_ptr<ArgumentT>>, std::string_view>>;
} && std::predicate<CheckF, const lambda_argument_type<CheckF>&>;

template <typename ArgumentT, typename Cases>
Expand Down Expand Up @@ -62,7 +62,7 @@ class MatchCastImpl {

auto [check, transformer] = checkAndTransformer;
if (std::unique_ptr<CaseType> castResult = RecursiveCast<CaseType>(arg); castResult && check(*castResult))
result = transformer(*castResult, visitor).transform([](gsl::not_null<std::unique_ptr<ArgumentT>>&& transformResult) { return std::move(transformResult); });
result = transformer(*castResult, visitor).transform([](gsl_lite::not_null<std::unique_ptr<ArgumentT>>&& transformResult) { return std::move(transformResult); });
});
return result;
}
Expand Down
5 changes: 2 additions & 3 deletions include/Oasis/SimplifyVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#ifndef SIMPLIFYVISITOR_HPP
#define SIMPLIFYVISITOR_HPP

#include <format>
#include <string>

#include <gsl/gsl-lite.hpp>
#include <gsl-lite/gsl-lite.hpp>

#include "Oasis/Visit.hpp"

Expand All @@ -22,7 +21,7 @@ struct SimplifyOpts {
= AngleUnits::RADIANS;
};

class SimplifyVisitor final : public TypedVisitor<std::expected<gsl::not_null<std::unique_ptr<Expression>>, std::string>> {
class SimplifyVisitor final : public TypedVisitor<std::expected<gsl_lite::not_null<std::unique_ptr<Expression>>, std::string>> {
public:
SimplifyVisitor();
explicit SimplifyVisitor(SimplifyOpts& opts);
Expand Down
12 changes: 6 additions & 6 deletions io/include/Oasis/MathMLSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef MATHMLSERIALIZER_HPP
#define MATHMLSERIALIZER_HPP

#include <gsl/gsl-lite.hpp>
#include <gsl-lite/gsl-lite.hpp>
#include <tinyxml2.h>

#include "Oasis/BinaryExpression.hpp"
Expand All @@ -14,7 +14,7 @@

namespace Oasis {

class MathMLSerializer final : public TypedVisitor<std::expected<gsl::not_null<tinyxml2::XMLElement*>, std::string>> {
class MathMLSerializer final : public TypedVisitor<std::expected<gsl_lite::not_null<tinyxml2::XMLElement*>, std::string>> {
public:
explicit MathMLSerializer(tinyxml2::XMLDocument& doc);

Expand All @@ -40,15 +40,15 @@ class MathMLSerializer final : public TypedVisitor<std::expected<gsl::not_null<t
[[nodiscard]] tinyxml2::XMLDocument& GetDocument() const;

private:
auto GetOpsAsMathMLPair(const DerivedFromBinaryExpression auto& binexp) -> std::expected<std::pair<gsl::not_null<tinyxml2::XMLElement*>, gsl::not_null<tinyxml2::XMLElement*>>, std::string>;
auto GetOpsAsMathMLPair(const DerivedFromBinaryExpression auto& binexp) -> std::expected<std::pair<gsl_lite::not_null<tinyxml2::XMLElement*>, gsl_lite::not_null<tinyxml2::XMLElement*>>, std::string>;
tinyxml2::XMLDocument& doc;
};

auto MathMLSerializer::GetOpsAsMathMLPair(const DerivedFromBinaryExpression auto& binexp) -> std::expected<std::pair<gsl::not_null<tinyxml2::XMLElement*>, gsl::not_null<tinyxml2::XMLElement*>>, std::string>
auto MathMLSerializer::GetOpsAsMathMLPair(const DerivedFromBinaryExpression auto& binexp) -> std::expected<std::pair<gsl_lite::not_null<tinyxml2::XMLElement*>, gsl_lite::not_null<tinyxml2::XMLElement*>>, std::string>
{
MathMLSerializer& thisSerializer = *this;
return binexp.GetMostSigOp().Accept(thisSerializer).and_then([&binexp, &thisSerializer](gsl::not_null<tinyxml2::XMLElement*> mostSigOp) {
return binexp.GetLeastSigOp().Accept(thisSerializer).transform([&mostSigOp](gsl::not_null<tinyxml2::XMLElement*> leastSigOp) {
return binexp.GetMostSigOp().Accept(thisSerializer).and_then([&binexp, &thisSerializer](gsl_lite::not_null<tinyxml2::XMLElement*> mostSigOp) {
return binexp.GetLeastSigOp().Accept(thisSerializer).transform([&mostSigOp](gsl_lite::not_null<tinyxml2::XMLElement*> leastSigOp) {
return std::pair { mostSigOp, leastSigOp };
});
});
Expand Down
36 changes: 18 additions & 18 deletions io/src/MathMLSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ auto MathMLSerializer::TypedVisit(const Real& real) -> RetT
{
tinyxml2::XMLElement* result = doc.NewElement("mn");
result->SetText(std::format("{:.5}", real.GetValue()).c_str());
return gsl::not_null(result);
return gsl_lite::not_null(result);
}

auto MathMLSerializer::TypedVisit(const Imaginary&) -> RetT
{
tinyxml2::XMLElement* result = doc.NewElement("mi");
result->SetText("i");
return gsl::not_null(result);
return gsl_lite::not_null(result);
}

auto MathMLSerializer::TypedVisit(const Matrix& matrix) -> RetT
Expand Down Expand Up @@ -72,35 +72,35 @@ auto MathMLSerializer::TypedVisit(const Matrix& matrix) -> RetT
mrow->InsertEndChild(table);
mrow->InsertEndChild(closeBrace);

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
}

auto MathMLSerializer::TypedVisit(const Oasis::Pi&) -> RetT
{
tinyxml2::XMLElement* result = doc.NewElement("mi");
result->SetText("&pi;");
return gsl::not_null(result);
return gsl_lite::not_null(result);
}

auto MathMLSerializer::TypedVisit(const Oasis::EulerNumber&) -> RetT
{
tinyxml2::XMLElement* result = doc.NewElement("mi");
result->SetText("e");
return gsl::not_null(result);
return gsl_lite::not_null(result);
}

auto MathMLSerializer::TypedVisit(const Variable& variable) -> RetT
{
tinyxml2::XMLElement* result = doc.NewElement("mi");
result->SetText(variable.GetName().c_str());
return gsl::not_null(result);
return gsl_lite::not_null(result);
}

auto MathMLSerializer::TypedVisit(const Undefined&) -> RetT
{
tinyxml2::XMLElement* const mtext = doc.NewElement("mtext");
mtext->SetText("Undefined");
return gsl::not_null(mtext);
return gsl_lite::not_null(mtext);
}

auto MathMLSerializer::TypedVisit(const Add<>& add) -> RetT
Expand All @@ -122,7 +122,7 @@ auto MathMLSerializer::TypedVisit(const Add<>& add) -> RetT

// remove last mo
mrow->DeleteChild(mrow->LastChild());
return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
}

auto MathMLSerializer::TypedVisit(const Subtract<>& subtract) -> RetT
Expand Down Expand Up @@ -165,7 +165,7 @@ auto MathMLSerializer::TypedVisit(const Subtract<>& subtract) -> RetT
mrow->InsertEndChild(rightParen);
}

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
});
}

Expand Down Expand Up @@ -226,7 +226,7 @@ auto MathMLSerializer::TypedVisit(const Multiply<>& multiply) -> RetT
}
}

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
}

auto MathMLSerializer::TypedVisit(const Divide<>& divide) -> RetT
Expand All @@ -239,7 +239,7 @@ auto MathMLSerializer::TypedVisit(const Divide<>& divide) -> RetT
mfrac->InsertEndChild(dividendElement);
mfrac->InsertEndChild(divisorElement);

return gsl::not_null(mfrac);
return gsl_lite::not_null(mfrac);
});
}

Expand Down Expand Up @@ -272,7 +272,7 @@ auto MathMLSerializer::TypedVisit(const Exponent<>& exponent) -> RetT

msup->InsertEndChild(powerElement);

return gsl::not_null(msup);
return gsl_lite::not_null(msup);
});
}

Expand Down Expand Up @@ -306,7 +306,7 @@ auto MathMLSerializer::TypedVisit(const Log<>& log) -> RetT
mrow->InsertEndChild(argElement);
mrow->InsertEndChild(rightParen);

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
});
}

Expand All @@ -333,14 +333,14 @@ auto MathMLSerializer::TypedVisit(const Negate<Expression>& negate) -> RetT
rightParen->SetText(")");
mrow->InsertEndChild(rightParen);

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
}

auto MathMLSerializer::TypedVisit(const Sine<Expression>&) -> RetT
{
// mrow
tinyxml2::XMLElement* const mrow = doc.NewElement("mrow");
return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
}

auto MathMLSerializer::TypedVisit(const Derivative<>& derivative) -> RetT
Expand Down Expand Up @@ -379,7 +379,7 @@ auto MathMLSerializer::TypedVisit(const Derivative<>& derivative) -> RetT
mrow->InsertEndChild(expElement);
mrow->InsertEndChild(rightParen);

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
});
}

Expand All @@ -406,7 +406,7 @@ auto MathMLSerializer::TypedVisit(const Integral<>& integral) -> RetT
mrow->InsertEndChild(expElement);
mrow->InsertEndChild(dVar);

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
});
}

Expand All @@ -433,7 +433,7 @@ auto MathMLSerializer::TypedVisit(const Magnitude<Expression>& magnitude) -> Ret
rightParen->SetText("|");
mrow->InsertEndChild(rightParen);

return gsl::not_null(mrow);
return gsl_lite::not_null(mrow);
}

}
Loading
Loading