Skip to main content

Checker

Struct Checker 

Source
pub struct Checker<'a> { /* private fields */ }
Expand description

The checking pass.

Implementations§

Source§

impl Checker<'_>

Source

pub fn check_decl(&mut self, id: DeclId) -> DeclList

Checks one declaration and gives back the objects and functions it declared.

The run is empty for a declaration that declares neither, which is a typedef, a tag, a static assertion, or one of the mistakes that leaves nothing behind.

Source§

impl Checker<'_>

Source

pub fn check_stmt(&mut self, ret: TypeId, id: StmtId) -> StmtId

Checks one statement, as though it were the body of a function returning ret.

The entry for a caller that has a statement rather than a translation unit, which is what the tests here are built on. A body is opened around it and closed after, so that the labels are resolved and reported the way they are in a real function.

Source§

impl Checker<'_>

Source

pub fn type_name(&mut self, id: TypeNameId) -> TypeId

The type a type name names, which is a cast, a sizeof or a _Generic association.

Source

pub fn declared_type( &mut self, specs: DeclSpecsId, declarator: DeclaratorId, ) -> TypeId

The type one declarator of one declaration declares.

Always gives back a type. A declarator that does not check is reported and answered with the nearest thing that does, so that the declaration around it is still checked instead of collapsing, which is the same rule the expressions follow with their poisoned nodes.

Source

pub fn declare_typedef(&mut self, name: Symbol, ty: TypeId)

Declares a typedef name in the current scope.

Public for the same reason Checker::declare_object is: a caller that checks one expression rather than a translation unit still needs a way to say that a name the parser already decided was a type is one.

Source§

impl<'a> Checker<'a>

Source

pub fn new(ast: &'a Ast, cx: Context<'a>) -> Checker<'a>

A checker over one untyped tree.

Source

pub fn check_unit(&mut self)

Checks a whole translation unit, which is what a compilation does.

The declarations are checked in the order they were written, since that is the order the scopes are built in and the order the diagnostics belong in.

Source

pub fn check_expr(&mut self, id: ExprId) -> ExprId

Checks one expression and gives back the node it became.

Always gives back a node. An expression that does not check is poisoned rather than absent, so that the operators around it are still checked and the diagnostics they would produce are still held back.

Source

pub fn eval_constant(&mut self, expr: ExprId) -> Result<Const, NotConstant>

Folds a checked expression, reporting whatever the folding itself found wrong.

§Errors

NotConstant when the expression is not one. It is handed back rather than reported because the message names the context: case label does not reduce to an integer constant and enumerator value for 'x' is not an integer constant are two sentences about the same failure, and only the caller knows which one to write.

Source

pub fn eval_integer(&mut self, expr: ExprId) -> Result<i128, NotConstant>

The same, for a context that needs an integer constant expression.

§Errors

NotConstant when the expression is not one, or is a constant of some other type.

Source

pub fn finish(self) -> Checked

The tree, the types and the diagnostics.

Source

pub fn declare_object(&mut self, name: Symbol, ty: TypeId, span: Span) -> DeclId

Declares an object in the current scope without a declaration to read it from.

Checker::check_decl is what a translation unit goes through. This is for the caller that wants to check one expression against names it has decided on itself, which is what Checker::check_expr is for and what the tests here are built on.

Trait Implementations§

Source§

impl<'a> Debug for Checker<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Checker<'a>

§

impl<'a> RefUnwindSafe for Checker<'a>

§

impl<'a> Send for Checker<'a>

§

impl<'a> Sync for Checker<'a>

§

impl<'a> Unpin for Checker<'a>

§

impl<'a> UnsafeUnpin for Checker<'a>

§

impl<'a> UnwindSafe for Checker<'a>

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 = !

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.