Commit 896090d0

896090d00e56Merged

sacckey <[email protected]> · 7 months ago · 2 files · +1 added · ~1 modified

Description

fix(codegen): support nested ConstantPath constant reads in classes/modules

Details

Commit
896090d00e56
Parent
7f910a3027cd

spinel_codegen.rbmodifiedView file

@@ -1070,8 +1070,11 @@
10701070 end
10711071 if t == "ConstantPathNode"
10721072 if @nd_receiver[nid] >= 0
1073- rname = @nd_name[@nd_receiver[nid]]
1073+ rname = const_ref_flat_name(@nd_receiver[nid])
10741074 nname = @nd_name[nid]
1075+ if rname == ""
1076+ return "int"
1077+ end
10751078 cpname = rname + "_" + nname
10761079 ci = find_const_idx(cpname)
10771080 if ci >= 0
@@ -3468,6 +3471,24 @@
34683471 collect_class_with_prefix(nid, "")
34693472 end
34703473
3474+ def collect_scoped_constant(scope_name, nid)
3475+ cname = scope_name + "_" + @nd_name[nid]
3476+ expr_id = @nd_expression[nid]
3477+ ct = "int"
3478+ if expr_id >= 0
3479+ ct = infer_type(expr_id)
3480+ end
3481+ ci = find_const_idx(cname)
3482+ if ci >= 0
3483+ @const_types[ci] = ct
3484+ @const_expr_ids[ci] = expr_id
3485+ return
3486+ end
3487+ @const_names.push(cname)
3488+ @const_types.push(ct)
3489+ @const_expr_ids.push(expr_id)
3490+ end
3491+
34713492 def collect_class_with_prefix(nid, module_prefix)
34723493 ci = @cls_names.length
34733494 cname = ""
@@ -3523,6 +3544,9 @@
35233544 if @nd_type[sid] == "DefNode"
35243545 collect_class_method(ci, sid)
35253546 end
3547+ if @nd_type[sid] == "ConstantWriteNode"
3548+ collect_scoped_constant(cname, sid)
3549+ end
35263550 if @nd_type[sid] == "CallNode"
35273551 cn = @nd_name[sid]
35283552 if cn != "include"
@@ -3669,6 +3693,9 @@
36693693 if @nd_type[sid] == "DefNode"
36703694 collect_class_method(ci, sid)
36713695 end
3696+ if @nd_type[sid] == "ConstantWriteNode"
3697+ collect_scoped_constant(cname, sid)
3698+ end
36723699 if @nd_type[sid] == "CallNode"
36733700 cn = @nd_name[sid]
36743701 if cn != "include"
@@ -11405,8 +11432,11 @@
1140511432 end
1140611433 if t == "ConstantPathNode"
1140711434 if @nd_receiver[nid] >= 0
11408- rname = @nd_name[@nd_receiver[nid]]
11435+ rname = const_ref_flat_name(@nd_receiver[nid])
1140911436 nname = @nd_name[nid]
11437+ if rname == ""
11438+ return @nd_name[nid]
11439+ end
1141011440 cpname = rname + "_" + nname
1141111441 ci = find_const_idx(cpname)
1141211442 if ci >= 0