Skip to content

Commit

Permalink
Merge pull request #253 from rbrich/ranges
Browse files Browse the repository at this point in the history
Use C++ std::ranges
  • Loading branch information
rbrich authored Nov 18, 2024
2 parents 719956d + 1e192a7 commit f1ecdfe
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 83 deletions.
54 changes: 15 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ jobs:
cxx: g++
libcxx: libstdc++11
build_args: ""
- os: ubuntu-22.04
name: "Clang 13 / Release"
cc: clang
cc_ver: 13
cxx: clang++
libcxx: libc++
apt: libc++-13-dev libc++abi-13-dev libc++-14-dev- libc++1-14- libc++abi-14-dev- libc++abi1-14- libunwind-14- libunwind-14-dev-
build_args: ""
# - os: ubuntu-22.04
# name: "Clang 14 / Release"
# cc: clang
# cc_ver: 14
# cxx: clang++
# libcxx: libc++
# apt: libc++-14-dev libc++abi-14-dev
# build_args: ""
- os: ubuntu-22.04
name: "Clang 15 / Release"
cc: clang
Expand Down Expand Up @@ -90,52 +74,44 @@ jobs:
cxx: g++
libcxx: libstdc++11
build_args: "--minsize --unity"
- os: macos-12
name: "Clang 15 / Release"
- os: macos-15
name: "Clang 18 arm64 / Release"
cc: clang
cc_ver: 15
libcxx: libc++
clang: llvm@15
os_target: "11.0"
build_args: ""
- os: macos-12
name: "Xcode 13.2 / Release"
cc: apple-clang
cc_ver: 13
cc_ver: 18
libcxx: libc++
clang: Xcode_13.2.1
os_target: "11.0"
clang: llvm@18
os_target: "15.0"
build_args: ""
- os: macos-12
name: "Xcode 14.2 / Release"
- os: macos-13
name: "Xcode 14.3 / Release"
cc: apple-clang
cc_ver: 14
libcxx: libc++
clang: Xcode_14.2
os_target: "12.0"
clang: Xcode_14.3
os_target: "13.0"
build_args: ""
- os: macos-13
name: "Xcode 15.0 / Release"
name: "Xcode 15.2 / Release"
cc: apple-clang
cc_ver: 15
libcxx: libc++
clang: Xcode_15.0
clang: Xcode_15.2.0
os_target: "13.0"
build_args: ""
- os: macos-14
name: "Xcode 15.2 arm64 / Release"
name: "Xcode 15.4 arm64 / Release"
cc: apple-clang
cc_ver: 15
libcxx: libc++
clang: Xcode_15.2
clang: Xcode_15.4.0
os_target: "14.0"
build_args: ""
- os: macos-15
name: "Xcode 16 arm64 / Release"
name: "Xcode 16.1 arm64 / Release"
cc: apple-clang
cc_ver: 16
libcxx: libc++
clang: Xcode_16
clang: Xcode_16.1.0
os_target: "15.0"
build_args: ""
- os: windows-2019
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ set(XCI_CXX_STANDARD 20)
if (HAVE_LIBSTDCXX)
set(CMAKE_CXX_EXTENSIONS ON) # for __int128
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
# Enable C++20 ranges in Clang 15
add_compile_options(-fexperimental-library)
endif()

