@@ -2214,30 +2214,30 @@ impl Symbol {
2214
2214
let mut iter: Vec < Rc < RefCell < Symbol > > > = Vec :: new ( ) ;
2215
2215
match self {
2216
2216
Symbol :: File ( _) => {
2217
- for symbol in self . iter_symbols ( ) . flat_map ( |( name , hashmap) | hashmap. into_iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2217
+ for symbol in self . iter_symbols ( ) . flat_map ( |( _ , hashmap) | hashmap. into_iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2218
2218
iter. push ( symbol. clone ( ) ) ;
2219
2219
}
2220
2220
} ,
2221
2221
Symbol :: Class ( _) => {
2222
- for symbol in self . iter_symbols ( ) . flat_map ( |( name , hashmap) | hashmap. into_iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2222
+ for symbol in self . iter_symbols ( ) . flat_map ( |( _ , hashmap) | hashmap. into_iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2223
2223
iter. push ( symbol. clone ( ) ) ;
2224
2224
}
2225
2225
} ,
2226
2226
Symbol :: Function ( _) => {
2227
- for symbol in self . iter_symbols ( ) . flat_map ( |( name , hashmap) | hashmap. iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2227
+ for symbol in self . iter_symbols ( ) . flat_map ( |( _ , hashmap) | hashmap. iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2228
2228
iter. push ( symbol. clone ( ) ) ;
2229
2229
}
2230
2230
} ,
2231
2231
Symbol :: Package ( PackageSymbol :: Module ( m) ) => {
2232
- for symbol in self . iter_symbols ( ) . flat_map ( |( name , hashmap) | hashmap. iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2232
+ for symbol in self . iter_symbols ( ) . flat_map ( |( _ , hashmap) | hashmap. iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2233
2233
iter. push ( symbol. clone ( ) ) ;
2234
2234
}
2235
2235
for symbol in m. module_symbols . values ( ) . cloned ( ) {
2236
2236
iter. push ( symbol. clone ( ) ) ;
2237
2237
}
2238
2238
} ,
2239
2239
Symbol :: Package ( PackageSymbol :: PythonPackage ( p) ) => {
2240
- for symbol in self . iter_symbols ( ) . flat_map ( |( name , hashmap) | hashmap. iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2240
+ for symbol in self . iter_symbols ( ) . flat_map ( |( _ , hashmap) | hashmap. iter ( ) . flat_map ( |( _, vec) | vec. clone ( ) ) ) {
2241
2241
iter. push ( symbol. clone ( ) ) ;
2242
2242
}
2243
2243
for symbol in p. module_symbols . values ( ) . cloned ( ) {
@@ -2261,77 +2261,81 @@ impl Symbol {
2261
2261
2262
2262
//store in result all available members for symbol: sub symbols, base class elements and models symbols
2263
2263
//TODO is order right of Vec in HashMap? if we take first or last in it, do we have the last effective value?
2264
- pub fn all_members ( symbol : & Rc < RefCell < Symbol > > , session : & mut SessionInfo , result : & mut HashMap < OYarn , Vec < ( Rc < RefCell < Symbol > > , Option < OYarn > ) > > , with_co_models : bool , only_fields : bool , only_methods : bool , from_module : Option < Rc < RefCell < Symbol > > > , acc : & mut Option < HashSet < Tree > > , is_super : bool ) {
2265
- if acc. is_none ( ) {
2266
- * acc = Some ( HashSet :: new ( ) ) ;
2267
- }
2264
+ pub fn all_members (
2265
+ symbol : & Rc < RefCell < Symbol > > ,
2266
+ session : & mut SessionInfo ,
2267
+ with_co_models : bool ,
2268
+ only_fields : bool ,
2269
+ only_methods : bool ,
2270
+ from_module : Option < Rc < RefCell < Symbol > > > ,
2271
+ is_super : bool ) -> HashMap < OYarn , Vec < ( Rc < RefCell < Symbol > > , Option < OYarn > ) > > {
2272
+ let mut result: HashMap < OYarn , Vec < ( Rc < RefCell < Symbol > > , Option < OYarn > ) > > = HashMap :: new ( ) ;
2273
+ let mut acc: HashSet < Tree > = HashSet :: new ( ) ;
2274
+ Symbol :: _all_members ( symbol, session, & mut result, with_co_models, only_fields, only_methods, from_module, & mut acc, is_super) ;
2275
+ return result;
2276
+ }
2277
+ fn _all_members ( symbol : & Rc < RefCell < Symbol > > , session : & mut SessionInfo , result : & mut HashMap < OYarn , Vec < ( Rc < RefCell < Symbol > > , Option < OYarn > ) > > , with_co_models : bool , only_fields : bool , only_methods : bool , from_module : Option < Rc < RefCell < Symbol > > > , acc : & mut HashSet < Tree > , is_super : bool ) {
2268
2278
let tree = symbol. borrow ( ) . get_tree ( ) ;
2269
- if acc. as_mut ( ) . unwrap ( ) . contains ( & tree) {
2279
+ if acc. contains ( & tree) {
2270
2280
return ;
2271
2281
}
2272
- acc. as_mut ( ) . unwrap ( ) . insert ( tree) ;
2282
+ acc. insert ( tree) ;
2283
+ let mut append_result = |symbol : Rc < RefCell < Symbol > > , dep : Option < OYarn > | {
2284
+ let name = symbol. borrow ( ) . name ( ) . clone ( ) ;
2285
+ if let Some ( vec) = result. get_mut ( & name) {
2286
+ vec. push ( ( symbol, dep) ) ;
2287
+ } else {
2288
+ result. insert ( name. clone ( ) , vec ! [ ( symbol, dep) ] ) ;
2289
+ }
2290
+ } ;
2273
2291
let typ = symbol. borrow ( ) . typ ( ) ;
2274
2292
match typ {
2275
2293
SymType :: CLASS => {
2276
2294
// Skip current class symbols for super
2277
2295
if !is_super{
2278
2296
for symbol in symbol. borrow ( ) . all_symbols ( ) {
2279
- if only_fields && !symbol. borrow ( ) . is_field ( session) {
2297
+ if ( only_fields && !symbol. borrow ( ) . is_field ( session) ) || ( only_methods && symbol . borrow ( ) . typ ( ) != SymType :: FUNCTION ) {
2280
2298
continue ;
2281
2299
}
2282
- if only_methods && symbol. borrow ( ) . typ ( ) != SymType :: FUNCTION {
2283
- continue ;
2284
- }
2285
- let name = symbol. borrow ( ) . name ( ) . clone ( ) ;
2286
- if let Some ( vec) = result. get_mut ( & name) {
2287
- vec. push ( ( symbol, None ) ) ;
2288
- } else {
2289
- result. insert ( name. clone ( ) , vec ! [ ( symbol, None ) ] ) ;
2290
- }
2300
+ append_result ( symbol, None ) ;
2291
2301
}
2292
2302
}
2303
+ let mut bases: PtrWeakHashSet < Weak < RefCell < Symbol > > > = PtrWeakHashSet :: new ( ) ;
2304
+ symbol. borrow ( ) . as_class_sym ( ) . bases . iter ( ) . for_each ( |base| {
2305
+ base. upgrade ( ) . map ( |b| bases. insert ( b) ) ;
2306
+ } ) ;
2293
2307
if with_co_models {
2294
- let sym = symbol. borrow ( ) ;
2295
- let model_data = sym. as_class_sym ( ) . _model . as_ref ( ) ;
2296
- if let Some ( model_data) = model_data {
2297
- if let Some ( model) = session. sync_odoo . models . get ( & model_data. name ) . cloned ( ) {
2298
- for ( model_sym, dependency) in model. borrow ( ) . all_symbols ( session, from_module. clone ( ) , true ) {
2299
- if dependency. is_none ( ) && !Rc :: ptr_eq ( symbol, & model_sym) {
2300
- for s in model_sym. borrow ( ) . all_symbols ( ) {
2301
- if only_fields && !s. borrow ( ) . is_field ( session) {
2302
- continue ;
2303
- }
2304
- if only_methods && symbol. borrow ( ) . typ ( ) != SymType :: FUNCTION {
2305
- continue ;
2306
- }
2307
- let name = s. borrow ( ) . name ( ) . clone ( ) ;
2308
- if let Some ( vec) = result. get_mut ( & name) {
2309
- vec. push ( ( s, Some ( model_sym. borrow ( ) . name ( ) . clone ( ) ) ) ) ;
2310
- } else {
2311
- result. insert ( name. clone ( ) , vec ! [ ( s, Some ( model_sym. borrow( ) . name( ) . clone( ) ) ) ] ) ;
2312
- }
2313
- }
2314
- //add fields from _inherits
2315
- if let Some ( model_data) = model_sym. borrow ( ) . as_class_sym ( ) . _model . as_ref ( ) {
2316
- for ( inherits_model, inherits_field) in model_data. inherits . iter ( ) {
2317
- let inherits_model_sym = session. sync_odoo . models . get ( inherits_model) . cloned ( ) ;
2318
- if let Some ( inherits_model_sym) = inherits_model_sym {
2319
- for ( model_symbol, deps) in inherits_model_sym. borrow ( ) . all_symbols ( session, from_module. clone ( ) , true ) . iter ( ) . filter ( |( x, deps) | deps. is_none ( ) ) {
2320
- for ( field_name, field_symbols) in Symbol :: all_fields ( & model_symbol, session, from_module. clone ( ) ) {
2321
- for ( s, deps) in field_symbols. iter ( ) . filter ( |( x, deps) | deps. is_none ( ) ) {
2322
- if let Some ( vec) = result. get_mut ( & field_name) {
2323
- vec. push ( ( s. clone ( ) , Some ( model_sym. borrow ( ) . name ( ) . clone ( ) ) ) ) ;
2324
- } else {
2325
- result. insert ( field_name. clone ( ) , vec ! [ ( s. clone( ) , Some ( model_sym. borrow( ) . name( ) . clone( ) ) ) ] ) ;
2326
- }
2327
- }
2328
- }
2329
- }
2330
- }
2331
- }
2332
- }
2333
- }
2308
+ let Some ( model) = symbol. borrow ( ) . as_class_sym ( ) . _model . as_ref ( ) . and_then ( |model_data|
2309
+ session. sync_odoo . models . get ( & model_data. name ) . cloned ( )
2310
+ ) else {
2311
+ return ;
2312
+ } ;
2313
+ // no recursion because it is handled in all_symbols_inherits
2314
+ let ( model_symbols, model_inherits_symbols) = model. borrow ( ) . all_symbols_inherits ( session, from_module. clone ( ) ) ;
2315
+ for ( model_sym, dependency) in model_symbols {
2316
+ if dependency. is_some ( ) || Rc :: ptr_eq ( symbol, & model_sym) {
2317
+ continue ;
2318
+ }
2319
+ model_sym. borrow ( ) . as_class_sym ( ) . bases . iter ( ) . for_each ( |base| {
2320
+ base. upgrade ( ) . map ( |b| bases. insert ( b) ) ;
2321
+ } ) ;
2322
+ for s in model_sym. borrow ( ) . all_symbols ( ) {
2323
+ if ( only_fields && !s. borrow ( ) . is_field ( session) ) || ( only_methods && s. borrow ( ) . typ ( ) != SymType :: FUNCTION ) {
2324
+ continue ;
2334
2325
}
2326
+ append_result ( s, Some ( model_sym. borrow ( ) . name ( ) . clone ( ) ) ) ;
2327
+ }
2328
+ }
2329
+ for ( model_sym, dependency) in model_inherits_symbols {
2330
+ if dependency. is_some ( ) || Rc :: ptr_eq ( symbol, & model_sym) {
2331
+ continue ;
2332
+ }
2333
+ model_sym. borrow ( ) . as_class_sym ( ) . bases . iter ( ) . for_each ( |base| {
2334
+ base. upgrade ( ) . map ( |b| bases. insert ( b) ) ;
2335
+ } ) ;
2336
+ // for inherits symbols, we only add fields
2337
+ for s in model_sym. borrow ( ) . all_symbols ( ) . filter ( |s| s. borrow ( ) . is_field ( session) ) {
2338
+ append_result ( s, Some ( model_sym. borrow ( ) . name ( ) . clone ( ) ) ) ;
2335
2339
}
2336
2340
}
2337
2341
}
@@ -2340,23 +2344,14 @@ impl Symbol {
2340
2344
//no comodel as we will search for co-model from original class (what about overrided _name?)
2341
2345
//TODO what about base of co-models classes?
2342
2346
if let Some ( base) = base. upgrade ( ) {
2343
- Symbol :: all_members ( & base, session, result, false , only_fields, only_methods, from_module. clone ( ) , acc, false ) ;
2347
+ Symbol :: _all_members ( & base, session, result, false , only_fields, only_methods, from_module. clone ( ) , acc, false ) ;
2344
2348
}
2345
2349
}
2346
2350
} ,
2347
- _ => {
2348
- for symbol in symbol. borrow ( ) . all_symbols ( ) {
2349
- if only_fields && !symbol. borrow ( ) . is_field ( session) {
2350
- continue ;
2351
- }
2352
- let name = symbol. borrow ( ) . name ( ) . clone ( ) ;
2353
- if let Some ( vec) = result. get_mut ( & name) {
2354
- vec. push ( ( symbol, None ) ) ;
2355
- } else {
2356
- result. insert ( name. clone ( ) , vec ! [ ( symbol, None ) ] ) ;
2357
- }
2358
- }
2359
- }
2351
+ // if not class just add it to result
2352
+ _ => symbol. borrow ( ) . all_symbols ( ) . for_each ( |s|
2353
+ if !( only_fields && !s. borrow ( ) . is_field ( session) ) { append_result ( s, None ) }
2354
+ )
2360
2355
}
2361
2356
}
2362
2357
@@ -2634,9 +2629,7 @@ impl Symbol {
2634
2629
}
2635
2630
2636
2631
pub fn all_fields ( symbol : & Rc < RefCell < Symbol > > , session : & mut SessionInfo , from_module : Option < Rc < RefCell < Symbol > > > ) -> HashMap < OYarn , Vec < ( Rc < RefCell < Symbol > > , Option < OYarn > ) > > {
2637
- let mut all_fields = HashMap :: new ( ) ;
2638
- Symbol :: all_members ( symbol, session, & mut all_fields, true , true , false , from_module. clone ( ) , & mut None , false ) ;
2639
- all_fields
2632
+ Symbol :: all_members ( symbol, session, true , true , false , from_module. clone ( ) , false )
2640
2633
}
2641
2634
2642
2635
/* similar to get_symbol: will return the symbol that is under this one with the specified name.
0 commit comments