pub trait CodeGen: Debug + Clone {
type Context;
type Options;
type SymbolTable;
// Required method
fn to_rust(
self,
ctx: Self::Context,
options: Self::Options,
symbols: Self::SymbolTable,
) -> Result<TokenStream, Box<dyn Error>>;
// Provided methods
fn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable { ... }
fn get_docstring(&self) -> Option<String> { ... }
}
Expand description
Reexport the CodeGen from to_tokenstream A trait for an object that can be converted to Rust code. Any data structure implementing this trait can be converted into a proc_macro2::TokenStream.
Required Associated Types§
Sourcetype Context
type Context
A type, generally an enum, that passes the code generator the context of the node.
Sourcetype SymbolTable
type SymbolTable
A trait for a symbol table
Required Methods§
Sourcefn to_rust(
self,
ctx: Self::Context,
options: Self::Options,
symbols: Self::SymbolTable,
) -> Result<TokenStream, Box<dyn Error>>
fn to_rust( self, ctx: Self::Context, options: Self::Options, symbols: Self::SymbolTable, ) -> Result<TokenStream, Box<dyn Error>>
A trait method to output Rust code in a general sense. The output should be stream of Rust tokens, however, it is not guaranteed that it will fully compile because of scoping errors and other checks that don’t occur until later.
Provided Methods§
Sourcefn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable
fn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable
A default implementation for find_symbols(), which simply returns the input. Language nodes that modify the symbol table should override this method.
Sourcefn get_docstring(&self) -> Option<String>
fn get_docstring(&self) -> Option<String>
A trait method for extracting a docstring from an object that can have a docstring.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl CodeGen for StatementType
impl CodeGen for StatementType
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Argument
impl CodeGen for Argument
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Arguments
impl CodeGen for Arguments
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for CallArguments
impl CodeGen for CallArguments
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Parameter
impl CodeGen for Parameter
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for AsyncFor
impl CodeGen for AsyncFor
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for AsyncWith
impl CodeGen for AsyncWith
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for AugAssign
impl CodeGen for AugAssign
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for BinOp
impl CodeGen for BinOp
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for ClassDef
impl CodeGen for ClassDef
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Compare
impl CodeGen for Compare
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Constant
impl CodeGen for Constant
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Dict
impl CodeGen for Dict
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Expr
impl CodeGen for Expr
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for FormattedValue
impl CodeGen for FormattedValue
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for JoinedStr
impl CodeGen for JoinedStr
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for For
impl CodeGen for For
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for FunctionDef
impl CodeGen for FunctionDef
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for IfExp
impl CodeGen for IfExp
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for If
impl CodeGen for If
type Context = CodeGenContext
type Options = PythonOptions
type SymbolTable = SymbolTableScopes
Source§impl CodeGen for Import
An Import (or FromImport) statement causes 2 things to occur:
impl CodeGen for Import
An Import (or FromImport) statement causes 2 things to occur:
- Declares the imported object within the existing scope.
- Causes the referenced module to be compiled into the program (only once).