pub struct Checker<'a> { /* private fields */ }Expand description
The checking pass.
Implementations§
Source§impl Checker<'_>
impl Checker<'_>
Sourcepub fn check_decl(&mut self, id: DeclId) -> DeclList
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<'_>
impl Checker<'_>
Sourcepub fn check_stmt(&mut self, ret: TypeId, id: StmtId) -> StmtId
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<'_>
impl Checker<'_>
Sourcepub fn type_name(&mut self, id: TypeNameId) -> TypeId
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.
Sourcepub fn declared_type(
&mut self,
specs: DeclSpecsId,
declarator: DeclaratorId,
) -> TypeId
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.
Sourcepub fn declare_typedef(&mut self, name: Symbol, ty: TypeId)
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>
impl<'a> Checker<'a>
Sourcepub fn check_unit(&mut self)
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.
Sourcepub fn check_expr(&mut self, id: ExprId) -> ExprId
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.
Sourcepub fn eval_constant(&mut self, expr: ExprId) -> Result<Const, NotConstant>
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.
Sourcepub fn eval_integer(&mut self, expr: ExprId) -> Result<i128, NotConstant>
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.
Sourcepub fn declare_object(&mut self, name: Symbol, ty: TypeId, span: Span) -> DeclId
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.