@@ -32,15 +32,16 @@ def split_args(s: str) -> list[str]:
32
32
33
33
34
34
string_re = re .compile (
35
- r"sc::message<sc::undefined<sc::args<(.*)>, char, (.*)>\s*>"
35
+ r"sc::message<sc::undefined<sc::args<(.*)>, (.*), char, (.*)>\s*>"
36
36
)
37
37
38
38
39
39
def extract_string_id (line_m ):
40
40
catalog_type = line_m .group (1 )
41
41
string_m = string_re .match (line_m .group (3 ))
42
42
arg_tuple = string_m .group (1 )
43
- string_tuple = string_m .group (2 ).replace ("(char)" , "" )
43
+ string_id = int (string_m .group (2 ))
44
+ string_tuple = string_m .group (3 ).replace ("(char)" , "" )
44
45
string_value = "" .join ((chr (int (c )) for c in re .split (r"\s*,\s*" , string_tuple )))
45
46
args = split_args (arg_tuple )
46
47
@@ -51,11 +52,12 @@ def extract_string_id(line_m):
51
52
type = "flow" if string_value .startswith ("flow." ) else "msg" ,
52
53
arg_types = args ,
53
54
arg_count = len (args ),
55
+ id = string_id
54
56
),
55
57
)
56
58
57
59
58
- module_re = re .compile (r"sc::module_string<sc::undefined<void, char, (.*)>\s?>" )
60
+ module_re = re .compile (r"sc::module_string<sc::undefined<void, -1, char, (.*)>\s?>" )
59
61
60
62
61
63
def module_string (module ) -> str :
@@ -110,8 +112,18 @@ def get_id(stable_ids, key_fn, gen, obj):
110
112
else :
111
113
return next (gen )
112
114
115
+ unique_strings = {i [0 ][0 ]: i for i in strings }.values ()
116
+
113
117
stable_msg_ids , stable_module_ids = stable_ids
114
118
119
+ for _ , msg in filter (lambda u : u [1 ]["id" ] != - 1 , unique_strings ):
120
+ stable_msg_ids [stable_msg_key (msg )] = msg ["id" ]
121
+
122
+ if len (stable_msg_ids ) != len (set (stable_msg_ids .values ())):
123
+ import collections
124
+ dupes = [item for item , count in collections .Counter (stable_msg_ids .values ()).items () if count > 1 ]
125
+ raise Exception (f"Duplicate string IDs found: { dupes } ." )
126
+
115
127
old_msg_ids = set (stable_msg_ids .values ())
116
128
msg_id_gen = itertools .filterfalse (old_msg_ids .__contains__ , itertools .count (0 ))
117
129
get_msg_id = partial (get_id , stable_msg_ids , stable_msg_key , msg_id_gen )
@@ -122,7 +134,6 @@ def get_id(stable_ids, key_fn, gen, obj):
122
134
)
123
135
get_module_id = partial (get_id , stable_module_ids , stable_module_key , module_id_gen )
124
136
125
- unique_strings = {i [0 ][0 ]: i for i in strings }.values ()
126
137
return (
127
138
{m : {"string" : module_string (m ), "id" : get_module_id (m )} for m in sorted (set (modules ))},
128
139
{item [0 ]: {** item [1 ], "id" : get_msg_id (item [1 ])} for item in unique_strings },
@@ -144,7 +155,7 @@ def make_cpp_module_defn(m: str, text: str, n: int) -> str:
144
155
return f"""/*
145
156
"{ text } "
146
157
*/
147
- template<> unsigned int module<sc::module_string<sc::undefined<void, char, { m } >>>() {{
158
+ template<> unsigned int module<sc::module_string<sc::undefined<void, -1, char, { m } >>>() {{
148
159
return { n } ;
149
160
}}"""
150
161
0 commit comments