Trait AnalyzerContext

Source
pub trait AnalyzerContext {
Show 27 methods // Required methods fn resolve_name( &self, name: &str, span: Span, ) -> Result<Option<NamedThing>, IncompleteItem>; fn resolve_path( &self, path: &Path, span: Span, ) -> Result<NamedThing, FatalError>; fn resolve_visible_path(&self, path: &Path) -> Option<NamedThing>; fn resolve_any_path(&self, path: &Path) -> Option<NamedThing>; fn add_diagnostic(&self, diag: Diagnostic); fn db(&self) -> &dyn AnalyzerDb; fn add_expression( &self, node: &Node<Expr>, attributes: ExpressionAttributes, ); fn update_expression( &self, node: &Node<Expr>, f: &dyn Fn(&mut ExpressionAttributes), ); fn expr_typ(&self, expr: &Node<Expr>) -> Type; fn add_constant( &self, name: &Node<SmolStr>, expr: &Node<Expr>, value: Constant, ); fn constant_value_by_name( &self, name: &SmolStr, span: Span, ) -> Result<Option<Constant>, IncompleteItem>; fn parent(&self) -> Item; fn module(&self) -> ModuleId; fn parent_function(&self) -> FunctionId; fn add_call(&self, node: &Node<Expr>, call_type: CallType); fn get_call(&self, node: &Node<Expr>) -> Option<CallType>; fn is_in_function(&self) -> bool; fn inherits_type(&self, typ: BlockScopeType) -> bool; fn get_context_type(&self) -> Option<TypeId>; // Provided methods fn error( &self, message: &str, label_span: Span, label: &str, ) -> DiagnosticVoucher { ... } fn root_item(&self) -> Item { ... } fn type_error( &self, message: &str, span: Span, expected: TypeId, actual: TypeId, ) -> DiagnosticVoucher { ... } fn not_yet_implemented( &self, feature: &str, span: Span, ) -> DiagnosticVoucher { ... } fn fancy_error( &self, message: &str, labels: Vec<Label>, notes: Vec<String>, ) -> DiagnosticVoucher { ... } fn duplicate_name_error( &self, message: &str, name: &str, original: Span, duplicate: Span, ) -> DiagnosticVoucher { ... } fn name_conflict_error( &self, name_kind: &str, name: &str, original: &NamedThing, original_span: Option<Span>, duplicate_span: Span, ) -> DiagnosticVoucher { ... } fn register_diag(&self, diag: Diagnostic) -> DiagnosticVoucher { ... }
}

Required Methods§

Source

fn resolve_name( &self, name: &str, span: Span, ) -> Result<Option<NamedThing>, IncompleteItem>

Source

fn resolve_path( &self, path: &Path, span: Span, ) -> Result<NamedThing, FatalError>

Resolves the given path and registers all errors

Source

fn resolve_visible_path(&self, path: &Path) -> Option<NamedThing>

Resolves the given path only if it is visible. Does not register any errors

Source

fn resolve_any_path(&self, path: &Path) -> Option<NamedThing>

Resolves the given path. Does not register any errors

Source

fn add_diagnostic(&self, diag: Diagnostic)

Source

fn db(&self) -> &dyn AnalyzerDb

Source

fn add_expression(&self, node: &Node<Expr>, attributes: ExpressionAttributes)

Attribute contextual information to an expression node.

§Panics

Panics if an entry already exists for the node id.

Source

fn update_expression( &self, node: &Node<Expr>, f: &dyn Fn(&mut ExpressionAttributes), )

Update the expression attributes.

§Panics

Panics if an entry does not already exist for the node id.

Source

fn expr_typ(&self, expr: &Node<Expr>) -> Type

Returns a type of an expression.

§Panics

Panics if type analysis is not performed for an expr.

Source

fn add_constant(&self, name: &Node<SmolStr>, expr: &Node<Expr>, value: Constant)

Add evaluated constant value in a constant declaration to the context.

Source

fn constant_value_by_name( &self, name: &SmolStr, span: Span, ) -> Result<Option<Constant>, IncompleteItem>

Returns constant value from variable name.

Source

fn parent(&self) -> Item

Returns an item enclosing current context.

§Example
contract Foo:
    fn foo():
       if ...:
           ...
       else:
           ...

If the context is in then block, then this function returns Item::Function(..).

Source

fn module(&self) -> ModuleId

Returns the module enclosing current context.

Source

fn parent_function(&self) -> FunctionId

Returns a function id that encloses a context.

§Panics

Panics if a context is not in a function. Use Self::is_in_function to determine whether a context is in a function.

Source

fn add_call(&self, node: &Node<Expr>, call_type: CallType)

§Panics

Panics if a context is not in a function. Use Self::is_in_function to determine whether a context is in a function.

Source

fn get_call(&self, node: &Node<Expr>) -> Option<CallType>

Source

fn is_in_function(&self) -> bool

Returns true if the context is in function scope.

Source

fn inherits_type(&self, typ: BlockScopeType) -> bool

Returns true if the scope or any of its parents is of the given type.

Source

fn get_context_type(&self) -> Option<TypeId>

Returns the Context type, if it is defined.

Provided Methods§

Source

fn error( &self, message: &str, label_span: Span, label: &str, ) -> DiagnosticVoucher

Source

fn root_item(&self) -> Item

Returns a non-function item that encloses a context.

§Example
contract Foo:
    fn foo():
       if ...:
           ...
       else:
           ...

If the context is in then block, then this function returns Item::Type(TypeDef::Contract(..)).

Source

fn type_error( &self, message: &str, span: Span, expected: TypeId, actual: TypeId, ) -> DiagnosticVoucher

Source

fn not_yet_implemented(&self, feature: &str, span: Span) -> DiagnosticVoucher

Source

fn fancy_error( &self, message: &str, labels: Vec<Label>, notes: Vec<String>, ) -> DiagnosticVoucher

Source

fn duplicate_name_error( &self, message: &str, name: &str, original: Span, duplicate: Span, ) -> DiagnosticVoucher

Source

fn name_conflict_error( &self, name_kind: &str, name: &str, original: &NamedThing, original_span: Option<Span>, duplicate_span: Span, ) -> DiagnosticVoucher

Source

fn register_diag(&self, diag: Diagnostic) -> DiagnosticVoucher

Implementors§