mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-31 07:38:04 +00:00
Add SymbolFlags
This commit is contained in:
parent
7f2f2cb8ad
commit
27dd95c8f9
1 changed files with 28 additions and 0 deletions
|
@ -11,6 +11,7 @@ use crate::{
|
||||||
error::{CodegenError, CodegenErrorType},
|
error::{CodegenError, CodegenErrorType},
|
||||||
IndexMap,
|
IndexMap,
|
||||||
};
|
};
|
||||||
|
use bitflags::bitflags;
|
||||||
use rustpython_ast as ast;
|
use rustpython_ast as ast;
|
||||||
use rustpython_compiler_core::Location;
|
use rustpython_compiler_core::Location;
|
||||||
use std::{borrow::Cow, fmt};
|
use std::{borrow::Cow, fmt};
|
||||||
|
@ -94,6 +95,33 @@ pub enum SymbolScope {
|
||||||
Cell,
|
Cell,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
pub struct SymbolFlags: u16 {
|
||||||
|
const REFERENCED = 0x001;
|
||||||
|
const ASSIGNED = 0x002;
|
||||||
|
const PARAMETER = 0x004;
|
||||||
|
const ANNOTATED = 0x008;
|
||||||
|
const IMPORTED = 0x010;
|
||||||
|
const NONLOCAL = 0x020;
|
||||||
|
// indicates if the symbol gets a value assigned by a named expression in a comprehension
|
||||||
|
// this is required to correct the scope in the analysis.
|
||||||
|
const ASSIGNED_IN_COMPREHENSION = 0x040;
|
||||||
|
// indicates that the symbol is used a bound iterator variable. We distinguish this case
|
||||||
|
// from normal assignment to detect unallowed re-assignment to iterator variables.
|
||||||
|
const ITER = 0x080;
|
||||||
|
/// indicates that the symbol is a free variable in a class method from the scope that the
|
||||||
|
/// class is defined in, e.g.:
|
||||||
|
/// ```python
|
||||||
|
/// def foo(x):
|
||||||
|
/// class A:
|
||||||
|
/// def method(self):
|
||||||
|
/// return x // is_free_class
|
||||||
|
/// ```
|
||||||
|
const FREE_CLASS = 0x100;
|
||||||
|
const BOUND = Self::ASSIGNED.bits | Self::PARAMETER.bits | Self::IMPORTED.bits | Self::ITER.bits;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A single symbol in a table. Has various properties such as the scope
|
/// A single symbol in a table. Has various properties such as the scope
|
||||||
/// of the symbol, and also the various uses of the symbol.
|
/// of the symbol, and also the various uses of the symbol.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue