Skip to main content

Preprocessor

Struct Preprocessor 

Source
pub struct Preprocessor { /* private fields */ }
Expand description

プリプロセッサ

Implementations§

Source§

impl Preprocessor

Source

pub fn new(config: PPConfig) -> Self

新しいプリプロセッサを作成

Source

pub fn set_macro_def_callback(&mut self, callback: Box<dyn MacroDefCallback>)

マクロ定義コールバックを設定

Source

pub fn take_macro_def_callback(&mut self) -> Option<Box<dyn MacroDefCallback>>

マクロ定義コールバックを取得(所有権を移動)

Source

pub fn set_comment_callback(&mut self, callback: Box<dyn CommentCallback>)

コメントコールバックを設定

Source

pub fn take_comment_callback(&mut self) -> Option<Box<dyn CommentCallback>>

コメントコールバックを取得(所有権を移動)

Source

pub fn set_macro_called_callback( &mut self, macro_name: InternedStr, callback: Box<dyn MacroCalledCallback>, )

特定マクロの呼び出しコールバックを設定

指定したマクロが展開されたときにコールバックが呼ばれる。

Source

pub fn take_macro_called_callback( &mut self, macro_name: InternedStr, ) -> Option<Box<dyn MacroCalledCallback>>

マクロ呼び出しコールバックを取得(所有権移動)

Source

pub fn get_macro_called_callback( &self, macro_name: InternedStr, ) -> Option<&Box<dyn MacroCalledCallback>>

マクロ呼び出しコールバックへの参照を取得

Source

pub fn get_macro_called_callback_mut( &mut self, macro_name: InternedStr, ) -> Option<&mut Box<dyn MacroCalledCallback>>

マクロ呼び出しコールバックへの可変参照を取得

Source

pub fn add_wrapped_macro(&mut self, macro_name: &str)

マーカーで囲むマクロを登録(assert 等の特殊処理用)

登録されたマクロは展開時に MacroBegin/MacroEnd マーカーで囲まれ、 is_wrapped フラグが true になる。パーサーは args から元の式を復元できる。

Source

pub fn add_skip_expand_macro(&mut self, name: InternedStr)

展開抑制マクロを追加

登録されたマクロは展開されず、識別子としてそのまま出力される。 bindings.rs に存在する定数名を登録することで、コード生成時に 定数名を保持できる。

Source

pub fn add_skip_expand_macros( &mut self, names: impl IntoIterator<Item = InternedStr>, )

複数の展開抑制マクロを追加

Source

pub fn add_explicit_expand_macro(&mut self, name: InternedStr)

明示展開マクロを追加(preserve_function_macros モードで展開対象となる)

Source

pub fn add_explicit_expand_macros( &mut self, names: impl IntoIterator<Item = InternedStr>, )

複数の明示展開マクロを追加

Source

pub fn add_source_file(&mut self, path: &Path) -> Result<(), CompileError>

ファイルをソースとして登録する

注: この関数はファイルを InputSource として登録するだけで、 実際のマクロ展開処理は行わない。マクロ展開は next_token()collect_tokens() の呼び出し時に遅延実行される。

Source

pub fn next_token(&mut self) -> Result<Token, CompileError>

次のトークンを取得(メインインターフェース)

Source

pub fn unget_token(&mut self, token: Token)

トークンを先読みバッファに戻す

パーサーが先読みしたトークンを戻す必要がある場合に使用。

Source

pub fn files(&self) -> &FileRegistry

ファイルレジストリへの参照

Source

pub fn interner(&self) -> &StringInterner

文字列インターナーへの参照

Source

pub fn interner_mut(&mut self) -> &mut StringInterner

文字列インターナーへの可変参照

Source

pub fn macros(&self) -> &MacroTable

マクロテーブルへの参照

Source

pub fn expand_macro_body_for_inference( &mut self, body: &[Token], params: &[InternedStr], args: &[Vec<Token>], in_progress: &mut HashSet<InternedStr>, ) -> Result<(Vec<Token>, HashSet<InternedStr>), CompileError>

マクロ本体を展開する(MacroInferContext 用)

TokenExpander の代替として、マクロ推論で使用する。 トークンペースト(##)と文字列化(#)を完全にサポートする。

§Arguments
  • body: マクロ本体のトークン列
  • params: パラメータ名のリスト(関数マクロの場合)
  • args: 各パラメータに対応する引数トークン列
  • in_progress: 再帰展開防止用のマクロ名セット
§Returns

(展開結果, 呼び出されたマクロ集合)

Source

pub fn collect_tokens(&mut self) -> Result<Vec<Token>, CompileError>

全トークンを収集

Trait Implementations§

Source§

impl TokenSource for Preprocessor

TokenSource trait の実装

Parser がプリプロセッサをトークンソースとして使用できるようにする

Source§

fn next_token(&mut self) -> Result<Token>

次のトークンを取得
Source§

fn unget_token(&mut self, token: Token)

トークンを先読みバッファに戻す
Source§

fn interner(&self) -> &StringInterner

StringInterner への参照を取得
Source§

fn interner_mut(&mut self) -> &mut StringInterner

StringInterner への可変参照を取得
Source§

fn files(&self) -> &FileRegistry

FileRegistry への参照を取得
Source§

fn is_file_in_target(&self, file_id: FileId) -> bool

指定されたファイルがターゲットディレクトリ内かどうかを判定 デフォルト実装は常に false を返す(TokenSlice など)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.