Browse Source

Set the file's filename and directory in `init_ast_file`

gingerBill 2 years ago
parent
commit
44caa96d50
3 changed files with 11 additions and 7 deletions
  1. 2 5
      src/llvm_backend.cpp
  2. 4 2
      src/parser.cpp
  3. 5 0
      src/parser.hpp

+ 2 - 5
src/llvm_backend.cpp

@@ -1740,12 +1740,9 @@ gb_internal void lb_generate_code(lbGenerator *gen) {
 		if (m->debug_builder) { // Debug Info
 			for (auto const &file_entry : info->files) {
 				AstFile *f = file_entry.value;
-				String fullpath = f->fullpath;
-				String filename = remove_directory_from_path(fullpath);
-				String directory = directory_from_path(fullpath);
 				LLVMMetadataRef res = LLVMDIBuilderCreateFile(m->debug_builder,
-					cast(char const *)filename.text, filename.len,
-					cast(char const *)directory.text, directory.len);
+					cast(char const *)f->filename.text, f->filename.len,
+					cast(char const *)f->directory.text, f->directory.len);
 				lb_set_llvm_metadata(m, f, res);
 			}
 

+ 4 - 2
src/parser.cpp

@@ -4768,8 +4768,10 @@ gb_internal Array<Ast *> parse_stmt_list(AstFile *f) {
 
 gb_internal ParseFileError init_ast_file(AstFile *f, String const &fullpath, TokenPos *err_pos) {
 	GB_ASSERT(f != nullptr);
-	f->fullpath = string_trim_whitespace(fullpath); // Just in case
-	set_file_path_string(f->id, fullpath);
+	f->fullpath  = string_trim_whitespace(fullpath); // Just in case
+	f->filename  = remove_directory_from_path(f->fullpath);
+	f->directory = directory_from_path(f->fullpath);
+	set_file_path_string(f->id, f->fullpath);
 	thread_safe_set_ast_file_from_id(f->id, f);
 	if (!string_ends_with(f->fullpath, str_lit(".odin"))) {
 		return ParseFile_WrongExtension;

+ 5 - 0
src/parser.hpp

@@ -99,7 +99,11 @@ struct AstFile {
 	Scope *      scope;
 
 	Ast *        pkg_decl;
+
 	String       fullpath;
+	String       filename;
+	String       directory;
+
 	Tokenizer    tokenizer;
 	Array<Token> tokens;
 	isize        curr_token_index;
@@ -109,6 +113,7 @@ struct AstFile {
 	Token        package_token;
 	String       package_name;
 
+
 	// >= 0: In Expression
 	// <  0: In Control Clause
 	// NOTE(bill): Used to prevent type literals in control clauses