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§
fn resolve_name( &self, name: &str, span: Span, ) -> Result<Option<NamedThing>, IncompleteItem>
Sourcefn resolve_path(
&self,
path: &Path,
span: Span,
) -> Result<NamedThing, FatalError>
fn resolve_path( &self, path: &Path, span: Span, ) -> Result<NamedThing, FatalError>
Resolves the given path and registers all errors
Sourcefn resolve_visible_path(&self, path: &Path) -> Option<NamedThing>
fn resolve_visible_path(&self, path: &Path) -> Option<NamedThing>
Resolves the given path only if it is visible. Does not register any errors
Sourcefn resolve_any_path(&self, path: &Path) -> Option<NamedThing>
fn resolve_any_path(&self, path: &Path) -> Option<NamedThing>
Resolves the given path. Does not register any errors
fn add_diagnostic(&self, diag: Diagnostic)
fn db(&self) -> &dyn AnalyzerDb
Sourcefn add_expression(&self, node: &Node<Expr>, attributes: ExpressionAttributes)
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.
Sourcefn update_expression(
&self,
node: &Node<Expr>,
f: &dyn Fn(&mut ExpressionAttributes),
)
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.
Sourcefn add_constant(&self, name: &Node<SmolStr>, expr: &Node<Expr>, value: Constant)
fn add_constant(&self, name: &Node<SmolStr>, expr: &Node<Expr>, value: Constant)
Add evaluated constant value in a constant declaration to the context.
Sourcefn constant_value_by_name(
&self,
name: &SmolStr,
span: Span,
) -> Result<Option<Constant>, IncompleteItem>
fn constant_value_by_name( &self, name: &SmolStr, span: Span, ) -> Result<Option<Constant>, IncompleteItem>
Returns constant value from variable name.
Sourcefn parent(&self) -> Item
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(..)
.
Sourcefn parent_function(&self) -> FunctionId
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.
Sourcefn add_call(&self, node: &Node<Expr>, call_type: CallType)
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.
fn get_call(&self, node: &Node<Expr>) -> Option<CallType>
Sourcefn is_in_function(&self) -> bool
fn is_in_function(&self) -> bool
Returns true
if the context is in function scope.
Sourcefn inherits_type(&self, typ: BlockScopeType) -> bool
fn inherits_type(&self, typ: BlockScopeType) -> bool
Returns true
if the scope or any of its parents is of the given type.
Sourcefn get_context_type(&self) -> Option<TypeId>
fn get_context_type(&self) -> Option<TypeId>
Returns the Context
type, if it is defined.
Provided Methods§
fn error( &self, message: &str, label_span: Span, label: &str, ) -> DiagnosticVoucher
Sourcefn root_item(&self) -> Item
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(..))
.