# HG changeset patch # User John W. Eaton # Date 1638817931 18000 # Node ID bd67d0045e21d31d010b21efd5cfd5fecd884480 # Parent abb4823df5350e101ee373cd21401cdd8902e947 use separate files for MArray, intNDArray, and range template forward decls * MArray-fwd.h, intNDArray-fwd.h, range-fwd.h: New files. * liboctave/array/module.mk: Update. * pr-output.h, ov-range.h, MArray-C.cc, MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc, MArray.h, Range.h, dNDArray.h, fNDArray.h, idx-vector.h, intNDArray.h, sparse-qr.h, oct-inttypes.h: Use new header files to replace inline forward declarations of some template types. diff -r abb4823df535 -r bd67d0045e21 libinterp/corefcn/pr-output.h --- a/libinterp/corefcn/pr-output.h Sat Dec 04 09:13:12 2021 -0500 +++ b/libinterp/corefcn/pr-output.h Mon Dec 06 14:12:11 2021 -0500 @@ -31,8 +31,10 @@ #include #include "Array-fwd.h" +#include "intNDArray-fwd.h" #include "oct-cmplx.h" #include "oct-inttypes-fwd.h" +#include "range-fwd.h" #include "pr-flt-fmt.h" @@ -56,13 +58,6 @@ class Cell; class octave_value; -namespace octave -{ - template class range; -} - -template class intNDArray; - template float_display_format make_format (const std::complex&) diff -r abb4823df535 -r bd67d0045e21 libinterp/octave-value/ov-range.h --- a/libinterp/octave-value/ov-range.h Sat Dec 04 09:13:12 2021 -0500 +++ b/libinterp/octave-value/ov-range.h Mon Dec 06 14:12:11 2021 -0500 @@ -33,6 +33,7 @@ #include #include +#include "Array-fwd.h" #include "Range.h" #include "lo-mappers.h" diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-C.cc --- a/liboctave/array/MArray-C.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-C.cc Mon Dec 06 14:12:11 2021 -0500 @@ -34,7 +34,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (Complex); +INSTANTIATE_MARRAY (Complex, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (Complex, OCTAVE_API) diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-d.cc --- a/liboctave/array/MArray-d.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-d.cc Mon Dec 06 14:12:11 2021 -0500 @@ -32,7 +32,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (double); +INSTANTIATE_MARRAY (double, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (double, OCTAVE_API) diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-f.cc --- a/liboctave/array/MArray-f.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-f.cc Mon Dec 06 14:12:11 2021 -0500 @@ -32,7 +32,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (float); +INSTANTIATE_MARRAY (float, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (float, OCTAVE_API) diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-fC.cc --- a/liboctave/array/MArray-fC.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-fC.cc Mon Dec 06 14:12:11 2021 -0500 @@ -34,7 +34,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (FloatComplex); +INSTANTIATE_MARRAY (FloatComplex, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (FloatComplex, OCTAVE_API) diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-fwd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/array/MArray-fwd.h Mon Dec 06 14:12:11 2021 -0500 @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_MArray_fwd_h) +#define octave_MArray_fwd_h 1 + +#include "octave-config.h" + +template class OCTARRAY_API MArray; + +#endif diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-i.cc --- a/liboctave/array/MArray-i.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-i.cc Mon Dec 06 14:12:11 2021 -0500 @@ -34,9 +34,9 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (int); +INSTANTIATE_MARRAY (int, OCTAVE_API); #if defined (OCTAVE_ENABLE_64) -INSTANTIATE_MARRAY (int64_t); +INSTANTIATE_MARRAY (int64_t, OCTAVE_API); #endif INSTANTIATE_MARRAY_FRIENDS (int, OCTAVE_API) @@ -44,20 +44,20 @@ INSTANTIATE_MARRAY_FRIENDS (int64_t, OCTAVE_API) #endif -INSTANTIATE_MARRAY (octave_int8); -INSTANTIATE_MARRAY (octave_int16); -INSTANTIATE_MARRAY (octave_int32); -INSTANTIATE_MARRAY (octave_int64); +INSTANTIATE_MARRAY (octave_int8, OCTAVE_API); +INSTANTIATE_MARRAY (octave_int16, OCTAVE_API); +INSTANTIATE_MARRAY (octave_int32, OCTAVE_API); +INSTANTIATE_MARRAY (octave_int64, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (octave_int8, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_int16, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_int32, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_int64, OCTAVE_API) -INSTANTIATE_MARRAY (octave_uint8); -INSTANTIATE_MARRAY (octave_uint16); -INSTANTIATE_MARRAY (octave_uint32); -INSTANTIATE_MARRAY (octave_uint64); +INSTANTIATE_MARRAY (octave_uint8, OCTAVE_API); +INSTANTIATE_MARRAY (octave_uint16, OCTAVE_API); +INSTANTIATE_MARRAY (octave_uint32, OCTAVE_API); +INSTANTIATE_MARRAY (octave_uint64, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (octave_uint8, OCTAVE_API) INSTANTIATE_MARRAY_FRIENDS (octave_uint16, OCTAVE_API) diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray-s.cc --- a/liboctave/array/MArray-s.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray-s.cc Mon Dec 06 14:12:11 2021 -0500 @@ -32,7 +32,7 @@ #include "MArray.h" #include "MArray.cc" -INSTANTIATE_MARRAY (short); +INSTANTIATE_MARRAY (short, OCTAVE_API); INSTANTIATE_MARRAY_FRIENDS (short, OCTAVE_API) diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray.cc --- a/liboctave/array/MArray.cc Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray.cc Mon Dec 06 14:12:11 2021 -0500 @@ -372,8 +372,24 @@ return do_mx_unary_op (a, mx_inline_uminus); } +template +void MArray::instantiation_guard () +{ + // This guards against accidental implicit instantiations. + // Array instances should always be explicit and use INSTANTIATE_ARRAY. + T::__xXxXx__ (); +} + #if defined (__clang__) -# define INSTANTIATE_MARRAY(T) template class OCTAVE_API MArray +# define INSTANTIATE_MARRAY(T, API) \ + template <> API void \ + MArray::instantiation_guard () { } \ + \ + template class API MArray #else -# define INSTANTIATE_MARRAY(T) template class MArray +# define INSTANTIATE_MARRAY(T, API) \ + template <> API void \ + MArray::instantiation_guard () { } \ + \ + template class MArray #endif diff -r abb4823df535 -r bd67d0045e21 liboctave/array/MArray.h --- a/liboctave/array/MArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/MArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -29,38 +29,36 @@ #include "octave-config.h" #include "Array.h" +#include "MArray-fwd.h" #include "mx-inlines.cc" -// forward declare template with visibility attribute -template class OCTAVE_API MArray; - -template OCTAVE_API MArray& operator += (MArray&, const T&); -template OCTAVE_API MArray& operator -= (MArray&, const T&); -template OCTAVE_API MArray& operator *= (MArray&, const T&); -template OCTAVE_API MArray& operator /= (MArray&, const T&); -template OCTAVE_API MArray& operator += (MArray&, const MArray&); -template OCTAVE_API MArray& operator -= (MArray&, const MArray&); -template OCTAVE_API MArray& product_eq (MArray&, const MArray&); -template OCTAVE_API MArray& quotient_eq (MArray&, const MArray&); -template OCTAVE_API MArray operator + (const MArray&); -template OCTAVE_API MArray operator - (const MArray&); -template OCTAVE_API MArray operator + (const MArray&, const T&); -template OCTAVE_API MArray operator - (const MArray&, const T&); -template OCTAVE_API MArray operator * (const MArray&, const T&); -template OCTAVE_API MArray operator / (const MArray&, const T&); -template OCTAVE_API MArray operator + (const T&, const MArray&); -template OCTAVE_API MArray operator - (const T&, const MArray&); -template OCTAVE_API MArray operator * (const T&, const MArray&); -template OCTAVE_API MArray operator / (const T&, const MArray&); -template OCTAVE_API MArray operator + (const MArray&, const MArray&); -template OCTAVE_API MArray operator - (const MArray&, const MArray&); -template OCTAVE_API MArray quotient (const MArray&, const MArray&); -template OCTAVE_API MArray product (const MArray&, const MArray&); +template OCTARRAY_API MArray& operator += (MArray&, const T&); +template OCTARRAY_API MArray& operator -= (MArray&, const T&); +template OCTARRAY_API MArray& operator *= (MArray&, const T&); +template OCTARRAY_API MArray& operator /= (MArray&, const T&); +template OCTARRAY_API MArray& operator += (MArray&, const MArray&); +template OCTARRAY_API MArray& operator -= (MArray&, const MArray&); +template OCTARRAY_API MArray& product_eq (MArray&, const MArray&); +template OCTARRAY_API MArray& quotient_eq (MArray&, const MArray&); +template OCTARRAY_API MArray operator + (const MArray&); +template OCTARRAY_API MArray operator - (const MArray&); +template OCTARRAY_API MArray operator + (const MArray&, const T&); +template OCTARRAY_API MArray operator - (const MArray&, const T&); +template OCTARRAY_API MArray operator * (const MArray&, const T&); +template OCTARRAY_API MArray operator / (const MArray&, const T&); +template OCTARRAY_API MArray operator + (const T&, const MArray&); +template OCTARRAY_API MArray operator - (const T&, const MArray&); +template OCTARRAY_API MArray operator * (const T&, const MArray&); +template OCTARRAY_API MArray operator / (const T&, const MArray&); +template OCTARRAY_API MArray operator + (const MArray&, const MArray&); +template OCTARRAY_API MArray operator - (const MArray&, const MArray&); +template OCTARRAY_API MArray quotient (const MArray&, const MArray&); +template OCTARRAY_API MArray product (const MArray&, const MArray&); //! Template for N-dimensional array classes with like-type math operators. template class -OCTAVE_API +OCTARRAY_API MArray : public Array { public: @@ -106,22 +104,25 @@ //! Performs indexed accumulative addition. //@{ - OCTAVE_API void idx_add (const octave::idx_vector& idx, T val); - OCTAVE_API void + OCTARRAY_API void idx_add (const octave::idx_vector& idx, T val); + OCTARRAY_API void idx_add (const octave::idx_vector& idx, const MArray& vals); //@} - OCTAVE_API void + OCTARRAY_API void idx_min (const octave::idx_vector& idx, const MArray& vals); - OCTAVE_API void + OCTARRAY_API void idx_max (const octave::idx_vector& idx, const MArray& vals); - OCTAVE_API void + OCTARRAY_API void idx_add_nd (const octave::idx_vector& idx, const MArray& vals, int dim = -1); - OCTAVE_API void changesign (void); + OCTARRAY_API void changesign (void); + +private: + OCTARRAY_API static void instantiation_guard (); }; // Define all the MArray forwarding functions for return type R and diff -r abb4823df535 -r bd67d0045e21 liboctave/array/Range.h --- a/liboctave/array/Range.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/Range.h Mon Dec 06 14:12:11 2021 -0500 @@ -35,13 +35,12 @@ #include "dim-vector.h" #include "lo-error.h" #include "oct-sort.h" +#include "range-fwd.h" namespace octave { template - class - OCTAVE_API - range + class range { public: diff -r abb4823df535 -r bd67d0045e21 liboctave/array/dNDArray.h --- a/liboctave/array/dNDArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/dNDArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -28,13 +28,12 @@ #include "octave-config.h" +#include "intNDArray-fwd.h" #include "MArray.h" #include "bsxfun-decl.h" #include "mx-defs.h" #include "mx-op-decl.h" -template class intNDArray; - class OCTAVE_API NDArray : public MArray diff -r abb4823df535 -r bd67d0045e21 liboctave/array/fNDArray.h --- a/liboctave/array/fNDArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/fNDArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -28,13 +28,12 @@ #include "octave-config.h" +#include "intNDArray-fwd.h" #include "MArray.h" #include "bsxfun-decl.h" #include "mx-defs.h" #include "mx-op-decl.h" -template class intNDArray; - class OCTAVE_API FloatNDArray : public MArray diff -r abb4823df535 -r bd67d0045e21 liboctave/array/idx-vector.h --- a/liboctave/array/idx-vector.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/idx-vector.h Mon Dec 06 14:12:11 2021 -0500 @@ -40,11 +40,10 @@ #include "oct-inttypes.h" #include "oct-refcount.h" #include "Sparse-fwd.h" +#include "range-fwd.h" namespace octave { - template class range; - // Design rationale: // // idx_vector is a reference-counting, polymorphic pointer, that can diff -r abb4823df535 -r bd67d0045e21 liboctave/array/intNDArray-fwd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/array/intNDArray-fwd.h Mon Dec 06 14:12:11 2021 -0500 @@ -0,0 +1,33 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_intNDArray_fwd_h) +#define octave_intNDArray_fwd_h 1 + +#include "octave-config.h" + +template class OCTAVE_API intNDArray; + +#endif diff -r abb4823df535 -r bd67d0045e21 liboctave/array/intNDArray.h --- a/liboctave/array/intNDArray.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/intNDArray.h Mon Dec 06 14:12:11 2021 -0500 @@ -28,6 +28,7 @@ #include "octave-config.h" +#include "intNDArray-fwd.h" #include "MArray.h" #include "boolNDArray.h" @@ -35,7 +36,6 @@ template class -OCTAVE_API intNDArray : public MArray { public: diff -r abb4823df535 -r bd67d0045e21 liboctave/array/module.mk --- a/liboctave/array/module.mk Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/array/module.mk Mon Dec 06 14:12:11 2021 -0500 @@ -36,7 +36,9 @@ %reldir%/int32NDArray.h \ %reldir%/int64NDArray.h \ %reldir%/int8NDArray.h \ + %reldir%/intNDArray-fwd.h \ %reldir%/intNDArray.h \ + %reldir%/MArray-fwd.h \ %reldir%/MArray.h \ %reldir%/Matrix.h \ %reldir%/MatrixType.h \ @@ -44,6 +46,7 @@ %reldir%/MSparse.h \ %reldir%/PermMatrix.h \ %reldir%/Range.h \ + %reldir%/range-fwd.h \ %reldir%/Sparse-fwd.h \ %reldir%/Sparse.h \ %reldir%/uint16NDArray.h \ diff -r abb4823df535 -r bd67d0045e21 liboctave/array/range-fwd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/array/range-fwd.h Mon Dec 06 14:12:11 2021 -0500 @@ -0,0 +1,36 @@ +//////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2021 The Octave Project Developers +// +// See the file COPYRIGHT.md in the top-level directory of this +// distribution or . +// +// This file is part of Octave. +// +// Octave is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Octave is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Octave; see the file COPYING. If not, see +// . +// +//////////////////////////////////////////////////////////////////////// + +#if ! defined (octave_range_fwd_h) +#define octave_range_fwd_h 1 + +#include "octave-config.h" + +namespace octave +{ + template class OCTAVE_API range; +} + +#endif diff -r abb4823df535 -r bd67d0045e21 liboctave/numeric/sparse-qr.h --- a/liboctave/numeric/sparse-qr.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/numeric/sparse-qr.h Mon Dec 06 14:12:11 2021 -0500 @@ -31,13 +31,13 @@ #include #include "oct-cmplx.h" +#include "MArray-fwd.h" class Matrix; class ComplexMatrix; class SparseMatrix; class SparseComplexMatrix; class ColumnVector; -template class MArray; namespace octave { diff -r abb4823df535 -r bd67d0045e21 liboctave/util/oct-inttypes.h --- a/liboctave/util/oct-inttypes.h Sat Dec 04 09:13:12 2021 -0500 +++ b/liboctave/util/oct-inttypes.h Mon Dec 06 14:12:11 2021 -0500 @@ -779,9 +779,7 @@ { }; template -class -OCTAVE_API -octave_int : public octave_int_base +class octave_int : public octave_int_base { public: