@@ -11,6 +11,7 @@ use crate::{
11
11
error:: { CodegenError , CodegenErrorType } ,
12
12
IndexMap ,
13
13
} ;
14
+ use bitflags:: bitflags;
14
15
use rustpython_ast as ast;
15
16
use rustpython_compiler_core:: Location ;
16
17
use std:: { borrow:: Cow , fmt} ;
@@ -94,6 +95,33 @@ pub enum SymbolScope {
94
95
Cell ,
95
96
}
96
97
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
+
97
125
/// A single symbol in a table. Has various properties such as the scope
98
126
/// of the symbol, and also the various uses of the symbol.
99
127
#[ derive( Debug , Clone ) ]
0 commit comments