Move AST::new() and AST::new_with_source() to internals.

This commit is contained in:
Stephen Chung 2021-11-29 10:58:46 +08:00
parent c5f2b0a253
commit 0ab86ac623
3 changed files with 60 additions and 22 deletions

View File

@ -15,11 +15,12 @@ Enhancements
* Added `into_array` and `into_typed_array` for `Dynamic`.
* Added `FnPtr::call` to simplify calling a function pointer.
Deprecated API's
----------------
Deprecated and Gated API's
--------------------------
* `NativeCallContext::new` is deprecated because it is simpler to call a function pointer via `FnPtr::call`.
* `AST::merge_filtered` and `AST::combine_filtered` are no longer exported under `no_function`.
* `AST::new` and `AST::new_with_source` are moved under `internals`.
Version 1.2.1

View File

@ -196,7 +196,26 @@ impl Default for AST {
impl AST {
/// Create a new [`AST`].
#[inline]
#[cfg(not(feature = "internals"))]
#[inline(always)]
#[must_use]
pub(crate) fn new(
statements: impl IntoIterator<Item = Stmt>,
#[cfg(not(feature = "no_function"))] functions: impl Into<Shared<Module>>,
) -> Self {
Self {
source: None,
body: StmtBlock::new(statements, Position::NONE),
#[cfg(not(feature = "no_function"))]
functions: functions.into(),
#[cfg(not(feature = "no_module"))]
resolver: None,
}
}
/// _(internals)_ Create a new [`AST`].
/// Exported under the `internals` feature only.
#[cfg(feature = "internals")]
#[inline(always)]
#[must_use]
pub fn new(
statements: impl IntoIterator<Item = Stmt>,
@ -211,6 +230,41 @@ impl AST {
resolver: None,
}
}
/// Create a new [`AST`] with a source name.
#[cfg(not(feature = "internals"))]
#[inline(always)]
#[must_use]
pub(crate) fn new_with_source(
statements: impl IntoIterator<Item = Stmt>,
#[cfg(not(feature = "no_function"))] functions: impl Into<Shared<Module>>,
source: impl Into<Identifier>,
) -> Self {
let mut ast = Self::new(
statements,
#[cfg(not(feature = "no_function"))]
functions,
);
ast.set_source(source);
ast
}
/// _(internals)_ Create a new [`AST`] with a source name.
/// Exported under the `internals` feature only.
#[cfg(feature = "internals")]
#[inline(always)]
#[must_use]
pub fn new_with_source(
statements: impl IntoIterator<Item = Stmt>,
#[cfg(not(feature = "no_function"))] functions: impl Into<Shared<Module>>,
source: impl Into<Identifier>,
) -> Self {
let mut ast = Self::new(
statements,
#[cfg(not(feature = "no_function"))]
functions,
);
ast.set_source(source);
ast
}
/// Create an empty [`AST`].
#[inline]
#[must_use]
@ -224,23 +278,6 @@ impl AST {
resolver: None,
}
}
/// Create a new [`AST`] with a source name.
#[inline(always)]
#[must_use]
pub fn new_with_source(
statements: impl IntoIterator<Item = Stmt>,
#[cfg(not(feature = "no_function"))] functions: impl Into<Shared<Module>>,
source: impl Into<Identifier>,
) -> Self {
Self {
source: Some(source.into()),
body: StmtBlock::new(statements, Position::NONE),
#[cfg(not(feature = "no_function"))]
functions: functions.into(),
#[cfg(not(feature = "no_module"))]
resolver: None,
}
}
/// Get the source, if any.
#[inline(always)]
#[must_use]
@ -286,7 +323,7 @@ impl AST {
&self.body.0
}
/// Get a mutable reference to the statements.
#[cfg(not(feature = "no_optimize"))]
#[allow(dead_code)]
#[inline(always)]
#[must_use]
pub(crate) fn statements_mut(&mut self) -> &mut StaticVec<Stmt> {

View File

@ -272,7 +272,7 @@ impl Engine {
}
/// Generate a list of all functions in JSON format.
/// Available only under the `metadata` feature.
/// Exported under the `metadata` feature only.
///
/// Functions from the following sources are included:
/// 1) Functions registered into the global namespace