Skip to main content

Scopes

Struct Scopes 

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

The scopes the parser keeps, across the namespaces it has to hold apart.

Implementations§

Source§

impl Scopes

Source

pub fn new() -> Self

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 void f(struct S *p); declares a tag that is gone by the time the next declaration is read, and getting that wrong in one namespace and not the other is how the two drift out of step.

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 ident(&self, name: Symbol) -> Option<IdentKind>

What name means here, and None when it has not been declared.

Source

pub fn is_typedef_name(&self, name: Symbol) -> bool

Whether name in a specifier list is a type name.

This is the answer the whole ambiguity turns on. An identifier that has not been declared at all is not a type name: the declaration it is missing is an error, and guessing that an unknown name is a type in the hope of a better parse produces a cascade out of one typo.

Source

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

Declares name in the innermost scope, and gives back what it was in that same scope.

Called at the end of a declarator rather than at its start, which is what makes typedef int T; T T; read the way C says it does.

Source

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

Declares a tag, and gives back what it was in the same scope.

Source

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

What tag name names here.

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.