Skip to content

Commit 1ffb652

Browse files
committed
Add SymbolFlags
1 parent f23ea5e commit 1ffb652

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

compiler/codegen/src/symboltable.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
error::{CodegenError, CodegenErrorType},
1212
IndexMap,
1313
};
14+
use bitflags::bitflags;
1415
use rustpython_ast as ast;
1516
use rustpython_compiler_core::Location;
1617
use std::{borrow::Cow, fmt};
@@ -94,6 +95,33 @@ pub enum SymbolScope {
9495
Cell,
9596
}
9697

98+
bitflags! {
99+
pub struct SymbolFlags: u16 {
100+
const REFERENCED = 0x001;
101+
const ASSIGNED = 0x002;
102+
const PARAMETER = 0x004;
103+
const ANNOTATED = 0x008;
104+
const IMPORTED = 0x010;
105+
const NONLOCAL = 0x020;
106+
// indicates if the symbol gets a value assigned by a named expression in a comprehension
107+
// this is required to correct the scope in the analysis.
108+
const ASSIGNED_IN_COMPREHENSION = 0x040;
109+
// indicates that the symbol is used a bound iterator variable. We distinguish this case
110+
// from normal assignment to detect unallowed re-assignment to iterator variables.
111+
const ITER = 0x080;
112+
/// indicates that the symbol is a free variable in a class method from the scope that the
113+
/// class is defined in, e.g.:
114+
/// ```python
115+
/// def foo(x):
116+
/// class A:
117+
/// def method(self):
118+
/// return x // is_free_class
119+
/// ```
120+
const FREE_CLASS = 0x100;
121+
const BOUND = Self::ASSIGNED.bits | Self::PARAMETER.bits | Self::IMPORTED.bits | Self::ITER.bits;
122+
}
123+
}
124+
97125
/// A single symbol in a table. Has various properties such as the scope
98126
/// of the symbol, and also the various uses of the symbol.
99127
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)