@@ -2277,56 +2277,45 @@ def check_basic_path(stmt, toks, ctx, x,
2277
2277
else :
2278
2278
paths_left .update (paths_right )
2279
2279
if sys .version < '3' :
2280
- for value , path_or_literal in paths_left .iteritems ():
2281
- if path_or_literal == 'literal' :
2282
- value = value .replace ("'" , '' ).replace ('"' , '' ).strip ()
2283
- for path_stmt in path_stmts :
2284
- type = get_type_of_typedef (path_stmt , ctx )
2285
- check_type (path_stmt .search_one ('type' ), type ,
2286
- value , ctx )
2287
- else :
2288
- path_stmts2 = check_path (value , stmt , ctx )
2289
- if path_stmts2 is None :
2290
- return None
2291
- for path_stmt in path_stmts :
2292
- for path_stmt2 in path_stmts2 :
2293
- type = get_type_of_typedef (path_stmt , ctx )
2294
- type2 = get_type_of_typedef (path_stmt2 , ctx )
2295
- if type != type2 and not function_exists :
2296
- if not ((type .startswith ('uint' ) and
2297
- type2 .startswith ('uint' )) or
2298
- (type .startswith ('int' ) and
2299
- type2 .startswith ('int' ))):
2300
- raise SyntaxError (
2301
- 'Types in path condition "{}" does ' +
2302
- 'not equal' .format (stmt .arg ))
2280
+ iteritems = paths_left .iteritems ()
2303
2281
else :
2304
- for value , path_or_literal in paths_left .items ():
2305
- if path_or_literal == 'literal' :
2306
- value = value .replace ("'" , '' ).replace ('"' , '' ).strip ()
2307
- for path_stmt in path_stmts :
2308
- type = get_type_of_typedef (path_stmt , ctx )
2309
- check_type (path_stmt .search_one ('type' ), type ,
2310
- value , ctx )
2311
- else :
2312
- path_stmts2 = check_path (value , stmt , ctx )
2313
- if path_stmts2 is None :
2314
- return None
2315
- for path_stmt in path_stmts :
2316
- for path_stmt2 in path_stmts2 :
2317
- type = get_type_of_typedef (path_stmt , ctx )
2318
- type2 = get_type_of_typedef (path_stmt2 , ctx )
2319
- if type != type2 and not function_exists :
2320
- if not ((type .startswith ('uint' ) and
2321
- type2 .startswith ('uint' )) or
2322
- (type .startswith ('int' ) and
2323
- type2 .startswith ('int' ))):
2324
- raise SyntaxError (
2325
- 'Types in path condition "{}" does ' +
2326
- 'not equal' .format (stmt .arg ))
2327
-
2328
-
2329
- def get_type_of_typedef (path_stmt , ctx ):
2282
+ iteritems = paths_left .items ()
2283
+ for value , path_or_literal in iteritems :
2284
+ if path_or_literal == 'literal' :
2285
+ value = value .replace ("'" , '' ).replace ('"' , '' ).strip ()
2286
+ for path_stmt in path_stmts :
2287
+ type = get_type_of_typedef (path_stmt , ctx )
2288
+ check_type (path_stmt .search_one ('type' ), type ,
2289
+ value , ctx )
2290
+ else :
2291
+ path_stmts2 = check_path (value , stmt , ctx )
2292
+ if path_stmts2 is None :
2293
+ return None
2294
+ for path_stmt in path_stmts :
2295
+ for path_stmt2 in path_stmts2 :
2296
+ types = get_type_of_typedef (path_stmt , ctx , True )
2297
+ types2 = get_type_of_typedef (path_stmt2 , ctx , True )
2298
+ if not isinstance (types , list ):
2299
+ types = [types ]
2300
+ if not isinstance (types2 , list ):
2301
+ types2 = [types2 ]
2302
+ found = False
2303
+ for type in types :
2304
+ for type2 in types2 :
2305
+ if type == type2 or function_exists :
2306
+ found = True
2307
+ elif ((type .startswith ('uint' ) and
2308
+ type2 .startswith ('uint' )) or
2309
+ (type .startswith ('int' ) and
2310
+ type2 .startswith ('int' ))):
2311
+ found = True
2312
+ if not found :
2313
+ raise SyntaxError (
2314
+ 'Types in path condition "{}" does ' .format (stmt .arg ) +
2315
+ 'not equal' )
2316
+
2317
+
2318
+ def get_type_of_typedef (path_stmt , ctx , check_union = False ):
2330
2319
if path_stmt .keyword == 'identity' :
2331
2320
return 'identityref'
2332
2321
elif path_stmt .keyword == 'refine' :
@@ -2339,7 +2328,12 @@ def get_type_of_typedef(path_stmt, ctx):
2339
2328
type_stmt = path_stmt .search_one ('type' )
2340
2329
name = type_stmt .i_type_spec .name
2341
2330
if name == 'leafref' :
2342
- return get_type_of_typedef (type_stmt .i_type_spec .i_target_node , ctx )
2331
+ return get_type_of_typedef (type_stmt .i_type_spec .i_target_node , ctx , check_union )
2332
+ elif name == 'union' and check_union :
2333
+ ret = []
2334
+ for t in type_stmt .search ('type' ):
2335
+ ret .append (t .arg )
2336
+ return ret
2343
2337
else :
2344
2338
return name
2345
2339
except AttributeError :
@@ -2376,10 +2370,13 @@ def check_type(stmt, type, literal, ctx):
2376
2370
elif type == 'bits' :
2377
2371
bits = stmt .i_type_spec .bits
2378
2372
found = False
2379
- for bit in bits :
2380
- if bit [0 ] == literal :
2381
- found = True
2382
- break
2373
+ if len (literal ) == 0 :
2374
+ found = True
2375
+ else :
2376
+ for bit in bits :
2377
+ if bit [0 ] == literal :
2378
+ found = True
2379
+ break
2383
2380
if not found :
2384
2381
raise Exception
2385
2382
elif type == 'empty' :
0 commit comments