set(XCIKIT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

Expand Down
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ Technologies:
Supported compilers:

* GCC >= 10
* Clang >= 13
* Xcode >= 13
* Clang >= 15
* Xcode >= 14
* Visual Studio >= 16

Any Unix-like OS with C++20 compliant compiler should work.
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ PACKAGE_OUTPUT_DIR="${ROOT_DIR}/artifacts"
PACKAGE_FILENAME="xcikit-${VERSION}-${PLATFORM}-${ARCH}"
[[ ${BUILD_TYPE} != "Release" ]] && PACKAGE_FILENAME="${PACKAGE_FILENAME}-${BUILD_TYPE}"

CONAN_ARGS+=("-pr=${CONAN_PROFILE}" "-pr:b=${CONAN_PROFILE}")
CONAN_ARGS+=("-pr:a=${CONAN_PROFILE}")

COMPONENTS=(vfs data script graphics text widgets)
if [[ -z "$component_default" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions build_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yaml
from pathlib import Path
from shlex import quote
from shutil import rmtree
import sys
import subprocess

Expand Down Expand Up @@ -87,6 +88,8 @@ def main():
run(["git", "-c", "advice.detachedHead=false",
"clone", url, "--depth=1", "--branch", git_ref, source_dir])

if force_rebuild:
rmtree(build_dir)
build_dir.mkdir(parents=True, exist_ok=True)
cmake_args = ["-D" + d for d in cmake_defs.split()]
if args.toolchain is not None:
Expand Down
2 changes: 1 addition & 1 deletion conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ requirements:
- "spirv_cross_core/"
- "spirv_cross_glsl/"
conan: "spirv-cross/1.3.268.0"
upstream: "github.com KhronosGroup/SPIRV-Cross vulkan-sdk-1.3.283"
upstream: "github.com KhronosGroup/SPIRV-Cross vulkan-sdk-1.3.296"
cmake_defs: SPIRV_CROSS_STATIC=ON SPIRV_CROSS_SHARED=OFF SPIRV_CROSS_CLI=OFF
prereq:
- shed_tool
Expand Down
6 changes: 3 additions & 3 deletions src/xci/script/Class.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Class.cpp created on 2019-09-11 as part of xcikit project
// https://github.com/rbrich/xcikit
//
// Copyright 2019–2023 Radek Brich
// Copyright 2019–2024 Radek Brich
// Licensed under the Apache License, Version 2.0 (see LICENSE file)

#include "Class.h"
#include "Function.h"

#include <range/v3/algorithm.hpp>
#include <ranges>

namespace xci::script {

Expand Down Expand Up @@ -42,7 +42,7 @@ Instance::Instance(Class& cls, SymbolTable& symtab)

bool Instance::is_generic() const
{
return ranges::any_of(m_types, [](const TypeInfo& t) { return t.has_generic(); });
return std::ranges::any_of(m_types, [](const TypeInfo& t) { return t.has_generic(); });
}


Expand Down
5 changes: 2 additions & 3 deletions src/xci/script/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
#include "Stack.h"
#include <xci/compat/macros.h>

#include <range/v3/view/reverse.hpp>

#include <ranges>
#include <sstream>
#include <cassert>

namespace xci::script {

using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;


class CompilerVisitor: public ast::VisitorExclTypes {
Expand Down
4 changes: 2 additions & 2 deletions src/xci/script/Stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "Function.h"
#include "Module.h"

#include <range/v3/view/reverse.hpp>
#include <ranges>

#include <iostream>
#include <iomanip>

namespace xci::script {

using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;
using std::cout;
using std::endl;

Expand Down
12 changes: 6 additions & 6 deletions src/xci/script/TypeInfo.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// TypeInfo.cpp created on 2019-06-09 as part of xcikit project
// https://github.com/rbrich/xcikit
//
// Copyright 2019–2023 Radek Brich
// Copyright 2019–2024 Radek Brich
// Licensed under the Apache License, Version 2.0 (see LICENSE file)

#include "TypeInfo.h"
#include "Error.h"
#include <xci/compat/macros.h>
#include <range/v3/algorithm/any_of.hpp>
#include <ranges>
#include <numeric>

namespace xci::script {
Expand Down Expand Up @@ -378,7 +378,7 @@ bool TypeInfo::has_unknown() const
return elem_type().has_unknown();
case Type::Tuple:
case Type::Struct:
return ranges::any_of(subtypes(), [](const TypeInfo& type_info) {
return std::ranges::any_of(subtypes(), [](const TypeInfo& type_info) {
return type_info.has_unknown();
});
default:
Expand All @@ -398,7 +398,7 @@ bool TypeInfo::has_generic() const
return elem_type().has_generic();
case Type::Tuple:
case Type::Struct:
return ranges::any_of(subtypes(), [](const TypeInfo& type_info) {
return std::ranges::any_of(subtypes(), [](const TypeInfo& type_info) {
return type_info.has_generic();
});
default:
Expand Down Expand Up @@ -447,15 +447,15 @@ TypeInfo& TypeInfo::underlying()

bool Signature::has_generic_nonlocals() const
{
return ranges::any_of(nonlocals, [](const TypeInfo& type_info) {
return std::ranges::any_of(nonlocals, [](const TypeInfo& type_info) {
return type_info.has_generic();
});
}


bool Signature::has_unknown_nonlocals() const
{
return ranges::any_of(nonlocals, [](const TypeInfo& type_info) {
return std::ranges::any_of(nonlocals, [](const TypeInfo& type_info) {
return type_info.has_unknown();
});
}
Expand Down
10 changes: 3 additions & 7 deletions src/xci/script/ast/AST.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
// AST.cpp created on 2019-05-15 as part of xcikit project
// https://github.com/rbrich/xcikit
//
// Copyright 2019–2023 Radek Brich
// Copyright 2019–2024 Radek Brich
// Licensed under the Apache License, Version 2.0 (see LICENSE file)

#include "AST.h"
#include <xci/script/Error.h>
#include <xci/compat/macros.h>
#include <xci/core/string.h>

#include <range/v3/view/reverse.hpp>

#include <ranges>
#include <string>
#include <stdexcept>
#include <sstream>
#include <cstdlib>
#include <cassert>

namespace xci::script::ast {

using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;


void Visitor::visit(Block& blk)
Expand Down
6 changes: 3 additions & 3 deletions src/xci/script/ast/resolve_spec.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// resolve_spec.cpp created on 2022-08-13 as part of xcikit project
// https://github.com/rbrich/xcikit
//
// Copyright 2022–2023 Radek Brich
// Copyright 2022–2024 Radek Brich
// Licensed under the Apache License, Version 2.0 (see LICENSE file)

#include "resolve_spec.h"
Expand All @@ -17,8 +17,8 @@
#include <xci/core/log.h>

#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/reverse.hpp>

#include <ranges>
#include <sstream>
#include <optional>
#include <span>
Expand All @@ -28,7 +28,7 @@ namespace xci::script {
using std::stringstream;
using namespace xci::core;
using ranges::views::enumerate;
using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;


class ResolveSpecVisitor final: public ast::VisitorExclTypes {
Expand Down
4 changes: 2 additions & 2 deletions src/xci/script/ast/resolve_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
#include <xci/compat/macros.h>

#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/reverse.hpp>

#include <ranges>
#include <sstream>
#include <optional>

namespace xci::script {

using std::stringstream;
using ranges::views::enumerate;
using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;


class ResolveTypesVisitor final: public ast::VisitorExclTypes {
Expand Down
6 changes: 3 additions & 3 deletions src/xci/script/typing/overload_resolver.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// overload_resolver.cpp created on 2022-12-31 as part of xcikit project
// https://github.com/rbrich/xcikit
//
// Copyright 2022–2023 Radek Brich
// Copyright 2022–2024 Radek Brich
// Licensed under the Apache License, Version 2.0 (see LICENSE file)

#include "overload_resolver.h"
#include "generic_resolver.h"
#include <range/v3/view/reverse.hpp>
#include <ranges>

namespace xci::script {

using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;


std::pair<const Candidate*, bool> find_best_candidate(const std::vector<Candidate>& candidates)
Expand Down
7 changes: 3 additions & 4 deletions src/xci/widgets/Widget.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// Widget.cpp created on 2018-04-23 as part of xcikit project
// https://github.com/rbrich/xcikit
//
// Copyright 2018–2023 Radek Brich
// Copyright 2018–2024 Radek Brich
// Licensed under the Apache License, Version 2.0 (see LICENSE file)

#include "Widget.h"
#include <xci/core/rtti.h>
#include <xci/graphics/Window.h>
#include <range/v3/algorithm/any_of.hpp>
#include <ranges>
#include <cassert>

namespace xci::widgets {

using namespace xci::graphics;
using ranges::cpp20::any_of;

using std::ranges::any_of;

void Widget::set_position(const VariCoords& pos)
{
Expand Down
5 changes: 2 additions & 3 deletions tools/fire_script/Repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#include <xci/script/dump.h>
#include <xci/core/ResourceUsage.h>

#include <range/v3/view/reverse.hpp>

#include <ranges>
#include <iostream>

namespace xci::script::tool {

using xci::core::ResourceUsage;
using ranges::cpp20::views::reverse;
using std::ranges::views::reverse;
using std::endl;


Expand Down
Loading

0 comments on commit f1ecdfe

Please sign in to comment.