@@ -71,12 +71,20 @@ class CppScriptException(Exception):
7171 pass
7272
7373
74+ def replace_extension (filename , new_ext ):
75+ idx = filename .rfind ('.' )
76+ if idx == - 1 :
77+ return filename + new_ext
78+ else :
79+ return filename [:idx ] + new_ext
80+
81+
7482def resolve_path (path , cwd ):
7583 return path if os .path .isabs (path ) else os .path .abspath (os .path .join (cwd , path ))
7684
7785
7886def filename_to_gen_filename (name , env ):
79- return os .path .join (env ['gen_dir' ], os .path .relpath (name . replace ( '.hpp' , '.gen.cpp' ), env ['header_dir' ]))
87+ return os .path .join (env ['gen_dir' ], os .path .relpath (replace_extension ( name , '.gen.cpp' ), env ['header_dir' ]))
8088
8189
8290def collapse_list (list , key , action ):
@@ -270,7 +278,7 @@ def generate_header(source, env, get_file):
270278 return 0
271279
272280def parse_header (index , filename , filecontent , env ):
273- translation_unit = index .parse (filename , args = env ['parser_args' ], unsaved_files = [(filename , filecontent )], options = TranslationUnit .PARSE_DETAILED_PROCESSING_RECORD )
281+ translation_unit = index .parse (filename , args = env ['parser_args' ] + [ '-x' , 'c++' ] , unsaved_files = [(filename , filecontent )], options = TranslationUnit .PARSE_DETAILED_PROCESSING_RECORD )
274282
275283 if not translation_unit :
276284 raise CppScriptException ("{filename}: failed to create translation unit" )
0 commit comments