pub struct Scopes { /* private fields */ }Expand description
The scopes the parser keeps, across the namespaces it has to hold apart.
Implementations§
Source§impl Scopes
impl Scopes
Sourcepub fn push(&mut self)
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.
Sourcepub fn at_file_scope(&self) -> bool
pub fn at_file_scope(&self) -> bool
Whether the only open scope is the file scope.
Sourcepub fn ident(&self, name: Symbol) -> Option<IdentKind>
pub fn ident(&self, name: Symbol) -> Option<IdentKind>
What name means here, and None when it has not been declared.
Sourcepub fn is_typedef_name(&self, name: Symbol) -> bool
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.
Sourcepub fn declare(&mut self, name: Symbol, kind: IdentKind) -> Option<IdentKind>
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.