mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-07 10:19:57 +08:00
Further polishing. Mainly adding const qualifiers
This commit is contained in:
parent
b13ed07420
commit
55717cb115
358
.gitignore
vendored
358
.gitignore
vendored
@ -3,3 +3,361 @@
|
||||
/buckaroo/
|
||||
.buckconfig.local
|
||||
BUCKAROO_DEPS
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
49
CMakeSettings.json
Normal file
49
CMakeSettings.json
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
// See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file.
|
||||
"configurations": [
|
||||
{
|
||||
"name": "x86-Debug",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [ "msvc_x86" ],
|
||||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
|
||||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
},
|
||||
{
|
||||
"name": "x86-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "RelWithDebInfo",
|
||||
"inheritEnvironments": [ "msvc_x86" ],
|
||||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
|
||||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
},
|
||||
{
|
||||
"name": "x64-Debug",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
|
||||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
},
|
||||
{
|
||||
"name": "x64-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "RelWithDebInfo",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
|
||||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "-v",
|
||||
"ctestCommandArgs": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -2,4 +2,4 @@ def greet {
|
||||
return("hello")
|
||||
}
|
||||
|
||||
fun(){ "world" }
|
||||
fun() { return "world"; }
|
||||
|
||||
@ -820,6 +820,7 @@
|
||||
/// @namespace chaiscript::detail
|
||||
/// @brief Classes and functions reserved for internal use. Items in this namespace are not supported.
|
||||
|
||||
#include <utility>
|
||||
#include "chaiscript_basic.hpp"
|
||||
#include "language/chaiscript_parser.hpp"
|
||||
#include "chaiscript_stdlib.hpp"
|
||||
@ -836,7 +837,7 @@ namespace chaiscript
|
||||
: ChaiScript_Basic(
|
||||
chaiscript::Std_Lib::library(),
|
||||
std::make_unique<parser::ChaiScript_Parser<eval::Noop_Tracer, optimizer::Optimizer_Default>>(),
|
||||
t_modulepaths, t_usepaths, t_opts)
|
||||
std::move(t_modulepaths), std::move(t_usepaths), t_opts)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@ -155,7 +155,7 @@ namespace chaiscript {
|
||||
auto parse_num(const char *t_str) -> typename std::enable_if<std::is_integral<T>::value, T>::type
|
||||
{
|
||||
T t = 0;
|
||||
for (char c = *t_str; (c = *t_str) != 0; ++t_str) {
|
||||
for (char c; (c = *t_str) != 0; ++t_str) {
|
||||
if (c < '0' || c > '9') {
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ namespace chaiscript {
|
||||
|
||||
std::unique_ptr<Data> clone() const override
|
||||
{
|
||||
return std::unique_ptr<Data>(new Data_Impl<T>(m_data));
|
||||
return std::unique_ptr<Data>(std::make_unique<Data_Impl<T>>(m_data));
|
||||
}
|
||||
|
||||
Data_Impl &operator=(const Data_Impl&) = delete;
|
||||
@ -134,8 +134,7 @@ namespace chaiscript {
|
||||
|
||||
|
||||
// modifiers
|
||||
Any & swap(Any &t_other)
|
||||
{
|
||||
Any & swap(Any &t_other) noexcept {
|
||||
std::swap(t_other.m_data, m_data);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ namespace chaiscript
|
||||
|
||||
static bool has_guard(const Const_Proxy_Function &t_pf)
|
||||
{
|
||||
auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
|
||||
const auto pf = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_pf);
|
||||
return pf && pf->get_guard();
|
||||
}
|
||||
|
||||
@ -294,6 +294,7 @@ namespace chaiscript
|
||||
|
||||
std::vector<Boxed_Value> vbv;
|
||||
|
||||
vbv.reserve(v.size());
|
||||
for (const auto &o: v)
|
||||
{
|
||||
vbv.push_back(const_var(o));
|
||||
|
||||
@ -33,6 +33,7 @@ namespace chaiscript
|
||||
/// \brief Function for extracting a value stored in a Boxed_Value object
|
||||
/// \tparam Type The type to extract from the Boxed_Value
|
||||
/// \param[in] bv The Boxed_Value to extract a typed value from
|
||||
/// \param t_conversions
|
||||
/// \returns Type equivalent to the requested type
|
||||
/// \throws exception::bad_boxed_cast If the requested conversion is not possible
|
||||
///
|
||||
|
||||
@ -769,22 +769,22 @@ namespace chaiscript
|
||||
return Boxed_Number(oper(Operators::Opers::pre_increment, t_lhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number sum(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
static Boxed_Number sum(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::sum, t_lhs.bv, t_rhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number unary_plus(const Boxed_Number &t_lhs)
|
||||
static Boxed_Number unary_plus(const Boxed_Number &t_lhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::unary_plus, t_lhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number unary_minus(const Boxed_Number &t_lhs)
|
||||
static Boxed_Number unary_minus(const Boxed_Number &t_lhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::unary_minus, t_lhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number difference(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
static Boxed_Number difference(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::difference, t_lhs.bv, t_rhs.bv));
|
||||
}
|
||||
@ -824,22 +824,22 @@ namespace chaiscript
|
||||
return Boxed_Number(oper(Operators::Opers::assign_shift_right, t_lhs.bv, t_rhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number bitwise_and(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
static Boxed_Number bitwise_and(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::bitwise_and, t_lhs.bv, t_rhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number bitwise_complement(const Boxed_Number &t_lhs)
|
||||
static Boxed_Number bitwise_complement(const Boxed_Number &t_lhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::bitwise_complement, t_lhs.bv, Boxed_Value(0)));
|
||||
}
|
||||
|
||||
static const Boxed_Number bitwise_xor(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
static Boxed_Number bitwise_xor(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::bitwise_xor, t_lhs.bv, t_rhs.bv));
|
||||
}
|
||||
|
||||
static const Boxed_Number bitwise_or(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
static Boxed_Number bitwise_or(const Boxed_Number &t_lhs, const Boxed_Number &t_rhs)
|
||||
{
|
||||
return Boxed_Number(oper(Operators::Opers::bitwise_or, t_lhs.bv, t_rhs.bv));
|
||||
}
|
||||
|
||||
@ -208,15 +208,13 @@ namespace chaiscript
|
||||
Boxed_Value(const Boxed_Value&) = default;
|
||||
Boxed_Value& operator=(const Boxed_Value&) = default;
|
||||
|
||||
void swap(Boxed_Value &rhs)
|
||||
{
|
||||
void swap(Boxed_Value &rhs) noexcept {
|
||||
std::swap(m_data, rhs.m_data);
|
||||
}
|
||||
|
||||
/// Copy the values stored in rhs.m_data to m_data.
|
||||
/// m_data pointers are not shared in this case
|
||||
Boxed_Value assign(const Boxed_Value &rhs)
|
||||
{
|
||||
Boxed_Value assign(const Boxed_Value &rhs) const {
|
||||
(*m_data) = (*rhs.m_data);
|
||||
return *this;
|
||||
}
|
||||
@ -318,8 +316,7 @@ namespace chaiscript
|
||||
return m_data->m_const_data_ptr;
|
||||
}
|
||||
|
||||
Boxed_Value get_attr(const std::string &t_name)
|
||||
{
|
||||
Boxed_Value get_attr(const std::string &t_name) const {
|
||||
if (!m_data->m_attrs)
|
||||
{
|
||||
m_data->m_attrs = std::make_unique<std::map<std::string, std::shared_ptr<Data>>>();
|
||||
|
||||
@ -663,7 +663,7 @@ namespace chaiscript
|
||||
loc_mask = 0x0000FFFF
|
||||
};
|
||||
|
||||
uint_fast32_t loc = t_loc;
|
||||
const uint_fast32_t loc = t_loc;
|
||||
|
||||
if (loc == 0)
|
||||
{
|
||||
@ -733,7 +733,7 @@ namespace chaiscript
|
||||
if (t_throw) {
|
||||
throw std::range_error("Type Not Known");
|
||||
} else {
|
||||
return Type_Info();
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
@ -765,7 +765,7 @@ namespace chaiscript
|
||||
|
||||
std::shared_ptr<std::vector<Proxy_Function>> get_method_missing_functions() const
|
||||
{
|
||||
uint_fast32_t method_missing_loc = m_method_missing_loc;
|
||||
const uint_fast32_t method_missing_loc = m_method_missing_loc;
|
||||
auto method_missing_funs = get_function("method_missing", method_missing_loc);
|
||||
if (method_missing_funs.first != method_missing_loc) {
|
||||
m_method_missing_loc = uint_fast32_t(method_missing_funs.first);
|
||||
@ -782,7 +782,7 @@ namespace chaiscript
|
||||
|
||||
const auto &funs = get_functions_int();
|
||||
|
||||
auto itr = find_keyed_value(funs, t_name, t_hint);
|
||||
const auto itr = find_keyed_value(funs, t_name, t_hint);
|
||||
|
||||
if (itr != funs.end())
|
||||
{
|
||||
@ -808,7 +808,7 @@ namespace chaiscript
|
||||
{
|
||||
const auto &funs = get_boxed_functions_int();
|
||||
|
||||
auto itr = find_keyed_value(funs, t_name, t_hint);
|
||||
const auto itr = find_keyed_value(funs, t_name, t_hint);
|
||||
|
||||
if (itr != funs.end())
|
||||
{
|
||||
@ -959,7 +959,7 @@ namespace chaiscript
|
||||
Boxed_Value call_member(const std::string &t_name, std::atomic_uint_fast32_t &t_loc, const std::vector<Boxed_Value> ¶ms, bool t_has_params,
|
||||
const Type_Conversions_State &t_conversions)
|
||||
{
|
||||
uint_fast32_t loc = t_loc;
|
||||
const uint_fast32_t loc = t_loc;
|
||||
const auto funs = get_function(t_name, loc);
|
||||
if (funs.first != loc) { t_loc = uint_fast32_t(funs.first); }
|
||||
|
||||
@ -1079,7 +1079,7 @@ namespace chaiscript
|
||||
Boxed_Value call_function(const std::string &t_name, std::atomic_uint_fast32_t &t_loc, const std::vector<Boxed_Value> ¶ms,
|
||||
const Type_Conversions_State &t_conversions) const
|
||||
{
|
||||
uint_fast32_t loc = t_loc;
|
||||
const uint_fast32_t loc = t_loc;
|
||||
const auto funs = get_function(t_name, loc);
|
||||
if (funs.first != loc) { t_loc = uint_fast32_t(funs.first);
|
||||
}
|
||||
@ -1233,7 +1233,7 @@ namespace chaiscript
|
||||
{
|
||||
if (t_s.call_depth == 0)
|
||||
{
|
||||
m_conversions.enable_conversion_saves(t_saves, true);
|
||||
chaiscript::Type_Conversions::enable_conversion_saves(t_saves, true);
|
||||
}
|
||||
|
||||
++t_s.call_depth;
|
||||
@ -1250,7 +1250,7 @@ namespace chaiscript
|
||||
if (t_s.call_depth == 0)
|
||||
{
|
||||
t_s.call_params.back().clear();
|
||||
m_conversions.enable_conversion_saves(t_saves, false);
|
||||
chaiscript::Type_Conversions::enable_conversion_saves(t_saves, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1326,8 +1326,8 @@ namespace chaiscript
|
||||
static bool function_less_than(const Proxy_Function &lhs, const Proxy_Function &rhs)
|
||||
{
|
||||
|
||||
auto dynamic_lhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(lhs));
|
||||
auto dynamic_rhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(rhs));
|
||||
const auto dynamic_lhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(lhs));
|
||||
const auto dynamic_rhs(std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(rhs));
|
||||
|
||||
if (dynamic_lhs && dynamic_rhs)
|
||||
{
|
||||
|
||||
@ -44,7 +44,7 @@ namespace chaiscript
|
||||
{
|
||||
public:
|
||||
explicit Dynamic_Object(std::string t_type_name)
|
||||
: m_type_name(std::move(t_type_name)), m_option_explicit(false)
|
||||
: m_type_name(std::move(t_type_name))
|
||||
{
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ namespace chaiscript
|
||||
|
||||
const Boxed_Value &get_attr(const std::string &t_attr_name) const
|
||||
{
|
||||
auto a = m_attrs.find(t_attr_name);
|
||||
const auto a = m_attrs.find(t_attr_name);
|
||||
|
||||
if (a != m_attrs.end()) {
|
||||
return a->second;
|
||||
|
||||
@ -68,7 +68,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
|
||||
Dynamic_Object_Function &operator=(const Dynamic_Object_Function) = delete;
|
||||
Dynamic_Object_Function &operator=(Dynamic_Object_Function) = delete;
|
||||
Dynamic_Object_Function(Dynamic_Object_Function &) = delete;
|
||||
|
||||
bool operator==(const Proxy_Function_Base &f) const override
|
||||
@ -189,7 +189,7 @@ namespace chaiscript
|
||||
static std::vector<Type_Info> build_type_list(const std::vector<Type_Info> &tl)
|
||||
{
|
||||
auto begin = tl.begin();
|
||||
auto end = tl.end();
|
||||
const auto end = tl.end();
|
||||
|
||||
if (begin != end)
|
||||
{
|
||||
@ -201,7 +201,7 @@ namespace chaiscript
|
||||
|
||||
bool operator==(const Proxy_Function_Base &f) const override
|
||||
{
|
||||
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
||||
const auto *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
||||
return (dc != nullptr) && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,7 @@ namespace chaiscript
|
||||
/// build_function_caller(dispatchkit.get_function("print"));
|
||||
/// \returns A std::function object for dispatching
|
||||
/// \param[in] funcs the set of functions to dispatch on.
|
||||
/// \param t_conversions
|
||||
template<typename FunctionType>
|
||||
std::function<FunctionType> functor(const std::vector<Const_Proxy_Function> &funcs, const Type_Conversions_State *t_conversions)
|
||||
{
|
||||
@ -65,6 +66,7 @@ namespace chaiscript
|
||||
/// }
|
||||
/// \returns A std::function object for dispatching
|
||||
/// \param[in] func A function to execute.
|
||||
/// \param t_conversions
|
||||
template<typename FunctionType>
|
||||
std::function<FunctionType> functor(Const_Proxy_Function func, const Type_Conversions_State *t_conversions)
|
||||
{
|
||||
|
||||
@ -41,7 +41,7 @@ namespace chaiscript
|
||||
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params, *t_conversions), t_conversions);
|
||||
} else {
|
||||
Type_Conversions conv;
|
||||
Type_Conversions_State state(conv, conv.conversion_saves());
|
||||
const Type_Conversions_State state(conv, conv.conversion_saves());
|
||||
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params, state), t_conversions);
|
||||
}
|
||||
}
|
||||
@ -60,7 +60,7 @@ namespace chaiscript
|
||||
return Boxed_Number(dispatch::dispatch(t_funcs, params, *t_conversions)).get_as<Ret>();
|
||||
} else {
|
||||
Type_Conversions conv;
|
||||
Type_Conversions_State state(conv, conv.conversion_saves());
|
||||
const Type_Conversions_State state(conv, conv.conversion_saves());
|
||||
return Boxed_Number(dispatch::dispatch(t_funcs, params, state)).get_as<Ret>();
|
||||
}
|
||||
}
|
||||
@ -80,7 +80,7 @@ namespace chaiscript
|
||||
dispatch::dispatch(t_funcs, params, *t_conversions);
|
||||
} else {
|
||||
Type_Conversions conv;
|
||||
Type_Conversions_State state(conv, conv.conversion_saves());
|
||||
const Type_Conversions_State state(conv, conv.conversion_saves());
|
||||
dispatch::dispatch(t_funcs, params, state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ namespace chaiscript
|
||||
|
||||
bool operator==(const Proxy_Function_Base &rhs) const override
|
||||
{
|
||||
const Dynamic_Proxy_Function *prhs = dynamic_cast<const Dynamic_Proxy_Function *>(&rhs);
|
||||
const auto *prhs = dynamic_cast<const Dynamic_Proxy_Function *>(&rhs);
|
||||
|
||||
return this == &rhs
|
||||
|| ((prhs != nullptr)
|
||||
@ -733,7 +733,7 @@ namespace chaiscript
|
||||
|
||||
bool operator==(const Proxy_Function_Base &t_func) const override
|
||||
{
|
||||
const Attribute_Access<T, Class> * aa
|
||||
const auto * aa
|
||||
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
|
||||
|
||||
if (aa) {
|
||||
|
||||
@ -123,7 +123,7 @@ public:
|
||||
|
||||
T* allocate(std::size_t n)
|
||||
{
|
||||
return reinterpret_cast<T*>(a_.template allocate<alignof(T)>(n*sizeof(T)));
|
||||
return reinterpret_cast<T*>(a_.allocate<alignof(T)>(n*sizeof(T)));
|
||||
}
|
||||
void deallocate(T* p, std::size_t n) noexcept
|
||||
{
|
||||
|
||||
@ -156,11 +156,11 @@ namespace chaiscript
|
||||
if (t_from.is_const())
|
||||
{
|
||||
const From &d = detail::Cast_Helper<const From &>::cast(t_from, nullptr);
|
||||
const To &data = static_cast<const To &>(d);
|
||||
const auto &data = static_cast<const To &>(d);
|
||||
return Boxed_Value(std::cref(data));
|
||||
} else {
|
||||
From &d = detail::Cast_Helper<From &>::cast(t_from, nullptr);
|
||||
To &data = static_cast<To &>(d);
|
||||
auto &data = static_cast<To &>(d);
|
||||
return Boxed_Value(std::ref(data));
|
||||
}
|
||||
}
|
||||
@ -221,11 +221,11 @@ namespace chaiscript
|
||||
if (t_from.is_const())
|
||||
{
|
||||
const From &d = detail::Cast_Helper<const From &>::cast(t_from, nullptr);
|
||||
const To &data = dynamic_cast<const To &>(d);
|
||||
const auto &data = dynamic_cast<const To &>(d);
|
||||
return Boxed_Value(std::cref(data));
|
||||
} else {
|
||||
From &d = detail::Cast_Helper<From &>::cast(t_from, nullptr);
|
||||
To &data = dynamic_cast<To &>(d);
|
||||
auto &data = dynamic_cast<To &>(d);
|
||||
return Boxed_Value(std::ref(data));
|
||||
}
|
||||
}
|
||||
@ -335,18 +335,15 @@ namespace chaiscript
|
||||
};
|
||||
|
||||
Type_Conversions()
|
||||
: m_mutex(),
|
||||
m_conversions(),
|
||||
m_convertableTypes(),
|
||||
m_num_types(0)
|
||||
: m_num_types(0)
|
||||
{
|
||||
}
|
||||
|
||||
Type_Conversions(const Type_Conversions &t_other) = delete;
|
||||
Type_Conversions(Type_Conversions &&) = default;
|
||||
Type_Conversions(Type_Conversions &&) = default; //? this is implicitly deleted (because member not assignable or ...)
|
||||
|
||||
Type_Conversions &operator=(const Type_Conversions &) = delete;
|
||||
Type_Conversions &operator=(Type_Conversions &&) = default;
|
||||
Type_Conversions &operator=(Type_Conversions &&) = default; // ? implcitly deleted
|
||||
|
||||
const std::set<const std::type_info *, Less_Than> &thread_cache() const
|
||||
{
|
||||
@ -436,8 +433,7 @@ namespace chaiscript
|
||||
t_saves.enabled = t_val;
|
||||
}
|
||||
|
||||
std::vector<Boxed_Value> take_saves(Conversion_Saves &t_saves)
|
||||
{
|
||||
std::vector<Boxed_Value> take_saves(Conversion_Saves &t_saves) const {
|
||||
std::vector<Boxed_Value> ret;
|
||||
std::swap(ret, t_saves.saves);
|
||||
return ret;
|
||||
@ -504,8 +500,8 @@ namespace chaiscript
|
||||
std::set<std::shared_ptr<detail::Type_Conversion_Base>> m_conversions;
|
||||
std::set<const std::type_info *, Less_Than> m_convertableTypes;
|
||||
std::atomic_size_t m_num_types;
|
||||
mutable chaiscript::detail::threading::Thread_Storage<std::set<const std::type_info *, Less_Than>> m_thread_cache;
|
||||
mutable chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves;
|
||||
mutable chaiscript::detail::threading::Thread_Storage<std::set<const std::type_info *, Less_Than>> m_thread_cache{};
|
||||
mutable chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves{};
|
||||
};
|
||||
|
||||
class Type_Conversions_State
|
||||
|
||||
@ -73,7 +73,7 @@ namespace chaiscript
|
||||
Logical_And, Bitwise_Or, Bitwise_Xor, Bitwise_And,
|
||||
Equality, Comparison, Shift, Addition, Multiplication, Prefix };
|
||||
|
||||
namespace
|
||||
namespace // TODO:: should not use unnamed namespaces in header files
|
||||
{
|
||||
/// Helper lookup to get the name of each node type
|
||||
inline const char *ast_node_type_to_string(AST_Node_Type ast_node_type) {
|
||||
@ -263,7 +263,7 @@ namespace chaiscript
|
||||
const chaiscript::detail::Dispatch_Engine &t_ss)
|
||||
{
|
||||
assert(t_func);
|
||||
int arity = t_func->get_arity();
|
||||
const int arity = t_func->get_arity();
|
||||
std::vector<Type_Info> types = t_func->get_param_types();
|
||||
|
||||
std::string retval;
|
||||
@ -308,16 +308,16 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> dynfun
|
||||
const std::shared_ptr<const dispatch::Dynamic_Proxy_Function> dynfun
|
||||
= std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_func);
|
||||
|
||||
if (dynfun && dynfun->has_parse_tree())
|
||||
{
|
||||
Proxy_Function f = dynfun->get_guard();
|
||||
const Proxy_Function f = dynfun->get_guard();
|
||||
|
||||
if (f)
|
||||
{
|
||||
auto dynfunguard = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
|
||||
const auto dynfunguard = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
|
||||
if (dynfunguard && dynfunguard->has_parse_tree())
|
||||
{
|
||||
retval += " : " + format_guard(dynfunguard->get_parse_tree());
|
||||
@ -598,8 +598,7 @@ namespace chaiscript
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::vector<AST_Node_Trace> get_children(const AST_Node &node)
|
||||
{
|
||||
std::vector<AST_Node_Trace> get_children(const AST_Node &node) const {
|
||||
const auto node_children = node.get_children();
|
||||
return std::vector<AST_Node_Trace>(node_children.begin(), node_children.end());
|
||||
}
|
||||
@ -707,13 +706,11 @@ namespace chaiscript
|
||||
m_ds->pop_function_call(m_ds.stack_holder(), m_ds.conversion_saves());
|
||||
}
|
||||
|
||||
void save_params(const std::vector<Boxed_Value> &t_params)
|
||||
{
|
||||
void save_params(const std::vector<Boxed_Value> &t_params) const {
|
||||
m_ds->save_function_params(t_params);
|
||||
}
|
||||
|
||||
void save_params(std::initializer_list<Boxed_Value> t_params)
|
||||
{
|
||||
void save_params(std::initializer_list<Boxed_Value> t_params) const {
|
||||
m_ds->save_function_params(t_params);
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
@ -298,7 +299,7 @@ namespace chaiscript
|
||||
std::vector<std::string> t_module_paths = {},
|
||||
std::vector<std::string> t_use_paths = {},
|
||||
const std::vector<chaiscript::Options> &t_opts = chaiscript::default_options())
|
||||
: ChaiScript_Basic({}, std::move(parser), t_module_paths, t_use_paths, t_opts)
|
||||
: ChaiScript_Basic({}, std::move(parser), std::move(t_module_paths), std::move(t_use_paths), t_opts)
|
||||
{
|
||||
try {
|
||||
// attempt to load the stdlib
|
||||
@ -323,8 +324,7 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
||||
const std::vector<chaiscript::Options> &t_opts = chaiscript::default_options()) = delete;
|
||||
#endif
|
||||
|
||||
parser::ChaiScript_Parser_Base &get_parser()
|
||||
{
|
||||
parser::ChaiScript_Parser_Base &get_parser() const {
|
||||
return *m_parser;
|
||||
}
|
||||
|
||||
@ -337,8 +337,7 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
||||
}
|
||||
}
|
||||
|
||||
AST_NodePtr parse(const std::string &t_input, const bool t_debug_print = false)
|
||||
{
|
||||
AST_NodePtr parse(const std::string &t_input, const bool t_debug_print = false) const {
|
||||
auto ast = m_parser->parse(t_input, "PARSE");
|
||||
if (t_debug_print) {
|
||||
m_parser->debug_print(*ast);
|
||||
@ -371,6 +370,7 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
||||
try {
|
||||
const auto appendedpath = path + t_filename;
|
||||
|
||||
// l and l2 never used?
|
||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
|
||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);
|
||||
|
||||
@ -569,7 +569,7 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
||||
#else
|
||||
std::vector<exception::load_module_error> errors;
|
||||
std::string version_stripped_name = t_module_name;
|
||||
size_t version_pos = version_stripped_name.find("-" + Build_Info::version());
|
||||
const size_t version_pos = version_stripped_name.find("-" + Build_Info::version());
|
||||
if (version_pos != std::string::npos)
|
||||
{
|
||||
version_stripped_name.erase(version_pos);
|
||||
@ -616,7 +616,7 @@ explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&pars
|
||||
|
||||
if (m_loaded_modules.count(t_module_name) == 0)
|
||||
{
|
||||
detail::Loadable_Module_Ptr lm(new detail::Loadable_Module(t_module_name, t_filename));
|
||||
const detail::Loadable_Module_Ptr lm(new detail::Loadable_Module(t_module_name, t_filename));
|
||||
m_loaded_modules[t_module_name] = lm;
|
||||
m_active_loaded_modules.insert(t_module_name);
|
||||
add(lm->m_moduleptr);
|
||||
|
||||
@ -47,7 +47,7 @@ namespace chaiscript
|
||||
{
|
||||
template<typename T> struct AST_Node_Impl;
|
||||
|
||||
template<typename T> using AST_Node_Impl_Ptr = typename std::unique_ptr<AST_Node_Impl<T>>;
|
||||
template<typename T> using AST_Node_Impl_Ptr = std::unique_ptr<AST_Node_Impl<T>>;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
@ -57,7 +57,7 @@ namespace chaiscript
|
||||
chaiscript::detail::Dispatch_State state(t_ss);
|
||||
|
||||
const Boxed_Value *thisobj = [&]() -> const Boxed_Value *{
|
||||
auto &stack = t_ss.get_stack_data(state.stack_holder()).back();
|
||||
auto &stack = chaiscript::detail::Dispatch_Engine::get_stack_data(state.stack_holder()).back();
|
||||
if (!stack.empty() && stack.back().first == "__this") {
|
||||
return &stack.back().second;
|
||||
} else if (!t_vals.empty()) {
|
||||
@ -325,7 +325,7 @@ namespace chaiscript
|
||||
fpp.save_params(params);
|
||||
}
|
||||
|
||||
Boxed_Value fn(this->children[0]->eval(t_ss));
|
||||
const Boxed_Value fn(this->children[0]->eval(t_ss));
|
||||
|
||||
using ConstFunctionTypePtr = const dispatch::Proxy_Function_Base *;
|
||||
try {
|
||||
@ -337,7 +337,7 @@ namespace chaiscript
|
||||
catch(const exception::bad_boxed_cast &){
|
||||
try {
|
||||
using ConstFunctionTypeRef = const Const_Proxy_Function &;
|
||||
Const_Proxy_Function f = t_ss->boxed_cast<ConstFunctionTypeRef>(fn);
|
||||
const Const_Proxy_Function f = t_ss->boxed_cast<ConstFunctionTypeRef>(fn);
|
||||
// handle the case where there is only 1 function to try to call and dispatch fails on it
|
||||
throw exception::eval_error("Error calling function '" + this->children[0]->text + "'", params, {f}, false, *t_ss);
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
@ -689,7 +689,7 @@ namespace chaiscript
|
||||
const auto numparams = this->children[1]->children.size();
|
||||
const auto param_types = Arg_List_AST_Node<T>::get_arg_types(*this->children[1], t_ss);
|
||||
|
||||
std::reference_wrapper<chaiscript::detail::Dispatch_Engine> engine(*t_ss);
|
||||
const std::reference_wrapper<chaiscript::detail::Dispatch_Engine> engine(*t_ss);
|
||||
|
||||
return Boxed_Value(
|
||||
dispatch::make_dynamic_proxy_function(
|
||||
@ -1020,7 +1020,7 @@ namespace chaiscript
|
||||
|
||||
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
|
||||
|
||||
Boxed_Value match_value(this->children[0]->eval(t_ss));
|
||||
const Boxed_Value match_value(this->children[0]->eval(t_ss));
|
||||
|
||||
while (!breaking && (currentCase < this->children.size())) {
|
||||
try {
|
||||
@ -1322,7 +1322,7 @@ namespace chaiscript
|
||||
else if (catch_block.children.size() == 3) {
|
||||
//Variable capture, guards
|
||||
|
||||
bool guard = false;
|
||||
bool guard;
|
||||
try {
|
||||
guard = boxed_cast<bool>(catch_block.children[1]->eval(t_ss));
|
||||
} catch (const exception::bad_boxed_cast &) {
|
||||
|
||||
@ -160,6 +160,7 @@ namespace chaiscript {
|
||||
} else {
|
||||
const auto new_children = [&](){
|
||||
std::vector<eval::AST_Node_Impl_Ptr<T>> retval;
|
||||
retval.reserve(keepers.size());
|
||||
for (const auto x : keepers)
|
||||
{
|
||||
retval.push_back(std::move(node->children[x]));
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "chaiscript_tracer.hpp"
|
||||
#include "../utility/fnv1a.hpp"
|
||||
#include "../utility/static_string.hpp"
|
||||
#include <array>
|
||||
|
||||
#if defined(CHAISCRIPT_UTF16_UTF32)
|
||||
#include <locale>
|
||||
@ -126,7 +127,7 @@ namespace chaiscript
|
||||
|
||||
static std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> build_alphabet()
|
||||
{
|
||||
std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> alphabet;
|
||||
std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> alphabet{};
|
||||
|
||||
for (auto &alpha : alphabet) {
|
||||
alpha.fill(false);
|
||||
@ -461,8 +462,7 @@ namespace chaiscript
|
||||
|
||||
|
||||
/// Reads a symbol group from input if it matches the parameter, without skipping initial whitespace
|
||||
inline auto Symbol_(const utility::Static_String &sym)
|
||||
{
|
||||
inline auto Symbol_(const utility::Static_String &sym) {
|
||||
const auto len = sym.size();
|
||||
if (m_position.remaining() >= len) {
|
||||
const char *file_pos = &(*m_position);
|
||||
@ -675,7 +675,7 @@ namespace chaiscript
|
||||
|
||||
for (; i > 0; --i)
|
||||
{
|
||||
char val = t_val[i-1];
|
||||
const char val = t_val[i-1];
|
||||
|
||||
if (val == 'f' || val == 'F')
|
||||
{
|
||||
@ -739,7 +739,7 @@ namespace chaiscript
|
||||
#endif
|
||||
|
||||
try {
|
||||
auto u = std::stoll(val,nullptr,base);
|
||||
const auto u = std::stoll(val,nullptr,base);
|
||||
|
||||
|
||||
if (!unsigned_ && !long_ && u >= std::numeric_limits<int>::min() && u <= std::numeric_limits<int>::max()) {
|
||||
@ -761,7 +761,7 @@ namespace chaiscript
|
||||
} catch (const std::out_of_range &) {
|
||||
// too big to be signed
|
||||
try {
|
||||
auto u = std::stoull(val,nullptr,base);
|
||||
const auto u = std::stoull(val,nullptr,base);
|
||||
|
||||
if (!longlong_ && u >= std::numeric_limits<unsigned long>::min() && u <= std::numeric_limits<unsigned long>::max()) {
|
||||
return const_var(static_cast<unsigned long>(u));
|
||||
@ -1210,7 +1210,7 @@ namespace chaiscript
|
||||
std::string match;
|
||||
const auto prev_stack_top = m_match_stack.size();
|
||||
|
||||
bool is_interpolated = [&]()->bool {
|
||||
const bool is_interpolated = [&]()->bool {
|
||||
Char_Parser<std::string> cparser(match, true);
|
||||
|
||||
|
||||
@ -1409,7 +1409,7 @@ namespace chaiscript
|
||||
bool retval = Symbol_(t_s);
|
||||
|
||||
// ignore substring matches
|
||||
if (retval && m_position.has_more() && (t_disallow_prevention == false) && char_in_alphabet(*m_position,detail::symbol_alphabet)) {
|
||||
if (retval && m_position.has_more() && !t_disallow_prevention && char_in_alphabet(*m_position,detail::symbol_alphabet)) {
|
||||
if (*m_position != '=' && is_operator(Position::str(start, m_position)) && !is_operator(Position::str(start, m_position+1))) {
|
||||
// don't throw this away, it's a good match and the next is not
|
||||
} else {
|
||||
@ -1791,7 +1791,7 @@ namespace chaiscript
|
||||
bool Class(const bool t_class_allowed) {
|
||||
bool retval = false;
|
||||
|
||||
size_t prev_stack_top = m_match_stack.size();
|
||||
const size_t prev_stack_top = m_match_stack.size();
|
||||
|
||||
if (Keyword("class")) {
|
||||
if (!t_class_allowed) {
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#ifndef CHAISCRIPT_POSIX_HPP_
|
||||
#define CHAISCRIPT_POSIX_HPP_
|
||||
#include "../dispatchkit/bootstrap.hpp"
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
@ -29,12 +30,9 @@ namespace chaiscript
|
||||
DLModule(const DLModule &) = delete;
|
||||
DLModule &operator=(const DLModule &) = delete;
|
||||
|
||||
~DLModule()
|
||||
{
|
||||
dlclose(m_data);
|
||||
}
|
||||
~DLModule() = default;
|
||||
|
||||
void *m_data;
|
||||
void *m_data{};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -59,9 +57,13 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
DLModule m_dlmodule;
|
||||
DLSym<Create_Module_Func> m_func;
|
||||
ModulePtr m_moduleptr;
|
||||
DLSym<Create_Module_Func> m_func{};
|
||||
ModulePtr m_moduleptr{};
|
||||
};
|
||||
|
||||
inline Loadable_Module::DLModule::~DLModule() {
|
||||
dlclose(m_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
/// regarding the ChaiScript standard runtime library.
|
||||
|
||||
/// \brief Items in this namespace exist in the ChaiScript language runtime. They are not part of the C++ API
|
||||
#ifndef CHAISCRIPT_PRELUDE_DOCS_HPP
|
||||
#define CHAISCRIPT_PRELUDE_DOCS_HPP
|
||||
|
||||
namespace ChaiScript_Language
|
||||
{
|
||||
|
||||
@ -58,7 +61,7 @@ class Map_Pair
|
||||
{
|
||||
public:
|
||||
/// \brief Returns the key of the Map entry
|
||||
const string first();
|
||||
string first();
|
||||
|
||||
/// \brief Returns the value Object of the Map entry
|
||||
Object second();
|
||||
@ -596,7 +599,7 @@ bool even(Object x);
|
||||
/// eval> odd(4)
|
||||
/// false
|
||||
/// \endcode
|
||||
bool even(Object x);
|
||||
bool odd(Object x);
|
||||
|
||||
|
||||
/// \brief Applies the function f over each element in the Range c.
|
||||
@ -828,3 +831,4 @@ Const_Range retro(Const_Range);
|
||||
void throw(Object);
|
||||
}
|
||||
|
||||
#endif // CHAISCRIPT_PRELUDE_DOCS_HPP
|
||||
|
||||
@ -13,8 +13,7 @@ namespace chaiscript {
|
||||
|
||||
struct Noop_Tracer_Detail
|
||||
{
|
||||
template<typename T>
|
||||
void trace(const chaiscript::detail::Dispatch_State &, const AST_Node_Impl<T> *)
|
||||
template<typename T> static void trace(const chaiscript::detail::Dispatch_State &, const AST_Node_Impl<T> *)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@ -23,7 +23,7 @@ namespace chaiscript
|
||||
#endif
|
||||
}
|
||||
|
||||
ModulePtr m_moduleptr;
|
||||
ModulePtr m_moduleptr{};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ class JSON
|
||||
Internal( int64_t l ) : Int( l ), Type(Class::Integral) {}
|
||||
Internal( bool b ) : Bool( b ), Type(Class::Boolean) {}
|
||||
Internal( std::string s ) : String(std::make_unique<std::string>(std::move(s))), Type(Class::String) {}
|
||||
Internal() : Type(Class::Null) {}
|
||||
Internal() = default;
|
||||
|
||||
Internal(Class t_type) {
|
||||
set_type(t_type);
|
||||
@ -349,43 +349,39 @@ class JSON
|
||||
|
||||
JSONWrapper<QuickFlatMap> object_range() {
|
||||
if( internal.Type == Class::Object ) {
|
||||
return JSONWrapper<QuickFlatMap>( internal.Map.get() );
|
||||
} else {
|
||||
return JSONWrapper<QuickFlatMap>( nullptr );
|
||||
return { internal.Map.get() };
|
||||
}
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
JSONWrapper<std::vector<JSON>> array_range() {
|
||||
if( internal.Type == Class::Array ) {
|
||||
return JSONWrapper<std::vector<JSON>>( internal.List.get() );
|
||||
} else {
|
||||
return JSONWrapper<std::vector<JSON>>( nullptr );
|
||||
return { internal.List.get() };
|
||||
}
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
JSONConstWrapper<QuickFlatMap> object_range() const {
|
||||
if( internal.Type == Class::Object ) {
|
||||
return JSONConstWrapper<QuickFlatMap>( internal.Map.get() );
|
||||
} else {
|
||||
return JSONConstWrapper<QuickFlatMap>( nullptr );
|
||||
return { internal.Map.get() };
|
||||
}
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
|
||||
JSONConstWrapper<std::vector<JSON>> array_range() const {
|
||||
if( internal.Type == Class::Array ) {
|
||||
return JSONConstWrapper<std::vector<JSON>>( internal.List.get() );
|
||||
} else {
|
||||
return JSONConstWrapper<std::vector<JSON>>( nullptr );
|
||||
return { internal.List.get() };
|
||||
}
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
std::string dump( long depth = 1, std::string tab = " ") const {
|
||||
std::string dump( long depth = 1, const std::string &tab = " ") const {
|
||||
switch( internal.Type ) {
|
||||
case Class::Null:
|
||||
return "null";
|
||||
case Class::Object: {
|
||||
std::string pad = "";
|
||||
std::string pad;
|
||||
for( long i = 0; i < depth; ++i, pad += tab ) { }
|
||||
|
||||
std::string s = "{\n";
|
||||
@ -482,7 +478,7 @@ struct JSONParser {
|
||||
throw std::runtime_error(std::string("JSON ERROR: Object: Expected colon, found '") + str.at(offset) + "'\n");
|
||||
}
|
||||
consume_ws( str, ++offset );
|
||||
JSON Value = parse_next( str, offset );
|
||||
const JSON Value = parse_next( str, offset );
|
||||
Object[Key.to_string()] = Value;
|
||||
|
||||
consume_ws( str, offset );
|
||||
@ -645,9 +641,8 @@ struct JSONParser {
|
||||
}
|
||||
|
||||
static JSON parse_next( const std::string &str, size_t &offset ) {
|
||||
char value;
|
||||
consume_ws( str, offset );
|
||||
value = str.at(offset);
|
||||
const char value = str.at(offset);
|
||||
switch( value ) {
|
||||
case '[' : return parse_array( str, offset );
|
||||
case '{' : return parse_object( str, offset );
|
||||
|
||||
@ -48,7 +48,7 @@ namespace chaiscript
|
||||
/// {fun(static_cast<test & (test::*)(const test &)>(&test::operator=)), "=" }
|
||||
/// }
|
||||
/// );
|
||||
///
|
||||
/// \endcode
|
||||
template<typename Class, typename ModuleType>
|
||||
void add_class(ModuleType &t_module,
|
||||
const std::string &t_class_name,
|
||||
@ -115,6 +115,7 @@ namespace chaiscript
|
||||
{
|
||||
t_module.add_global_const(chaiscript::const_var(EnumClass(constant.first)), constant.second);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ int main(int /*argc*/, char * /*argv*/[]) {
|
||||
|
||||
//If we would like a type-safe return value from all call, we can use
|
||||
//the templated version of eval:
|
||||
int i = chai.eval<int>("5+5");
|
||||
const auto i = chai.eval<int>("5+5");
|
||||
|
||||
std::cout << "5+5: " << i << '\n';
|
||||
|
||||
@ -129,7 +129,7 @@ int main(int /*argc*/, char * /*argv*/[]) {
|
||||
chai("var scripti = 15");
|
||||
|
||||
//We can even get a handle to the variables in the system
|
||||
int &scripti = chai.eval<int &>("scripti");
|
||||
auto &scripti = chai.eval<int &>("scripti");
|
||||
|
||||
std::cout << "scripti: " << scripti << '\n';
|
||||
scripti *= 2;
|
||||
@ -139,7 +139,7 @@ int main(int /*argc*/, char * /*argv*/[]) {
|
||||
//To do: Add examples of handling Boxed_Values directly when needed
|
||||
|
||||
//Creating a functor on the stack and using it immediately
|
||||
int x = chai.eval<std::function<int (int, int)> >("fun (x, y) { return x + y; }")(5, 6);
|
||||
const int x = chai.eval<std::function<int (int, int)> >("fun (x, y) { return x + y; }")(5, 6);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << x;
|
||||
|
||||
@ -7,9 +7,9 @@ class Entity
|
||||
int height;
|
||||
int x;
|
||||
int y;
|
||||
std::string name;
|
||||
std::string name{};
|
||||
|
||||
std::function<void (Entity &)> updater;
|
||||
std::function<void (Entity &)> updater{};
|
||||
|
||||
Entity(const int t_width, const int t_height, const int t_x, const int t_y, std::string t_name)
|
||||
: width(t_width), height(t_height), x(t_x), y(t_y), name(std::move(t_name))
|
||||
@ -72,7 +72,7 @@ int main()
|
||||
chai.add(chaiscript::user_type<Factory>(), "Factory"); // this isn't strictly necessary but makes error messages nicer
|
||||
|
||||
|
||||
Factory f;
|
||||
Factory f{};
|
||||
chai.add(chaiscript::var(&f), "f");
|
||||
|
||||
std::string script = R""(
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
#else
|
||||
|
||||
char *mystrdup(const char *s) {
|
||||
size_t len = strlen(s); // Space for length plus nul
|
||||
const size_t len = strlen(s); // Space for length plus nul
|
||||
char *d = static_cast<char*>(malloc(len + 1));
|
||||
if (d == nullptr) return nullptr; // No memory
|
||||
#ifdef CHAISCRIPT_MSVC
|
||||
@ -75,8 +75,8 @@ std::vector<std::string> default_search_paths()
|
||||
|
||||
std::string exepath(path, size);
|
||||
|
||||
size_t lastslash = exepath.rfind('\\');
|
||||
size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
|
||||
const size_t lastslash = exepath.rfind('\\');
|
||||
const size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
|
||||
if (lastslash != std::string::npos)
|
||||
{
|
||||
paths.push_back(exepath.substr(0, lastslash));
|
||||
@ -84,7 +84,7 @@ std::vector<std::string> default_search_paths()
|
||||
|
||||
if (secondtolastslash != std::string::npos)
|
||||
{
|
||||
return{ exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\" };
|
||||
return{ exepath.substr(0, secondtolastslash) + R"(\lib\chaiscript\)"};
|
||||
}
|
||||
#else
|
||||
|
||||
@ -236,7 +236,7 @@ void interactive(chaiscript::ChaiScript& chai)
|
||||
using_history();
|
||||
|
||||
for (;;) {
|
||||
std::string input = get_next_command();
|
||||
const std::string input = get_next_command();
|
||||
try {
|
||||
// evaluate input
|
||||
chaiscript::Boxed_Value val = chai.eval(input);
|
||||
@ -251,7 +251,7 @@ void interactive(chaiscript::ChaiScript& chai)
|
||||
}
|
||||
catch (const chaiscript::exception::eval_error &ee) {
|
||||
std::cout << ee.what();
|
||||
if (ee.call_stack.size() > 0) {
|
||||
if (!ee.call_stack.empty()) {
|
||||
std::cout << "during evaluation at (" << ee.call_stack[0].start().line << ", " << ee.call_stack[0].start().column << ")";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
@ -315,7 +315,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
clock_t end = clock();
|
||||
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
|
||||
const double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
|
||||
|
||||
//begin = clock();
|
||||
|
||||
@ -375,7 +375,7 @@ int main(int argc, char *argv[])
|
||||
mode = eFile;
|
||||
}
|
||||
|
||||
chaiscript::Boxed_Value val;
|
||||
chaiscript::Boxed_Value val; /* never accessed? */
|
||||
try {
|
||||
switch (mode) {
|
||||
case eInteractive: interactive(chai); break;
|
||||
@ -386,7 +386,7 @@ int main(int argc, char *argv[])
|
||||
val = chai.eval_file(arg);
|
||||
|
||||
end = clock();
|
||||
double elapsed_secs1 = double(end - begin) / CLOCKS_PER_SEC;
|
||||
const auto elapsed_secs1 = double(end - begin) / CLOCKS_PER_SEC;
|
||||
printf("**C++::time= %.10f\n", elapsed_secs);
|
||||
printf("**ChaiScript::time= %.10f\n", elapsed_secs1);
|
||||
break;
|
||||
|
||||
@ -3,15 +3,13 @@
|
||||
class BaseClass
|
||||
{
|
||||
public:
|
||||
BaseClass()
|
||||
{
|
||||
}
|
||||
BaseClass() = default;
|
||||
|
||||
BaseClass(const BaseClass &) = default;
|
||||
BaseClass(const BaseClass &) = default;
|
||||
|
||||
virtual ~BaseClass() {}
|
||||
virtual ~BaseClass() = default;
|
||||
|
||||
virtual std::string doSomething(float, double) const = 0;
|
||||
virtual std::string doSomething(float, double) const = default;
|
||||
|
||||
|
||||
void setValue(const std::string &t_val) {
|
||||
@ -29,7 +27,7 @@ class BaseClass
|
||||
virtual bool validateValue(const std::string &t_val) = 0;
|
||||
|
||||
private:
|
||||
std::string m_value;
|
||||
std::string m_value{};
|
||||
};
|
||||
|
||||
class ChaiScriptDerived : public BaseClass
|
||||
@ -63,8 +61,8 @@ class ChaiScriptDerived : public BaseClass
|
||||
t_param = chaiscript::boxed_cast<Param>(t_func);
|
||||
}
|
||||
|
||||
std::function<std::string (const ChaiScriptDerived&, float, double)> m_doSomethingImpl;
|
||||
std::function<bool (ChaiScriptDerived&, const std::string &t_val)> m_validateValueImpl;
|
||||
std::function<std::string (const ChaiScriptDerived&, float, double)> m_doSomethingImpl{};
|
||||
std::function<bool (ChaiScriptDerived&, const std::string &t_val)> m_validateValueImpl{};
|
||||
};
|
||||
|
||||
int main()
|
||||
@ -126,7 +124,7 @@ int main()
|
||||
assert(myderived.getValue() == "new");
|
||||
|
||||
// call the other derived method via chaiscript and return the value to c++ land:
|
||||
std::string retval = chai.eval<std::string>("myderived.doSomething(2,4.3)");
|
||||
auto retval = chai.eval<std::string>("myderived.doSomething(2,4.3)");
|
||||
assert(retval == "new8.6");
|
||||
|
||||
// The whole process is fully orthogonal
|
||||
|
||||
@ -23,7 +23,7 @@ std::string get_next_command() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void function(void)
|
||||
void function()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
@ -40,7 +40,7 @@ class test
|
||||
chai.add(chaiscript::fun(&function),"Whatever()");
|
||||
}
|
||||
|
||||
void RunFile(std::string sFile)
|
||||
void RunFile(const std::string &sFile)
|
||||
{
|
||||
try {
|
||||
chaiscript::Boxed_Value val = chai.eval_file(sFile);
|
||||
@ -56,10 +56,10 @@ class test
|
||||
|
||||
int main(int /*argc*/, char * /*argv*/[]) {
|
||||
|
||||
test myChai;
|
||||
test myChai{};
|
||||
|
||||
|
||||
std::string command = "";
|
||||
std::string command;
|
||||
|
||||
//
|
||||
// this loop increases memory usage, if RunFile is not called (just hitting enter)
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#else
|
||||
|
||||
char *mystrdup (const char *s) {
|
||||
size_t len = strlen(s); // Space for length plus nul
|
||||
const size_t len = strlen(s); // Space for length plus nul
|
||||
char *d = static_cast<char*>(malloc (len+1));
|
||||
if (d == nullptr) { return nullptr; } // No memory
|
||||
#ifdef CHAISCRIPT_MSVC
|
||||
@ -78,8 +78,8 @@ std::vector<std::string> default_search_paths()
|
||||
|
||||
std::string exepath(path, size);
|
||||
|
||||
size_t lastslash = exepath.rfind('\\');
|
||||
size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
|
||||
const size_t lastslash = exepath.rfind('\\');
|
||||
const size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
|
||||
if (lastslash != std::string::npos)
|
||||
{
|
||||
paths.push_back(exepath.substr(0, lastslash));
|
||||
@ -87,7 +87,7 @@ std::vector<std::string> default_search_paths()
|
||||
|
||||
if (secondtolastslash != std::string::npos)
|
||||
{
|
||||
return {exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\"};
|
||||
return {exepath.substr(0, secondtolastslash) + R"(\lib\chaiscript\)"};
|
||||
}
|
||||
#else
|
||||
|
||||
@ -128,7 +128,7 @@ std::vector<std::string> default_search_paths()
|
||||
exepath = std::string(rInfo.dli_fname);
|
||||
}
|
||||
|
||||
size_t lastslash = exepath.rfind('/');
|
||||
const size_t lastslash = exepath.rfind('/');
|
||||
|
||||
size_t secondtolastslash = exepath.rfind('/', lastslash - 1);
|
||||
if (lastslash != std::string::npos)
|
||||
@ -231,7 +231,7 @@ void interactive(chaiscript::ChaiScript_Basic& chai)
|
||||
using_history();
|
||||
|
||||
for (;;) {
|
||||
std::string input = get_next_command();
|
||||
const std::string input = get_next_command();
|
||||
try {
|
||||
// evaluate input
|
||||
chaiscript::Boxed_Value val = chai.eval(input);
|
||||
|
||||
12
src/main.cpp
12
src/main.cpp
@ -27,7 +27,7 @@
|
||||
#else
|
||||
|
||||
char *mystrdup (const char *s) {
|
||||
size_t len = strlen(s); // Space for length plus nul
|
||||
const size_t len = strlen(s); // Space for length plus nul
|
||||
char *d = static_cast<char*>(malloc (len+1));
|
||||
if (d == nullptr) { return nullptr; } // No memory
|
||||
#ifdef CHAISCRIPT_MSVC
|
||||
@ -78,8 +78,8 @@ std::vector<std::string> default_search_paths()
|
||||
|
||||
std::string exepath(path, size);
|
||||
|
||||
size_t lastslash = exepath.rfind('\\');
|
||||
size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
|
||||
const size_t lastslash = exepath.rfind('\\');
|
||||
const size_t secondtolastslash = exepath.rfind('\\', lastslash - 1);
|
||||
if (lastslash != std::string::npos)
|
||||
{
|
||||
paths.push_back(exepath.substr(0, lastslash));
|
||||
@ -87,7 +87,7 @@ std::vector<std::string> default_search_paths()
|
||||
|
||||
if (secondtolastslash != std::string::npos)
|
||||
{
|
||||
return {exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\"};
|
||||
return {exepath.substr(0, secondtolastslash) + R"(\lib\chaiscript\)"};
|
||||
}
|
||||
#else
|
||||
|
||||
@ -128,7 +128,7 @@ std::vector<std::string> default_search_paths()
|
||||
exepath = std::string(rInfo.dli_fname);
|
||||
}
|
||||
|
||||
size_t lastslash = exepath.rfind('/');
|
||||
const size_t lastslash = exepath.rfind('/');
|
||||
|
||||
size_t secondtolastslash = exepath.rfind('/', lastslash - 1);
|
||||
if (lastslash != std::string::npos)
|
||||
@ -231,7 +231,7 @@ void interactive(chaiscript::ChaiScript_Basic& chai)
|
||||
using_history();
|
||||
|
||||
for (;;) {
|
||||
std::string input = get_next_command();
|
||||
const std::string input = get_next_command();
|
||||
try {
|
||||
// evaluate input
|
||||
chaiscript::Boxed_Value val = chai.eval(input);
|
||||
|
||||
@ -13,10 +13,10 @@ class TestBaseType
|
||||
TestBaseType(int *) : val(10), const_val(15), mdarray{} { }
|
||||
|
||||
TestBaseType(const TestBaseType &) = default;
|
||||
virtual ~TestBaseType() {}
|
||||
virtual ~TestBaseType() = default;
|
||||
virtual int func() { return 0; }
|
||||
|
||||
int base_only_func() { return -9; }
|
||||
int base_only_func() const { return -9; }
|
||||
|
||||
const TestBaseType &constMe() const { return *this; }
|
||||
|
||||
@ -24,19 +24,19 @@ class TestBaseType
|
||||
const int const_val;
|
||||
const int *const_val_ptr = &const_val;
|
||||
|
||||
const int *get_const_val_ptr() {
|
||||
const int *get_const_val_ptr() const {
|
||||
return const_val_ptr;
|
||||
}
|
||||
|
||||
int mdarray[2][3][5];
|
||||
std::function<int (int)> func_member;
|
||||
std::function<int (int)> func_member{};
|
||||
|
||||
void set_string_val(std::string &t_str)
|
||||
{
|
||||
t_str = "42";
|
||||
}
|
||||
|
||||
private:
|
||||
//private:
|
||||
TestBaseType &operator=(const TestBaseType &) = delete;
|
||||
};
|
||||
|
||||
@ -44,7 +44,7 @@ class Type2
|
||||
{
|
||||
public:
|
||||
Type2(TestBaseType t_bt)
|
||||
: m_bt(std::move(t_bt)),
|
||||
: m_bt(t_bt),
|
||||
m_str("Hello World")
|
||||
{
|
||||
}
|
||||
@ -77,14 +77,15 @@ int to_int(TestEnum t)
|
||||
|
||||
class TestDerivedType : public TestBaseType
|
||||
{
|
||||
;
|
||||
public:
|
||||
virtual ~TestDerivedType() {}
|
||||
virtual ~TestDerivedType() = default;
|
||||
TestDerivedType(const TestDerivedType &) = default;
|
||||
TestDerivedType() = default;
|
||||
virtual int func() override { return 1; }
|
||||
int derived_only_func() { return 19; }
|
||||
|
||||
private:
|
||||
//private:
|
||||
TestDerivedType &operator=(const TestDerivedType &) = delete;
|
||||
};
|
||||
|
||||
@ -93,7 +94,7 @@ class TestMoreDerivedType : public TestDerivedType
|
||||
public:
|
||||
TestMoreDerivedType(const TestMoreDerivedType &) = default;
|
||||
TestMoreDerivedType() = default;
|
||||
virtual ~TestMoreDerivedType() {}
|
||||
virtual ~TestMoreDerivedType() = default;
|
||||
};
|
||||
|
||||
std::shared_ptr<TestBaseType> derived_type_factory()
|
||||
|
||||
@ -27,19 +27,14 @@ bool run_test_type_conversion(const Boxed_Value &bv, bool expectedpass)
|
||||
std::cerr << "Unexpected unknown exception when attempting cast_conversion.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (expectedpass)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return expectedpass;
|
||||
}
|
||||
|
||||
template<typename To>
|
||||
bool test_type_conversion(const Boxed_Value &bv, bool expectedpass)
|
||||
{
|
||||
bool ret = run_test_type_conversion<To>(bv, expectedpass);
|
||||
const bool ret = run_test_type_conversion<To>(bv, expectedpass);
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
@ -113,7 +108,7 @@ bool built_in_type_test(const T &initial, bool ispod)
|
||||
bool passed = true;
|
||||
|
||||
/** value tests **/
|
||||
T i = T(initial);
|
||||
auto i = T(initial);
|
||||
passed &= do_test<T>(var(i), true, true, true, true, true,
|
||||
true, true, true, true, true,
|
||||
true, true, true, true, true, true,
|
||||
@ -256,7 +251,7 @@ bool built_in_type_test(const T &initial, bool ispod)
|
||||
template<typename T>
|
||||
bool pointer_test(const T& default_value, const T& new_value)
|
||||
{
|
||||
T *p = new T(default_value);
|
||||
auto *p = new T(default_value);
|
||||
|
||||
// we store a pointer to a pointer, so we can get a pointer to a pointer
|
||||
try {
|
||||
|
||||
@ -583,7 +583,7 @@ namespace Catch {
|
||||
struct AssertionInfo
|
||||
{
|
||||
StringRef macroName;
|
||||
SourceLineInfo lineInfo;
|
||||
SourceLineInfo lineInfo{};
|
||||
StringRef capturedExpression;
|
||||
ResultDisposition::Flags resultDisposition;
|
||||
|
||||
@ -769,7 +769,7 @@ namespace Catch {
|
||||
// Should be preferably called fully qualified, like ::Catch::Detail::stringify
|
||||
template <typename T>
|
||||
std::string stringify(const T& e) {
|
||||
return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
|
||||
return StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
@ -1068,7 +1068,7 @@ namespace Catch {
|
||||
return rss.str();
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
template<typename R> /* TODO::Declaration doesn't declare anything */
|
||||
struct StringMaker<R, typename std::enable_if<is_range<R>::value && !is_string_array<R>::value>::type> {
|
||||
static std::string convert( R const& range ) {
|
||||
return rangeToString( range );
|
||||
@ -1347,7 +1347,7 @@ namespace Catch {
|
||||
return ExprLhs<T const&>{ lhs };
|
||||
}
|
||||
|
||||
auto operator <=( bool value ) -> ExprLhs<bool> {
|
||||
auto operator <=( bool value ) const -> ExprLhs<bool> {
|
||||
return ExprLhs<bool>{ value };
|
||||
}
|
||||
};
|
||||
@ -2004,7 +2004,7 @@ namespace Detail {
|
||||
|
||||
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||
friend bool operator == ( const T& lhs, Approx const& rhs ) {
|
||||
auto lhs_v = static_cast<double>(lhs);
|
||||
const auto lhs_v = static_cast<double>(lhs);
|
||||
return rhs.equalityComparisonImpl(lhs_v);
|
||||
}
|
||||
|
||||
@ -2045,7 +2045,7 @@ namespace Detail {
|
||||
|
||||
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||
Approx& epsilon( T const& newEpsilon ) {
|
||||
double epsilonAsDouble = static_cast<double>(newEpsilon);
|
||||
const double epsilonAsDouble = static_cast<double>(newEpsilon);
|
||||
if( epsilonAsDouble < 0 || epsilonAsDouble > 1.0 ) {
|
||||
throw std::domain_error
|
||||
( "Invalid Approx::epsilon: " +
|
||||
@ -2058,7 +2058,7 @@ namespace Detail {
|
||||
|
||||
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||
Approx& margin( T const& newMargin ) {
|
||||
double marginAsDouble = static_cast<double>(newMargin);
|
||||
const double marginAsDouble = static_cast<double>(newMargin);
|
||||
if( marginAsDouble < 0 ) {
|
||||
throw std::domain_error
|
||||
( "Invalid Approx::margin: " +
|
||||
@ -2153,11 +2153,17 @@ namespace Matchers {
|
||||
|
||||
template<typename ObjectT>
|
||||
struct MatcherMethod {
|
||||
virtual bool match( ObjectT const& arg ) const = 0;
|
||||
protected:
|
||||
~MatcherMethod() = default;
|
||||
public:
|
||||
virtual bool match( ObjectT const& arg ) const = 0;
|
||||
};
|
||||
template<typename PtrT>
|
||||
struct MatcherMethod<PtrT*> {
|
||||
virtual bool match( PtrT* arg ) const = 0;
|
||||
protected:
|
||||
~MatcherMethod() = default;
|
||||
public:
|
||||
virtual bool match( PtrT* arg ) const = 0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -4495,24 +4501,24 @@ bool marginComparison(double lhs, double rhs, double margin) {
|
||||
namespace Catch {
|
||||
namespace Detail {
|
||||
|
||||
Approx::Approx ( double value )
|
||||
inline Approx::Approx ( double value )
|
||||
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
||||
m_margin( 0.0 ),
|
||||
m_scale( 0.0 ),
|
||||
m_value( value )
|
||||
{}
|
||||
|
||||
Approx Approx::custom() {
|
||||
inline Approx Approx::custom() {
|
||||
return Approx( 0 );
|
||||
}
|
||||
|
||||
std::string Approx::toString() const {
|
||||
inline std::string Approx::toString() const {
|
||||
ReusableStringStream rss;
|
||||
rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )";
|
||||
return rss.str();
|
||||
}
|
||||
|
||||
bool Approx::equalityComparisonImpl(const double other) const {
|
||||
inline bool Approx::equalityComparisonImpl(const double other) const {
|
||||
// First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
|
||||
// Thanks to Richard Harris for his help refining the scaled margin value
|
||||
return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value)));
|
||||
@ -4520,7 +4526,7 @@ namespace Detail {
|
||||
|
||||
} // end namespace Detail
|
||||
|
||||
std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
|
||||
inline std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
@ -4843,22 +4849,22 @@ namespace Catch {
|
||||
// end catch_run_context.h
|
||||
namespace Catch {
|
||||
|
||||
auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
|
||||
inline auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
|
||||
expr.streamReconstructedExpression( os );
|
||||
return os;
|
||||
}
|
||||
|
||||
LazyExpression::LazyExpression( bool isNegated )
|
||||
inline LazyExpression::LazyExpression( bool isNegated )
|
||||
: m_isNegated( isNegated )
|
||||
{}
|
||||
|
||||
LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
|
||||
inline LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
|
||||
|
||||
LazyExpression::operator bool() const {
|
||||
inline LazyExpression::operator bool() const {
|
||||
return m_transientExpression != nullptr;
|
||||
}
|
||||
|
||||
auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
|
||||
inline auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
|
||||
if( lazyExpr.m_isNegated )
|
||||
os << "!";
|
||||
|
||||
@ -4874,7 +4880,7 @@ namespace Catch {
|
||||
return os;
|
||||
}
|
||||
|
||||
AssertionHandler::AssertionHandler
|
||||
inline AssertionHandler::AssertionHandler
|
||||
( StringRef macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
StringRef capturedExpression,
|
||||
@ -4883,18 +4889,19 @@ namespace Catch {
|
||||
m_resultCapture( getResultCapture() )
|
||||
{}
|
||||
|
||||
void AssertionHandler::handleExpr( ITransientExpression const& expr ) {
|
||||
inline void AssertionHandler::handleExpr( ITransientExpression const& expr ) {
|
||||
m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction );
|
||||
}
|
||||
void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) {
|
||||
|
||||
inline void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) {
|
||||
m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction );
|
||||
}
|
||||
|
||||
auto AssertionHandler::allowThrows() const -> bool {
|
||||
inline auto AssertionHandler::allowThrows() const -> bool {
|
||||
return getCurrentContext().getConfig()->allowThrows();
|
||||
}
|
||||
|
||||
void AssertionHandler::complete() {
|
||||
inline void AssertionHandler::complete() {
|
||||
setCompleted();
|
||||
if( m_reaction.shouldDebugBreak ) {
|
||||
|
||||
@ -4907,18 +4914,20 @@ namespace Catch {
|
||||
if( m_reaction.shouldThrow )
|
||||
throw Catch::TestFailureException();
|
||||
}
|
||||
void AssertionHandler::setCompleted() {
|
||||
|
||||
inline void AssertionHandler::setCompleted() {
|
||||
m_completed = true;
|
||||
}
|
||||
|
||||
void AssertionHandler::handleUnexpectedInflightException() {
|
||||
inline void AssertionHandler::handleUnexpectedInflightException() {
|
||||
m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction );
|
||||
}
|
||||
|
||||
void AssertionHandler::handleExceptionThrownAsExpected() {
|
||||
inline void AssertionHandler::handleExceptionThrownAsExpected() {
|
||||
m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
|
||||
}
|
||||
void AssertionHandler::handleExceptionNotThrownAsExpected() {
|
||||
|
||||
inline void AssertionHandler::handleExceptionNotThrownAsExpected() {
|
||||
m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
|
||||
}
|
||||
|
||||
@ -5041,7 +5050,7 @@ namespace Catch {
|
||||
getResultCapture().benchmarkStarting( { m_name } );
|
||||
}
|
||||
auto BenchmarkLooper::needsMoreIterations() -> bool {
|
||||
auto elapsed = m_timer.getElapsedNanoseconds();
|
||||
const auto elapsed = m_timer.getElapsedNanoseconds();
|
||||
|
||||
// Exponentially increasing iterations until we're confident in our timer resolution
|
||||
if( elapsed < m_resolution ) {
|
||||
@ -5065,8 +5074,8 @@ namespace Catch {
|
||||
// There is another overload, in catch_assertinhandler.h/.cpp, that only takes a string and infers
|
||||
// the Equals matcher (so the header does not mention matchers)
|
||||
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) {
|
||||
std::string exceptionMessage = Catch::translateActiveException();
|
||||
MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
|
||||
const std::string exceptionMessage = Catch::translateActiveException();
|
||||
const MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
|
||||
handler.handleExpr( expr );
|
||||
}
|
||||
|
||||
@ -5182,7 +5191,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
assert( m_stringIndex < m_column.m_strings.size() );
|
||||
|
||||
m_suffix = false;
|
||||
auto width = m_column.m_width-indent();
|
||||
const auto width = m_column.m_width-indent();
|
||||
m_end = m_pos;
|
||||
while( m_end < line().size() && line()[m_end] != '\n' )
|
||||
++m_end;
|
||||
@ -5207,7 +5216,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
}
|
||||
|
||||
auto indent() const -> size_t {
|
||||
auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos;
|
||||
const auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos;
|
||||
return initial == std::string::npos ? m_column.m_indent : initial;
|
||||
}
|
||||
|
||||
@ -5289,7 +5298,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
|
||||
inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) {
|
||||
bool first = true;
|
||||
for( auto line : col ) {
|
||||
for(const auto line : col ) {
|
||||
if( first )
|
||||
first = false;
|
||||
else
|
||||
@ -5299,7 +5308,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
return os;
|
||||
}
|
||||
|
||||
auto operator + ( Column const& other ) -> Columns;
|
||||
auto operator + ( Column const& other ) const -> Columns;
|
||||
|
||||
auto toString() const -> std::string {
|
||||
std::ostringstream oss;
|
||||
@ -5360,7 +5369,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
std::string row, padding;
|
||||
|
||||
for( size_t i = 0; i < m_columns.size(); ++i ) {
|
||||
auto width = m_columns[i].width();
|
||||
const auto width = m_columns[i].width();
|
||||
if( m_iterators[i] != m_columns[i].end() ) {
|
||||
std::string col = *m_iterators[i];
|
||||
row += padding + col;
|
||||
@ -5397,7 +5406,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
m_columns.push_back( col );
|
||||
return *this;
|
||||
}
|
||||
auto operator + ( Column const& col ) -> Columns {
|
||||
auto operator + ( Column const& col ) const -> Columns {
|
||||
Columns combined = *this;
|
||||
combined += col;
|
||||
return combined;
|
||||
@ -5423,7 +5432,7 @@ namespace Catch { namespace clara { namespace TextFlow {
|
||||
}
|
||||
};
|
||||
|
||||
inline auto Column::operator + ( Column const& other ) -> Columns {
|
||||
inline auto Column::operator + ( Column const& other ) const -> Columns {
|
||||
Columns cols;
|
||||
cols += *this;
|
||||
cols += other;
|
||||
@ -5521,7 +5530,7 @@ namespace detail {
|
||||
if( it != itEnd ) {
|
||||
auto const &next = *it;
|
||||
if( isOptPrefix( next[0] ) ) {
|
||||
auto delimiterPos = next.find_first_of( " :=" );
|
||||
const auto delimiterPos = next.find_first_of( " :=" );
|
||||
if( delimiterPos != std::string::npos ) {
|
||||
m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } );
|
||||
m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } );
|
||||
@ -5659,7 +5668,7 @@ namespace detail {
|
||||
auto errorMessage() const -> std::string { return m_errorMessage; }
|
||||
|
||||
protected:
|
||||
virtual void enforceOk() const {
|
||||
void enforceOk() const override {
|
||||
// !TBD: If no exceptions, std::terminate here or something
|
||||
switch( m_type ) {
|
||||
case ResultBase::LogicError:
|
||||
@ -5668,6 +5677,7 @@ namespace detail {
|
||||
throw std::runtime_error( m_errorMessage );
|
||||
case ResultBase::Ok:
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5970,10 +5980,10 @@ namespace detail {
|
||||
}
|
||||
|
||||
auto name() const -> std::string { return *m_name; }
|
||||
auto set( std::string const& newName ) -> ParserResult {
|
||||
auto set( std::string const& newName ) const -> ParserResult {
|
||||
|
||||
auto lastSlash = newName.find_last_of( "\\/" );
|
||||
auto filename = ( lastSlash == std::string::npos )
|
||||
const auto lastSlash = newName.find_last_of( "\\/" );
|
||||
const auto filename = ( lastSlash == std::string::npos )
|
||||
? newName
|
||||
: newName.substr( lastSlash+1 );
|
||||
|
||||
@ -5990,7 +6000,7 @@ namespace detail {
|
||||
using ParserRefImpl::ParserRefImpl;
|
||||
|
||||
auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override {
|
||||
auto validationResult = validate();
|
||||
const auto validationResult = validate();
|
||||
if( !validationResult )
|
||||
return InternalParseResult( validationResult );
|
||||
|
||||
@ -5999,7 +6009,7 @@ namespace detail {
|
||||
if( token.type != TokenType::Argument )
|
||||
return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
|
||||
|
||||
auto result = m_ref->setValue( remainingTokens->token );
|
||||
const auto result = m_ref->setValue( remainingTokens->token );
|
||||
if( !result )
|
||||
return InternalParseResult( result );
|
||||
else
|
||||
@ -6053,7 +6063,7 @@ namespace detail {
|
||||
}
|
||||
|
||||
auto isMatch( std::string const &optToken ) const -> bool {
|
||||
auto normalisedToken = normaliseOpt( optToken );
|
||||
const auto normalisedToken = normaliseOpt( optToken );
|
||||
for( auto const &name : m_optNames ) {
|
||||
if( normaliseOpt( name ) == normalisedToken )
|
||||
return true;
|
||||
@ -6064,7 +6074,7 @@ namespace detail {
|
||||
using ParserBase::parse;
|
||||
|
||||
auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
|
||||
auto validationResult = validate();
|
||||
const auto validationResult = validate();
|
||||
if( !validationResult )
|
||||
return InternalParseResult( validationResult );
|
||||
|
||||
@ -6195,13 +6205,13 @@ namespace detail {
|
||||
}
|
||||
|
||||
auto rows = getHelpColumns();
|
||||
size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH;
|
||||
const size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH;
|
||||
size_t optWidth = 0;
|
||||
for( auto const &cols : rows )
|
||||
optWidth = (std::max)(optWidth, cols.left.size() + 2);
|
||||
|
||||
for( auto const &cols : rows ) {
|
||||
auto row =
|
||||
const auto row =
|
||||
TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) +
|
||||
TextFlow::Spacer(4) +
|
||||
TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth );
|
||||
@ -6641,7 +6651,7 @@ namespace Catch {
|
||||
};
|
||||
|
||||
struct NoColourImpl : IColourImpl {
|
||||
void use( Colour::Code ) {}
|
||||
void use( Colour::Code ) override {}
|
||||
|
||||
static IColourImpl* instance() {
|
||||
static NoColourImpl s_instance;
|
||||
@ -6696,7 +6706,7 @@ namespace {
|
||||
}
|
||||
|
||||
private:
|
||||
void setTextAttribute( WORD _textAttribute ) {
|
||||
void setTextAttribute( WORD _textAttribute ) const {
|
||||
SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
|
||||
}
|
||||
HANDLE stdoutHandle;
|
||||
@ -6707,7 +6717,7 @@ namespace {
|
||||
IColourImpl* platformColourInstance() {
|
||||
static Win32ColourImpl s_instance;
|
||||
|
||||
IConfigPtr config = getCurrentContext().getConfig();
|
||||
const IConfigPtr config = getCurrentContext().getConfig();
|
||||
UseColour::YesOrNo colourMode = config
|
||||
? config->useColour()
|
||||
: UseColour::Auto;
|
||||
@ -7461,13 +7471,13 @@ namespace Catch {
|
||||
return;
|
||||
}
|
||||
|
||||
MultipleReporters* multi = nullptr;
|
||||
MultipleReporters* multi;
|
||||
|
||||
if( existingReporter->isMulti() ) {
|
||||
multi = static_cast<MultipleReporters*>( existingReporter.get() );
|
||||
}
|
||||
else {
|
||||
auto newMulti = std::unique_ptr<MultipleReporters>( new MultipleReporters );
|
||||
auto newMulti = std::make_unique<MultipleReporters>();
|
||||
newMulti->add( std::move( existingReporter ) );
|
||||
multi = newMulti.get();
|
||||
existingReporter = std::move( newMulti );
|
||||
@ -7568,7 +7578,7 @@ namespace Catch {
|
||||
|
||||
auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
||||
for( auto const& testCaseInfo : matchedTestCases ) {
|
||||
Colour::Code colour = testCaseInfo.isHidden()
|
||||
const Colour::Code colour = testCaseInfo.isHidden()
|
||||
? Colour::SecondaryText
|
||||
: Colour::None;
|
||||
Colour colourGuard( colour );
|
||||
@ -7649,7 +7659,7 @@ namespace Catch {
|
||||
ReusableStringStream rss;
|
||||
rss << " " << std::setw(2) << tagCount.second.count << " ";
|
||||
auto str = rss.str();
|
||||
auto wrapper = Column( tagCount.second.all() )
|
||||
const auto wrapper = Column( tagCount.second.all() )
|
||||
.initialIndent( 0 )
|
||||
.indent( str.size() )
|
||||
.width( CATCH_CONFIG_CONSOLE_WIDTH-10 );
|
||||
@ -7918,7 +7928,7 @@ namespace Matchers {
|
||||
if (m_caseSensitivity == CaseSensitive::Choice::No) {
|
||||
flags |= std::regex::icase;
|
||||
}
|
||||
auto reg = std::regex(m_regex, flags);
|
||||
const auto reg = std::regex(m_regex, flags);
|
||||
return std::regex_match(matchee, reg);
|
||||
}
|
||||
|
||||
@ -8281,7 +8291,7 @@ namespace Catch {
|
||||
ReporterRegistry::~ReporterRegistry() = default;
|
||||
|
||||
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
|
||||
auto it = m_factories.find( name );
|
||||
const auto it = m_factories.find( name );
|
||||
if( it == m_factories.end() )
|
||||
return nullptr;
|
||||
return it->second->create( ReporterConfig( config ) );
|
||||
@ -8387,7 +8397,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
RunContext::~RunContext() {
|
||||
m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting()));
|
||||
m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, RunContext::aborting()));
|
||||
}
|
||||
|
||||
void RunContext::testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount) {
|
||||
@ -8399,7 +8409,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
Totals RunContext::runTest(TestCase const& testCase) {
|
||||
Totals prevTotals = m_totals;
|
||||
const Totals prevTotals = m_totals;
|
||||
|
||||
std::string redirectedCout;
|
||||
std::string redirectedCerr;
|
||||
@ -8503,7 +8513,7 @@ namespace Catch {
|
||||
|
||||
void RunContext::sectionEnded(SectionEndInfo const & endInfo) {
|
||||
Counts assertions = m_totals.assertions - endInfo.prevAssertions;
|
||||
bool missingAssertions = testForMissingAssertions(assertions);
|
||||
const bool missingAssertions = testForMissingAssertions(assertions);
|
||||
|
||||
if (!m_activeSections.empty()) {
|
||||
m_activeSections.back()->close();
|
||||
@ -8560,7 +8570,7 @@ namespace Catch {
|
||||
// Instead, fake a result data.
|
||||
AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } );
|
||||
tempResult.message = message;
|
||||
AssertionResult result(m_lastAssertionInfo, tempResult);
|
||||
const AssertionResult result(m_lastAssertionInfo, tempResult);
|
||||
|
||||
assertionEnded(result);
|
||||
|
||||
@ -8568,11 +8578,11 @@ namespace Catch {
|
||||
|
||||
// Recreate section for test case (as we will lose the one that was in scope)
|
||||
auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
|
||||
SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description);
|
||||
const SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description);
|
||||
|
||||
Counts assertions;
|
||||
assertions.failed = 1;
|
||||
SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false);
|
||||
const SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false);
|
||||
m_reporter->sectionEnded(testCaseSectionStats);
|
||||
|
||||
auto const& testInfo = m_activeTestCase->getTestCaseInfo();
|
||||
@ -8606,9 +8616,9 @@ namespace Catch {
|
||||
|
||||
void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) {
|
||||
auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
|
||||
SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description);
|
||||
const SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description);
|
||||
m_reporter->sectionStarting(testCaseSection);
|
||||
Counts prevAssertions = m_totals.assertions;
|
||||
const Counts prevAssertions = m_totals.assertions;
|
||||
double duration = 0;
|
||||
m_shouldReportUnexpected = true;
|
||||
m_lastAssertionInfo = { "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal };
|
||||
@ -8645,8 +8655,8 @@ namespace Catch {
|
||||
m_messages.clear();
|
||||
|
||||
Counts assertions = m_totals.assertions - prevAssertions;
|
||||
bool missingAssertions = testForMissingAssertions(assertions);
|
||||
SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions);
|
||||
const bool missingAssertions = testForMissingAssertions(assertions);
|
||||
const SectionStats testCaseSectionStats(testCaseSection, assertions, duration, missingAssertions);
|
||||
m_reporter->sectionEnded(testCaseSectionStats);
|
||||
}
|
||||
|
||||
@ -8674,8 +8684,8 @@ namespace Catch {
|
||||
) {
|
||||
m_reporter->assertionStarting( info );
|
||||
|
||||
bool negated = isFalseTest( info.resultDisposition );
|
||||
bool result = expr.getResult() != negated;
|
||||
const bool negated = isFalseTest( info.resultDisposition );
|
||||
const bool result = expr.getResult() != negated;
|
||||
|
||||
if( result ) {
|
||||
if (!m_includeSuccessfulResults) {
|
||||
@ -8697,7 +8707,7 @@ namespace Catch {
|
||||
bool negated ) {
|
||||
|
||||
m_lastAssertionInfo = info;
|
||||
AssertionResultData data( resultType, LazyExpression( negated ) );
|
||||
const AssertionResultData data( resultType, LazyExpression( negated ) );
|
||||
|
||||
AssertionResult assertionResult{ info, data };
|
||||
assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
|
||||
@ -8738,7 +8748,7 @@ namespace Catch {
|
||||
|
||||
AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
|
||||
data.message = message;
|
||||
AssertionResult assertionResult{ info, data };
|
||||
const AssertionResult assertionResult{ info, data };
|
||||
assertionEnded( assertionResult );
|
||||
populateReaction( reaction );
|
||||
}
|
||||
@ -8755,7 +8765,7 @@ namespace Catch {
|
||||
|
||||
AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) );
|
||||
data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
|
||||
AssertionResult assertionResult{ info, data };
|
||||
const AssertionResult assertionResult{ info, data };
|
||||
assertionEnded( assertionResult );
|
||||
}
|
||||
void RunContext::handleNonExpr(
|
||||
@ -8765,7 +8775,7 @@ namespace Catch {
|
||||
) {
|
||||
m_lastAssertionInfo = info;
|
||||
|
||||
AssertionResultData data( resultType, LazyExpression( false ) );
|
||||
const AssertionResultData data( resultType, LazyExpression( false ) );
|
||||
AssertionResult assertionResult{ info, data };
|
||||
assertionEnded( assertionResult );
|
||||
|
||||
@ -8798,7 +8808,7 @@ namespace Catch {
|
||||
#endif
|
||||
Section::~Section() {
|
||||
if( m_sectionIncluded ) {
|
||||
SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
||||
const SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
|
||||
if( std::uncaught_exception() )
|
||||
getResultCapture().sectionEndedEarly( endInfo );
|
||||
else
|
||||
@ -8891,7 +8901,7 @@ namespace Catch {
|
||||
Version( unsigned int _majorVersion,
|
||||
unsigned int _minorVersion,
|
||||
unsigned int _patchNumber,
|
||||
char const * const _branchName,
|
||||
char const *_branchName,
|
||||
unsigned int _buildNumber );
|
||||
|
||||
unsigned int const majorVersion;
|
||||
@ -8979,13 +8989,13 @@ namespace Catch {
|
||||
auto tags = testCase.tags;
|
||||
|
||||
std::string filename = testCase.lineInfo.file;
|
||||
auto lastSlash = filename.find_last_of("\\/");
|
||||
const auto lastSlash = filename.find_last_of("\\/");
|
||||
if (lastSlash != std::string::npos) {
|
||||
filename.erase(0, lastSlash);
|
||||
filename[0] = '#';
|
||||
}
|
||||
|
||||
auto lastDot = filename.find_last_of('.');
|
||||
const auto lastDot = filename.find_last_of('.');
|
||||
if (lastDot != std::string::npos) {
|
||||
filename.erase(lastDot);
|
||||
}
|
||||
@ -9105,7 +9115,7 @@ namespace Catch {
|
||||
Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
|
||||
static_cast<void>(std::getchar());
|
||||
}
|
||||
int exitCode = runInternal();
|
||||
const int exitCode = runInternal();
|
||||
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
|
||||
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
|
||||
static_cast<void>(std::getchar());
|
||||
@ -9236,7 +9246,7 @@ namespace Catch {
|
||||
|
||||
struct OutputDebugWriter {
|
||||
|
||||
void operator()( std::string const&str ) {
|
||||
void operator()( std::string const&str ) const {
|
||||
writeToDebugConsole( str );
|
||||
}
|
||||
};
|
||||
@ -9314,11 +9324,11 @@ namespace Catch {
|
||||
|
||||
auto add() -> std::size_t {
|
||||
if( m_unused.empty() ) {
|
||||
m_streams.push_back( std::unique_ptr<std::ostringstream>( new std::ostringstream ) );
|
||||
m_streams.push_back(std::make_unique<std::ostringstream>());
|
||||
return m_streams.size()-1;
|
||||
}
|
||||
else {
|
||||
auto index = m_unused.back();
|
||||
const auto index = m_unused.back();
|
||||
m_unused.pop_back();
|
||||
return index;
|
||||
}
|
||||
@ -9412,8 +9422,8 @@ namespace Catch {
|
||||
}
|
||||
std::string trim( std::string const& str ) {
|
||||
static char const* whitespaceChars = "\n\r\t ";
|
||||
std::string::size_type start = str.find_first_not_of( whitespaceChars );
|
||||
std::string::size_type end = str.find_last_not_of( whitespaceChars );
|
||||
const std::string::size_type start = str.find_first_not_of( whitespaceChars );
|
||||
const std::string::size_type end = str.find_last_not_of( whitespaceChars );
|
||||
|
||||
return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
|
||||
}
|
||||
@ -9518,7 +9528,7 @@ namespace Catch {
|
||||
size_type noChars = m_size;
|
||||
// Make adjustments for uft encodings
|
||||
for( size_type i=0; i < m_size; ++i ) {
|
||||
char c = m_start[i];
|
||||
const char c = m_start[i];
|
||||
if( ( c & 0b11000000 ) == 0b11000000 ) {
|
||||
if( ( c & 0b11100000 ) == 0b11000000 )
|
||||
noChars--;
|
||||
@ -9595,7 +9605,7 @@ namespace Catch {
|
||||
std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
|
||||
std::string expandedTestSpec = unexpandedTestSpec;
|
||||
for( auto const& registryKvp : m_registry ) {
|
||||
std::size_t pos = expandedTestSpec.find( registryKvp.first );
|
||||
const auto pos = expandedTestSpec.find( registryKvp.first );
|
||||
if( pos != std::string::npos ) {
|
||||
expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
|
||||
registryKvp.second.tag +
|
||||
@ -9680,7 +9690,7 @@ namespace Catch {
|
||||
}
|
||||
else {
|
||||
if( c == ']' ) {
|
||||
TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
|
||||
const TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
|
||||
if( ( prop & TestCaseInfo::IsHidden ) != 0 )
|
||||
isHidden = true;
|
||||
else if( prop == TestCaseInfo::None )
|
||||
@ -9698,7 +9708,7 @@ namespace Catch {
|
||||
tags.push_back( "." );
|
||||
}
|
||||
|
||||
TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
|
||||
const TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
|
||||
return TestCase( _testCase, info );
|
||||
}
|
||||
|
||||
@ -9708,7 +9718,7 @@ namespace Catch {
|
||||
testCaseInfo.lcaseTags.clear();
|
||||
|
||||
for( auto const& tag : tags ) {
|
||||
std::string lcaseTag = toLower( tag );
|
||||
const std::string lcaseTag = toLower( tag );
|
||||
testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
|
||||
testCaseInfo.lcaseTags.push_back( lcaseTag );
|
||||
}
|
||||
@ -9819,7 +9829,7 @@ namespace Catch {
|
||||
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
|
||||
std::set<TestCase> seenFunctions;
|
||||
for( auto const& function : functions ) {
|
||||
auto prev = seenFunctions.insert( function );
|
||||
const auto prev = seenFunctions.insert( function );
|
||||
CATCH_ENFORCE( prev.second,
|
||||
"error: TEST_CASE( \"" << function.name << "\" ) already defined.\n"
|
||||
<< "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
|
||||
@ -9874,7 +9884,7 @@ namespace Catch {
|
||||
std::string className = classOrQualifiedMethodName;
|
||||
if( startsWith( className, '&' ) )
|
||||
{
|
||||
std::size_t lastColons = className.rfind( "::" );
|
||||
const std::size_t lastColons = className.rfind( "::" );
|
||||
std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
|
||||
if( penultimateColons == std::string::npos )
|
||||
penultimateColons = 1;
|
||||
@ -9978,7 +9988,7 @@ namespace TestCaseTracking {
|
||||
}
|
||||
|
||||
ITrackerPtr TrackerBase::findChild( NameAndLocation const& nameAndLocation ) {
|
||||
auto it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) );
|
||||
const auto it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) );
|
||||
return( it != m_children.end() )
|
||||
? *it
|
||||
: nullptr;
|
||||
@ -10072,7 +10082,7 @@ namespace TestCaseTracking {
|
||||
std::shared_ptr<SectionTracker> section;
|
||||
|
||||
ITracker& currentTracker = ctx.currentTracker();
|
||||
if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
|
||||
if( const ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
|
||||
assert( childTracker );
|
||||
assert( childTracker->isSectionTracker() );
|
||||
section = std::static_pointer_cast<SectionTracker>( childTracker );
|
||||
@ -10114,7 +10124,7 @@ namespace TestCaseTracking {
|
||||
std::shared_ptr<IndexTracker> tracker;
|
||||
|
||||
ITracker& currentTracker = ctx.currentTracker();
|
||||
if( ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
|
||||
if( const ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
|
||||
assert( childTracker );
|
||||
assert( childTracker->isIndexTracker() );
|
||||
tracker = std::static_pointer_cast<IndexTracker>( childTracker );
|
||||
@ -10338,13 +10348,13 @@ namespace Catch {
|
||||
for( std::size_t i = 0; i < iterations; ++i ) {
|
||||
|
||||
uint64_t ticks;
|
||||
uint64_t baseTicks = getCurrentNanosecondsSinceEpoch();
|
||||
const uint64_t baseTicks = getCurrentNanosecondsSinceEpoch();
|
||||
do {
|
||||
ticks = getCurrentNanosecondsSinceEpoch();
|
||||
}
|
||||
while( ticks == baseTicks );
|
||||
|
||||
auto delta = ticks - baseTicks;
|
||||
const auto delta = ticks - baseTicks;
|
||||
sum += delta;
|
||||
}
|
||||
|
||||
@ -10753,7 +10763,7 @@ namespace Catch {
|
||||
// (see: http://www.w3.org/TR/xml/#syntax)
|
||||
|
||||
for( std::size_t i = 0; i < m_str.size(); ++ i ) {
|
||||
char c = m_str[i];
|
||||
const char c = m_str[i];
|
||||
switch( c ) {
|
||||
case '<': os << "<"; break;
|
||||
case '&': os << "&"; break;
|
||||
@ -10873,7 +10883,7 @@ namespace Catch {
|
||||
|
||||
XmlWriter& XmlWriter::writeText( std::string const& text, bool indent ) {
|
||||
if( !text.empty() ){
|
||||
bool tagWasOpen = m_tagIsOpen;
|
||||
const bool tagWasOpen = m_tagIsOpen;
|
||||
ensureTagClosed();
|
||||
if( tagWasOpen && indent )
|
||||
m_os << m_indent;
|
||||
@ -11125,7 +11135,7 @@ private:
|
||||
stream << ' ' << issue;
|
||||
}
|
||||
|
||||
void printExpressionWas() {
|
||||
void printExpressionWas() const {
|
||||
if (result.hasExpression()) {
|
||||
stream << ';';
|
||||
{
|
||||
@ -11164,7 +11174,7 @@ private:
|
||||
return;
|
||||
|
||||
// using messages.end() directly yields (or auto) compilation error:
|
||||
std::vector<MessageInfo>::const_iterator itEnd = messages.end();
|
||||
const std::vector<MessageInfo>::const_iterator itEnd = messages.end();
|
||||
const std::size_t N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
|
||||
|
||||
{
|
||||
@ -11404,7 +11414,7 @@ private:
|
||||
};
|
||||
|
||||
std::size_t makeRatio(std::size_t number, std::size_t total) {
|
||||
std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
|
||||
const std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number / total : 0;
|
||||
return (ratio == 0 && number > 0) ? 1 : ratio;
|
||||
}
|
||||
|
||||
@ -11540,9 +11550,9 @@ public:
|
||||
}
|
||||
|
||||
friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) {
|
||||
auto colStr = tp.m_oss.str();
|
||||
const auto colStr = tp.m_oss.str();
|
||||
// This takes account of utf8 encodings
|
||||
auto strSize = Catch::StringRef(colStr).numberOfCharacters();
|
||||
const auto strSize = Catch::StringRef(colStr).numberOfCharacters();
|
||||
tp.m_oss.str("");
|
||||
tp.open();
|
||||
if (tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size() - 1)) {
|
||||
@ -11551,8 +11561,8 @@ public:
|
||||
}
|
||||
tp.m_currentColumn++;
|
||||
|
||||
auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
|
||||
auto padding = (strSize + 2 < static_cast<std::size_t>(colInfo.width))
|
||||
const auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
|
||||
const auto padding = (strSize + 2 < static_cast<std::size_t>(colInfo.width))
|
||||
? std::string(colInfo.width - (strSize + 2), ' ')
|
||||
: std::string();
|
||||
if (colInfo.justification == ColumnInfo::Left)
|
||||
@ -11595,7 +11605,7 @@ void ConsoleReporter::assertionStarting(AssertionInfo const&) {}
|
||||
bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) {
|
||||
AssertionResult const& result = _assertionStats.assertionResult;
|
||||
|
||||
bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
|
||||
const bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
|
||||
|
||||
// Drop out if result was successful but we're not printing them.
|
||||
if (!includeResults && result.getResultType() != ResultWas::Warning)
|
||||
@ -11639,7 +11649,7 @@ void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) {
|
||||
auto nameCol = Column( info.name ).width( static_cast<std::size_t>( m_tablePrinter->columnInfos()[0].width - 2 ) );
|
||||
|
||||
bool firstLine = true;
|
||||
for (auto line : nameCol) {
|
||||
for (const auto line : nameCol) {
|
||||
if (!firstLine)
|
||||
(*m_tablePrinter) << ColumnBreak() << ColumnBreak() << ColumnBreak();
|
||||
else
|
||||
@ -11649,7 +11659,7 @@ void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) {
|
||||
}
|
||||
}
|
||||
void ConsoleReporter::benchmarkEnded(BenchmarkStats const& stats) {
|
||||
Duration average(stats.elapsedTimeInNanoseconds / stats.iterations);
|
||||
const Duration average(stats.elapsedTimeInNanoseconds / stats.iterations);
|
||||
(*m_tablePrinter)
|
||||
<< stats.iterations << ColumnBreak()
|
||||
<< stats.elapsedTimeInNanoseconds << ColumnBreak()
|
||||
@ -11720,9 +11730,8 @@ void ConsoleReporter::printTestCaseAndSectionHeader() {
|
||||
if (m_sectionStack.size() > 1) {
|
||||
Colour colourGuard(Colour::Headers);
|
||||
|
||||
auto
|
||||
it = m_sectionStack.begin() + 1, // Skip first section (test case)
|
||||
itEnd = m_sectionStack.end();
|
||||
auto it = m_sectionStack.begin() + 1; // Skip first section (test case)
|
||||
const auto itEnd = m_sectionStack.end();
|
||||
for (; it != itEnd; ++it)
|
||||
printHeaderString(it->name, 2);
|
||||
}
|
||||
@ -11816,7 +11825,7 @@ void ConsoleReporter::printTotals( Totals const& totals ) {
|
||||
}
|
||||
void ConsoleReporter::printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row) {
|
||||
for (auto col : cols) {
|
||||
std::string value = col.rows[row];
|
||||
const std::string value = col.rows[row];
|
||||
if (col.label.empty()) {
|
||||
stream << label << ": ";
|
||||
if (value != "0")
|
||||
@ -11902,7 +11911,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
std::string fileNameTag(const std::vector<std::string> &tags) {
|
||||
auto it = std::find_if(begin(tags),
|
||||
const auto it = std::find_if(begin(tags),
|
||||
end(tags),
|
||||
[] (std::string const& tag) {return tag.front() == '#'; });
|
||||
if (it != tags.end())
|
||||
@ -11956,7 +11965,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
void JunitReporter::testGroupEnded( TestGroupStats const& testGroupStats ) {
|
||||
double suiteTime = suiteTimer.getElapsedSeconds();
|
||||
const double suiteTime = suiteTimer.getElapsedSeconds();
|
||||
CumulativeReporterBase::testGroupEnded( testGroupStats );
|
||||
writeGroup( *m_testGroups.back(), suiteTime );
|
||||
}
|
||||
@ -12278,7 +12287,7 @@ namespace Catch {
|
||||
|
||||
AssertionResult const& result = assertionStats.assertionResult;
|
||||
|
||||
bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
|
||||
const bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
|
||||
|
||||
if( includeResults || result.getResultType() == ResultWas::Warning ) {
|
||||
// Print any info messages in <Info> tags.
|
||||
|
||||
@ -58,7 +58,7 @@ TEST_CASE("Dynamic_Object attributes can be shared with C++")
|
||||
|
||||
chai("attr bob::z; def bob::bob() { this.z = 10 }; auto x = bob()");
|
||||
|
||||
chaiscript::dispatch::Dynamic_Object &mydo = chai.eval<chaiscript::dispatch::Dynamic_Object &>("x");
|
||||
auto &mydo = chai.eval<chaiscript::dispatch::Dynamic_Object &>("x");
|
||||
|
||||
CHECK(mydo.get_type_name() == "bob");
|
||||
|
||||
@ -347,7 +347,7 @@ TEST_CASE("Functor cast")
|
||||
chai.add(chaiscript::fun(&functor_cast_test_call), "test_call");
|
||||
|
||||
chai.eval("def func(i) { return i * 6; };");
|
||||
int d = chai.eval<int>("test_call(func, 3)");
|
||||
auto d = chai.eval<int>("test_call(func, 3)");
|
||||
|
||||
CHECK(d == 3 * 6);
|
||||
}
|
||||
@ -364,7 +364,7 @@ TEST_CASE("Set and restore chai state")
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser());
|
||||
|
||||
// save the initial state of globals and locals
|
||||
auto firststate = chai.get_state();
|
||||
const auto firststate = chai.get_state();
|
||||
std::map<std::string, chaiscript::Boxed_Value> locals = chai.get_locals();
|
||||
|
||||
// add some new globals and locals
|
||||
@ -598,8 +598,7 @@ class Object_Copy_Count_Test
|
||||
++copycount();
|
||||
}
|
||||
|
||||
Object_Copy_Count_Test(Object_Copy_Count_Test &&)
|
||||
{
|
||||
Object_Copy_Count_Test(Object_Copy_Count_Test &&) noexcept {
|
||||
std::cout << "Object_Copy_Count_Test(Object_Copy_Count_Test &&)\n";
|
||||
++movecount();
|
||||
}
|
||||
@ -868,10 +867,10 @@ TEST_CASE("Test long long dispatch")
|
||||
|
||||
struct Returned_Converted_Config
|
||||
{
|
||||
int num_iterations;
|
||||
int something_else;
|
||||
int num_iterations = 0;
|
||||
int something_else = 0;
|
||||
std::string a_string;
|
||||
std::function<int (const std::string &)> a_function;
|
||||
std::function<int (const std::string &)> a_function{};
|
||||
};
|
||||
|
||||
|
||||
@ -947,7 +946,7 @@ TEST_CASE("Parse floats with non-posix locale")
|
||||
std::setlocale(LC_ALL, "en_ZA.utf8");
|
||||
#endif
|
||||
chaiscript::ChaiScript_Basic chai(create_chaiscript_stdlib(),create_chaiscript_parser());
|
||||
const double parsed = chai.eval<double>("print(1.3); 1.3");
|
||||
const auto parsed = chai.eval<double>("print(1.3); 1.3");
|
||||
CHECK(parsed == Approx(1.3));
|
||||
const std::string str = chai.eval<std::string>("to_string(1.3)");
|
||||
CHECK(str == "1.3");
|
||||
@ -1229,7 +1228,7 @@ TEST_CASE("Test typed chaiscript functions to perform conversions")
|
||||
|
||||
chai.add(chaiscript::fun([]() -> std::shared_ptr<A>
|
||||
{
|
||||
return (std::shared_ptr<A>(new B()));
|
||||
return std::static_pointer_cast<A>(std::make_shared<B>());
|
||||
}), "Create");
|
||||
|
||||
chai.eval(R"(
|
||||
@ -1272,7 +1271,7 @@ TEST_CASE("Test reference member being registered")
|
||||
}
|
||||
|
||||
|
||||
const int add_3(const int &i)
|
||||
int add_3(const int &i)
|
||||
{
|
||||
return i + 3;
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ Multi_Test_Chai::Multi_Test_Chai()
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> Multi_Test_Chai::get_chai()
|
||||
{
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> Multi_Test_Chai::get_chai() const {
|
||||
return m_chai;
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#ifndef MULTIFILE_TEST_CHAI_HPP
|
||||
#define MULTIFILE_TEST_CHAI_HPP
|
||||
#include <chaiscript/chaiscript_basic.hpp>
|
||||
|
||||
class Multi_Test_Chai
|
||||
@ -5,10 +7,11 @@ class Multi_Test_Chai
|
||||
public:
|
||||
Multi_Test_Chai();
|
||||
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> get_chai();
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> get_chai() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> m_chai;
|
||||
std::shared_ptr<chaiscript::ChaiScript_Basic> m_chai{};
|
||||
};
|
||||
|
||||
|
||||
#endif // MULTIFILE_TEST_CHAI_HPP
|
||||
|
||||
@ -2,17 +2,14 @@
|
||||
|
||||
#include "multifile_test_module.hpp"
|
||||
|
||||
Multi_Test_Module::Multi_Test_Module()
|
||||
{
|
||||
}
|
||||
Multi_Test_Module::Multi_Test_Module() = default;
|
||||
|
||||
int Multi_Test_Module::get_module_value()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
chaiscript::ModulePtr Multi_Test_Module::get_module()
|
||||
{
|
||||
chaiscript::ModulePtr Multi_Test_Module::get_module() const {
|
||||
chaiscript::ModulePtr module(new chaiscript::Module());
|
||||
|
||||
module->add(chaiscript::fun(&Multi_Test_Module::get_module_value), "get_module_value");
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#ifndef MULTIFILE_TEST_MODULE_HPP
|
||||
#define MULTIFILE_TEST_MODULE_HPP
|
||||
#include <chaiscript/chaiscript_basic.hpp>
|
||||
|
||||
class Multi_Test_Module
|
||||
@ -7,5 +9,6 @@ class Multi_Test_Module
|
||||
|
||||
Multi_Test_Module();
|
||||
|
||||
chaiscript::ModulePtr get_module();
|
||||
chaiscript::ModulePtr get_module() const;
|
||||
};
|
||||
#endif // MULTIFILE_TEST_MODULE_HPP
|
||||
|
||||
@ -80,7 +80,7 @@ int main()
|
||||
std::vector<std::shared_ptr<std::thread> > threads;
|
||||
|
||||
// Ensure at least two, but say only 7 on an 8 core processor
|
||||
size_t num_threads = static_cast<size_t>(std::max(static_cast<int>(std::thread::hardware_concurrency()) - 1, 2));
|
||||
const size_t num_threads = static_cast<size_t>(std::max(static_cast<int>(std::thread::hardware_concurrency()) - 1, 2));
|
||||
|
||||
std::cout << "Num threads: " << num_threads << '\n';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user