Skip to main content

Scopes

Struct Scopes 

Source
pub struct Scopes { /* private fields */ }
Expand description

The scopes of one translation unit.

Implementations§

Source§

impl Scopes

Source

pub fn new() -> Scopes

Empty scopes, with the file scope open.

Source

pub fn push(&mut self)

Opens a scope in every namespace.

Both are pushed together because C opens them together. A parameter list is a scope of its own, which is why the tag in void f(struct S *p); is gone by the next declaration, and getting that wrong in one namespace and not the other is how the two drift.

Source

pub fn pop(&mut self)

Closes the innermost scope in every namespace.

§Panics

Panics on closing the file scope.

Source

pub fn at_file_scope(&self) -> bool

Whether the only open scope is the file scope.

Source

pub fn depth(&self) -> u32

How many scopes are open, the file scope counting as one.

Source

pub fn declare(&mut self, name: Symbol, binding: Binding) -> Option<Binding>

Binds an ordinary identifier, and gives back what it was bound to in the same scope.

A returned value is a redeclaration, which is the caller’s to judge, since int x; int x; is one object at file scope and an error inside a function.

Source

pub fn lookup(&self, name: Symbol) -> Option<Binding>

What an ordinary identifier names here.

Source

pub fn lookup_here(&self, name: Symbol) -> Option<Binding>

What an ordinary identifier names in the innermost scope alone.

Source

pub fn declare_tag(&mut self, name: Symbol, tag: Tag) -> Option<Tag>

Binds a tag, and gives back what it was bound to in the same scope.

Source

pub fn tag(&self, name: Symbol) -> Option<Tag>

What tag a name names here.

Source

pub fn tag_here(&self, name: Symbol) -> Option<Tag>

What tag a name names in the innermost scope alone.

This is the question struct S; asks, since a bare declaration of a tag declares a new type in this scope even where an outer one is visible, and struct S *p; asks the other one, since it refers to whatever S already means.

Trait Implementations§

Source§

impl Debug for Scopes

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Scopes

Source§

fn default() -> Scopes

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.