@@ -32,15 +32,16 @@ def split_args(s: str) -> list[str]:
3232
3333
3434string_re = re .compile (
35- r"sc::message<sc::undefined<sc::args<(.*)>, char, (.*)>\s*>"
35+ r"sc::message<sc::undefined<sc::args<(.*)>, (.*), char, (.*)>\s*>"
3636)
3737
3838
3939def extract_string_id (line_m ):
4040 catalog_type = line_m .group (1 )
4141 string_m = string_re .match (line_m .group (3 ))
4242 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)" , "" )
4445 string_value = "" .join ((chr (int (c )) for c in re .split (r"\s*,\s*" , string_tuple )))
4546 args = split_args (arg_tuple )
4647
@@ -51,11 +52,12 @@ def extract_string_id(line_m):
5152 type = "flow" if string_value .startswith ("flow." ) else "msg" ,
5253 arg_types = args ,
5354 arg_count = len (args ),
55+ id = string_id
5456 ),
5557 )
5658
5759
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?>" )
5961
6062
6163def module_string (module ) -> str :
@@ -110,8 +112,18 @@ def get_id(stable_ids, key_fn, gen, obj):
110112 else :
111113 return next (gen )
112114
115+ unique_strings = {i [0 ][0 ]: i for i in strings }.values ()
116+
113117 stable_msg_ids , stable_module_ids = stable_ids
114118
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+
115127 old_msg_ids = set (stable_msg_ids .values ())
116128 msg_id_gen = itertools .filterfalse (old_msg_ids .__contains__ , itertools .count (0 ))
117129 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):
122134 )
123135 get_module_id = partial (get_id , stable_module_ids , stable_module_key , module_id_gen )
124136
125- unique_strings = {i [0 ][0 ]: i for i in strings }.values ()
126137 return (
127138 {m : {"string" : module_string (m ), "id" : get_module_id (m )} for m in sorted (set (modules ))},
128139 {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:
144155 return f"""/*
145156 "{ text } "
146157 */
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 } >>>() {{
148159 return { n } ;
149160}}"""
150161
0 commit comments