pub struct Tast { /* private fields */ }Expand description
One typed translation unit.
Implementations§
Source§impl Tast
impl Tast
Sourcepub fn top_level(&self) -> &[DeclId] ⓘ
pub fn top_level(&self) -> &[DeclId] ⓘ
The objects and functions of the translation unit, in the order they were declared.
Sourcepub fn add_top_level(&mut self, decl: DeclId)
pub fn add_top_level(&mut self, decl: DeclId)
Adds a declaration at file scope.
Sourcepub fn file_asms(&self) -> &[FileAsm]
pub fn file_asms(&self) -> &[FileAsm]
The asm written at file scope, in the order they were written.
Beside Tast::top_level rather than in it, because one of these declares no object and
no function and so is not a Decl. What it is instead is a contribution to the object
file, which is a thing only the walk to the IR has anywhere to put.
Sourcepub fn add_file_asm(&mut self, asm: FileAsm)
pub fn add_file_asm(&mut self, asm: FileAsm)
Adds an asm written at file scope.
Sourcepub fn expr(&mut self, expr: Expr, span: Span) -> ExprId
pub fn expr(&mut self, expr: Expr, span: Span) -> ExprId
Adds an expression, with the source it came from.
§Panics
Panics if the arena would exceed four billion nodes, which is not a translation unit this compiler intends to accept.
Sourcepub fn stmt(&mut self, stmt: Stmt, span: Span) -> StmtId
pub fn stmt(&mut self, stmt: Stmt, span: Span) -> StmtId
Adds a statement, with the source it came from.
§Panics
Panics if the arena would exceed four billion nodes.
Sourcepub fn decl(&mut self, decl: Decl, span: Span) -> DeclId
pub fn decl(&mut self, decl: Decl, span: Span) -> DeclId
Adds a declaration, with the source it came from.
§Panics
Panics if the arena would exceed four billion nodes.
Sourcepub fn set_decl(&mut self, id: DeclId, decl: Decl)
pub fn set_decl(&mut self, id: DeclId, decl: Decl)
Replaces a declaration, which is what a definition of something already declared does.
§Panics
Panics if id is not a declaration of this tree.
Sourcepub fn set_stmt(&mut self, id: StmtId, stmt: Stmt)
pub fn set_stmt(&mut self, id: StmtId, stmt: Stmt)
Replaces a statement, which is what a switch does to the cases in its body.
A case is checked before the table it is an entry of exists, since the table is a run
and the run is not known until the whole body has been walked. So the statement is written
with a placeholder entry and given its real one here.
§Panics
Panics if id is not a statement of this tree.
Sourcepub fn add_vla(&mut self, size: ExprId) -> VlaId
pub fn add_vla(&mut self, size: ExprId) -> VlaId
Records the size of one variable length array, and gives back its identity.
The type table keeps a VlaId and nothing else, because two variable length arrays
written with the same element type are still distinct types and interning them together
would say they are not. The expression itself lives here, since it is evaluated once
where the declaration is reached and its value is what every sizeof of that type
afterwards answers with.
§Panics
Panics if the table would exceed four billion entries.
Sourcepub fn record_adjustment(&mut self, decl: DeclId, written: TypeId)
pub fn record_adjustment(&mut self, decl: DeclId, written: TypeId)
Records the type a parameter was written as, where adjusting it to a pointer dropped a length the program still has to evaluate.
int f(int a[i++]) declares a pointer, since C11 6.7.6.3p7 adjusts an array parameter to
one, and the adjustment takes the type away and not the expression: the size is evaluated
once on entry to the function, in the order the parameters were written, so i++ happens
and the function sees the incremented value. Nothing needs the size for anything, because
the parameter is a pointer, so what is kept here is the type it was written as and the
walk over that type is what evaluates every length in it.
Only the outermost length is ever lost this way. int a[][n] adjusts to int (*)[n] and
the n is still in the type the parameter has, which is why this is a handful of entries
in the whole tree and not one per parameter.
Sourcepub fn adjusted_from(&self, decl: DeclId) -> Option<TypeId>
pub fn adjusted_from(&self, decl: DeclId) -> Option<TypeId>
The type a parameter was written as, for the few that have one.
Sourcepub fn define_label(&mut self, id: LabelId, stmt: StmtId)
pub fn define_label(&mut self, id: LabelId, stmt: StmtId)
Records that a label names a statement, which is not known when the label is created
because a goto may come first.
§Panics
Panics if id is not a label of this tree.
Source§impl Tast
impl Tast
Sourcepub fn add_string(&mut self, item: StringLiteral) -> StrId
pub fn add_string(&mut self, item: StringLiteral) -> StrId
Source§impl Tast
impl Tast
Sourcepub fn add_expr_refs(&mut self, items: &[ExprId]) -> ExprList
pub fn add_expr_refs(&mut self, items: &[ExprId]) -> ExprList
Adds a run of expression references, which is what a call’s arguments are.
§Panics
Panics if the table would exceed four billion entries.
Source§impl Tast
impl Tast
Sourcepub fn add_stmt_refs(&mut self, items: &[StmtId]) -> StmtList
pub fn add_stmt_refs(&mut self, items: &[StmtId]) -> StmtList
Adds a run of statement references, which is what a block is.
§Panics
Panics if the table would exceed four billion entries.
Source§impl Tast
impl Tast
Sourcepub fn add_decl_refs(&mut self, items: &[DeclId]) -> DeclList
pub fn add_decl_refs(&mut self, items: &[DeclId]) -> DeclList
Adds a run of declaration references, which is what a declaration statement is.
§Panics
Panics if the table would exceed four billion entries.
Source§impl Tast
impl Tast
Sourcepub fn add_str_refs(&mut self, items: &[StrId]) -> StrList
pub fn add_str_refs(&mut self, items: &[StrId]) -> StrList
Adds a run of string literal references, which is what an asm clobber list is.
§Panics
Panics if the table would exceed four billion entries.
Source§impl Tast
impl Tast
Sourcepub fn add_label_refs(&mut self, items: &[LabelId]) -> LabelList
pub fn add_label_refs(&mut self, items: &[LabelId]) -> LabelList
Adds a run of label references, which is what the labels of an asm goto are.
§Panics
Panics if the table would exceed four billion entries.
Source§impl Tast
impl Tast
Sourcepub fn add_asm_operands(&mut self, items: &[AsmOperand]) -> AsmOperandList
pub fn add_asm_operands(&mut self, items: &[AsmOperand]) -> AsmOperandList
Adds the operands of one section of an asm statement.
§Panics
Panics if the table would exceed four billion entries.
Trait Implementations§
Source§impl Index<Idx<StringLiteral>> for Tast
impl Index<Idx<StringLiteral>> for Tast
Source§type Output = StringLiteral
type Output = StringLiteral
Source§impl Index<IdxRange<AsmOperand>> for Tast
impl Index<IdxRange<AsmOperand>> for Tast
Source§type Output = [AsmOperand]
type Output = [AsmOperand]
Source§fn index(&self, list: AsmOperandList) -> &[AsmOperand]
fn index(&self, list: AsmOperandList) -> &[AsmOperand]
container[index]) operation. Read more